Skip to content

Commit

Permalink
[FX-NULL] Do not render dropdown when options are empty (#4556)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashuk authored Sep 16, 2024
1 parent 894bfd3 commit 23e4e28
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/friendly-scissors-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@toptal/picasso-autocomplete': patch
---

- do not render options dropdown when options is null or undefined
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const OptionsMenu = ({
)
}

if (menuItems.length === 0) {
if (menuItems.length === 0 || !options) {
return null
}

Expand Down
15 changes: 15 additions & 0 deletions packages/base/Autocomplete/src/Autocomplete/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,21 @@ describe('Autocomplete', () => {
expect(myOtherOption).not.toBeNull()
expect(myOtherOption).toMatchSnapshot()
})

describe('when options is null', () => {
it('does not render dropdown', async () => {
const { getByTestId, queryByText } = renderAutocomplete({
options: null,
value: 'Ruby',
})

const input = getByTestId('autocomplete') as HTMLInputElement

fireEvent.change(input, { target: { value: '' } })

expect(queryByText('No options')).not.toBeInTheDocument()
})
})
})

describe('Autofill', () => {
Expand Down

0 comments on commit 23e4e28

Please sign in to comment.