Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not show selected tags in picker suggestions when no input is provided #1985 #2195

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 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,24 @@ 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, getAllByRole } = render(<XPicker model={pickerProps} />)
const input = (getByRole('combobox') as HTMLInputElement)

fireEvent.click(input)
expect(getAllByRole('option')).toHaveLength(2)
typeToInput(input, name)
fireEvent.click(getByRole('option'))

fireEvent.click(input)
expect(getAllByRole('option')).toHaveLength(1)
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