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): retain focus on the input if the Dropdown receives a click #3422

Merged
merged 6 commits into from
Feb 11, 2019
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
5 changes: 4 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,10 @@ export default class Dropdown extends Component {
e.stopPropagation()

if (!search) return this.toggle(e)
if (open) return
if (open) {
if (this.searchRef) this.searchRef.focus()
return
}
if (searchQuery.length >= minCharacters || minCharacters === 1) {
this.open(e)
return
Expand Down
11 changes: 11 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,17 @@ describe('Dropdown', () => {
)
})

it('sets focus to the search input on click Dropdown when is opened', () => {
wrapperMount(<Dropdown open options={options} multiple selection search />)
wrapper.simulate('click')

const activeElement = document.activeElement
const searchIsFocused = activeElement === document.querySelector('input.search')
searchIsFocused.should.be.true(
`Expected "input.search" to be the active element but found ${activeElement} instead.`,
)
})

it('clears the search query when an item is selected', () => {
// search for random item
const searchQuery = _.sample(options).text
Expand Down