From a5e8df3298f8ef72776dae796e9a6b95102da960 Mon Sep 17 00:00:00 2001 From: Marek Mihok Date: Thu, 16 Nov 2023 18:20:37 +0100 Subject: [PATCH] fix: do not show already used suggestions when no input is provided #1985 --- ui/src/picker.test.tsx | 15 ++++++++++++++- ui/src/picker.tsx | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ui/src/picker.test.tsx b/ui/src/picker.test.tsx index 58cd881775c..6a1874742e7 100644 --- a/ui/src/picker.test.tsx +++ b/ui/src/picker.test.tsx @@ -148,7 +148,7 @@ describe('Picker.tsx', () => { expect(getAllByRole('option')).toHaveLength(1) }) - it('Filters correctly - does not offer already selected', () => { + it('Filters correctly - does not offer already selected - with input provided', () => { const { getByRole, queryByRole } = render() const input = (getByRole('combobox') as HTMLInputElement) @@ -159,6 +159,19 @@ describe('Picker.tsx', () => { expect(queryByRole('option')?.querySelector('.ms-Suggestions-none')).toBeInTheDocument() }) + it('Filters correctly - does not offer already selected - without input provided', () => { + const { getByRole, queryByRole } = render() + const input = (getByRole('combobox') as HTMLInputElement) + + typeToInput(input, name) + fireEvent.click(getByRole('option')) + typeToInput(input, altName) + fireEvent.click(getByRole('option')) + fireEvent.click(input) + + expect(queryByRole('option')?.querySelector('.ms-Suggestions-none')).toBeInTheDocument() + }) + it('Sets args - single selection', () => { const { getByRole } = render() diff --git a/ui/src/picker.tsx b/ui/src/picker.tsx index 8794d0998dd..51902765cf7 100644 --- a/ui/src/picker.tsx +++ b/ui/src/picker.tsx @@ -67,7 +67,7 @@ export const XPicker = ({ model: m }: { model: Picker }) => { wave.args[m.name] = items ? items.map(({ key }) => key) : null if (m.trigger) wave.push() }, - onEmptyResolveSuggestions = () => tags + onEmptyResolveSuggestions = () => tags.filter(tag => !selectedTags.includes(tag)) React.useEffect(() => { wave.args[m.name] = m.values || null