From 54b8a635c9abd587f51236ed37653560892f14ef Mon Sep 17 00:00:00 2001 From: John Coburn Date: Thu, 21 Nov 2024 10:54:32 -0600 Subject: [PATCH] STCOM-1385 Clear filter value after an action is chosen from MultiSelection (#2393) * clear filter value after an action is chosen from MultiSelection's option list. * add tests for removed filter value, updated comment --- CHANGELOG.md | 1 + lib/MultiSelection/MultiSelection.js | 4 ++-- lib/MultiSelection/tests/MultiSelection-test.js | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 104c9ac7b..0e435b896 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Wrap `` in full-width div. Refs STCOM-1332. * Assign ``'s exit key handler to Modal's element rather than `document`. refs STCOM-1382. * Wrap ``'s render output in `` to facilitate ease with overlay components. Refs STCOM-1384. +* Clear filter value after an action chosen from `MultiSelection` menu. Refs STCOM-1385. ## [12.2.0](https://github.com/folio-org/stripes-components/tree/v12.2.0) (2024-10-11) [Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.1.0...v12.2.0) diff --git a/lib/MultiSelection/MultiSelection.js b/lib/MultiSelection/MultiSelection.js index 4b3d4d90d..0270b0464 100644 --- a/lib/MultiSelection/MultiSelection.js +++ b/lib/MultiSelection/MultiSelection.js @@ -256,7 +256,6 @@ const MultiSelection = ({ break; } }, - // stateReducer(state, actionAndChanges) { const { changes, type } = actionAndChanges switch (type) { @@ -272,8 +271,9 @@ const MultiSelection = ({ selectedItems, reset }); + setFilterValue(''); return { - isOpen: false, // keep the menu open after selection. + isOpen: false, // close the menu. highlightedIndex, // don't move highlight cursor back to top of list on selection. } } else { diff --git a/lib/MultiSelection/tests/MultiSelection-test.js b/lib/MultiSelection/tests/MultiSelection-test.js index 5eb31c00a..726af92cd 100644 --- a/lib/MultiSelection/tests/MultiSelection-test.js +++ b/lib/MultiSelection/tests/MultiSelection-test.js @@ -610,6 +610,16 @@ describe('MultiSelect', () => { it('calls the action\'s onSelect function', () => converge(() => { if (!actionSelected) throw new Error('MultiSelection - action should be executed'); })); }); + + describe('clicking a filtered action', () => { + beforeEach(async () => { + await multiselection.filter('act'); + await multiselection.select('actionItem'); + }); + + it('calls the action\'s onSelect function', () => converge(() => { if (!actionSelected) throw new Error('MultiSelection - action should be executed'); })); + it('clears the filter value', () => multiselection.has({ filterValue: '' })); + }); }); describe('asyncFiltering', () => {