Skip to content

Commit

Permalink
fix: do not show already used suggestions when no input is provided #…
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok committed Nov 16, 2023
1 parent a321fc9 commit a5e8df3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion ui/src/picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<XPicker model={pickerProps} />)
const input = (getByRole('combobox') as HTMLInputElement)

Expand All @@ -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(<XPicker model={pickerProps} />)
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(<XPicker model={pickerProps} />)

Expand Down
2 changes: 1 addition & 1 deletion ui/src/picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5e8df3

Please sign in to comment.