Skip to content

Commit 01117ee

Browse files
jcabannesZorin95670
authored andcommitted
feat(catalog-ui): reset selected filter when menu closes
1 parent 0b38a7b commit 01117ee

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

apps/catalog-ui/docs/components/smart-filter/LinidSmartFilter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,18 @@ Switching from one filter to another always resets the editor to its initial sta
8585
2. The component emits `update:filters` with all currently active filters (including the newly applied one).
8686
3. The parent updates its state and passes the new array back as `:filters`.
8787
4. The chip for that filter appears.
88+
5. The menu closes and the filter selection is reset — reopening the menu shows no filter pre-selected.
8889

8990
### Switching between filters
9091

9192
1. The user clicks a different filter name in the left column.
9293
2. The editor on the right is replaced with a fresh panel for the newly selected filter.
9394
3. Any previously typed values in the old panel are discarded — they are not applied until the user explicitly clicks **Search**.
9495

96+
### Closing the menu without applying
97+
98+
If the user closes the menu without clicking **Search** (clicking outside, pressing Escape), the filter selection is reset. Reopening the menu shows no filter pre-selected, and any values typed in the editor are lost.
99+
95100
---
96101

97102
## **Chip Lifecycle**

apps/catalog-ui/src/components/smart-filter/LinidSmartFilter.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ watch(
184184
{ immediate: true }
185185
);
186186
187+
watch(isFilterMenuOpen, (isOpen) => {
188+
if (!isOpen) {
189+
selectedFilterName.value = '';
190+
}
191+
});
192+
187193
const uiProps = {
188194
field: ui<LinidQFieldProps>(`${localUiNamespace}`, 'q-field'),
189195
menu: ui<LinidQMenuProps>(`${localUiNamespace}`, 'q-menu'),

apps/catalog-ui/tests/unit/components/smart-filter/LinidSmartFilter.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ describe('Test component: LinidSmartFilter', () => {
126126
wrapper = mountComponent();
127127
});
128128

129+
describe('Test watcher: isFilterMenuOpen', () => {
130+
it('should reset selectedFilterName to empty string when the menu closes', async () => {
131+
wrapper.vm.selectedFilterName = 'username';
132+
wrapper.vm.isFilterMenuOpen = true;
133+
134+
await wrapper.vm.$nextTick();
135+
wrapper.vm.isFilterMenuOpen = false;
136+
await wrapper.vm.$nextTick();
137+
138+
expect(wrapper.vm.selectedFilterName).toBe('');
139+
});
140+
141+
it('should not reset selectedFilterName when the menu opens', async () => {
142+
wrapper.vm.selectedFilterName = 'username';
143+
wrapper.vm.isFilterMenuOpen = false;
144+
145+
await wrapper.vm.$nextTick();
146+
wrapper.vm.isFilterMenuOpen = true;
147+
await wrapper.vm.$nextTick();
148+
149+
expect(wrapper.vm.selectedFilterName).toBe('username');
150+
});
151+
});
152+
129153
describe('Test watcher: filters', () => {
130154
it('should initialize activeFilters as an empty array when no filters prop is provided', () => {
131155
expect(wrapper.vm.activeFilters).toHaveLength(0);

0 commit comments

Comments
 (0)