Skip to content

Commit 591e966

Browse files
authored
Merge pull request #8454 from nextcloud-libraries/fix/search-clear-icon
fix(NcAppNavigationSearch): Show search clear icon only when field contains something
2 parents ea71fe9 + 11f2262 commit 591e966

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/components/NcAppNavigationSearch/NcAppNavigationSearch.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default {
133133
class="app-navigation-search__input"
134134
labelOutside
135135
:placeholder="placeholder ?? label"
136-
showTrailingButton
136+
:showTrailingButton="model.length > 0"
137137
:trailingButtonLabel="t('Clear search')"
138138
type="search"
139139
@trailingButtonClick="onCloseSearch">
@@ -230,6 +230,10 @@ function onCloseSearch() {
230230
gap: var(--app-navigation-padding);
231231
padding: var(--app-navigation-padding);
232232
233+
&__input {
234+
--input-padding-end: calc(var(--default-clickable-area) - var(--default-grid-baseline));
235+
}
236+
233237
&--has-actions &__input {
234238
flex-grow: 1;
235239
z-index: 3;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { mount } from '@vue/test-utils'
7+
import { describe, expect, it } from 'vitest'
8+
import { defineComponent } from 'vue'
9+
import NcAppNavigationSearch from '../../../../src/components/NcAppNavigationSearch/NcAppNavigationSearch.vue'
10+
11+
function findClearButton(wrapper) {
12+
return wrapper.find('button[aria-label="Clear search"]')
13+
}
14+
function mountWrapped(value = '') {
15+
return mount(defineComponent({
16+
components: {
17+
NcAppNavigationSearch,
18+
},
19+
data() {
20+
return {
21+
value,
22+
}
23+
},
24+
template: '<NcAppNavigationSearch v-model="value" />',
25+
}))
26+
}
27+
28+
describe('NcAppNavigationSearch', () => {
29+
it('does not show the clear button for an empty search', () => {
30+
const wrapper = mountWrapped()
31+
32+
expect(findClearButton(wrapper).exists()).toBe(false)
33+
})
34+
35+
it('only shows the clear button once the search has content', async () => {
36+
const wrapper = mountWrapped()
37+
38+
await wrapper.get('input').setValue('a')
39+
40+
expect(findClearButton(wrapper).exists()).toBe(true)
41+
})
42+
43+
it('hides the clear button again after clearing the search', async () => {
44+
const wrapper = mountWrapped('test')
45+
46+
await findClearButton(wrapper).trigger('click')
47+
48+
expect(findClearButton(wrapper).exists()).toBe(false)
49+
})
50+
})

0 commit comments

Comments
 (0)