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(Dropdown): closing the search menu on spacebar press #3766

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ export default class Dropdown extends Component {

if (
keyboardKey.getCode(e) !== keyboardKey.Enter &&
keyboardKey.getCode(e) !== keyboardKey.Spacebar
(keyboardKey.getCode(e) !== keyboardKey.Spacebar ||
// allow Spacebar in search Dropdown
search)
)
return
e.preventDefault()
Expand Down
29 changes: 28 additions & 1 deletion test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ describe('Dropdown', () => {
.at(1)
.should.have.props({ selected: true, active: true })
})
it('closes the menu', () => {
it('closes the menu on ENTER key', () => {
wrapperMount(<Dropdown options={options} selection />).simulate('click')

dropdownMenuIsOpen()
Expand All @@ -1087,6 +1087,33 @@ describe('Dropdown', () => {
domEvent.keyDown(document, { key: 'Enter' })
dropdownMenuIsClosed()
})
it('closes the menu on SPACE key', () => {
wrapperMount(<Dropdown options={options} selection />).simulate('click')

dropdownMenuIsOpen()

// choose an item closes
domEvent.keyDown(document, { key: 'Spacebar' })
dropdownMenuIsClosed()
})
it('closes the Search menu on ENTER key', () => {
wrapperMount(<Dropdown options={options} selection search />).simulate('click')

dropdownMenuIsOpen()

// choose an item closes
domEvent.keyDown(document, { key: 'Enter' })
dropdownMenuIsClosed()
})
it('does not close the Search menu on SPACE key', () => {
wrapperMount(<Dropdown options={options} selection search />).simulate('click')

dropdownMenuIsOpen()

// choose an item closes
domEvent.keyDown(document, { key: 'Spacebar' })
dropdownMenuIsOpen()
})
it('keeps value of the searchQuery when selection is changed', () => {
wrapperMount(<Dropdown options={options} selection search />)

Expand Down