-
Notifications
You must be signed in to change notification settings - Fork 4k
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): UX behavior of selectedItems and scroll for filtered options. #2375
Changes from 5 commits
073eb6f
bb860f3
466d48d
2b0279c
28bbf25
3080331
0813a69
7c67340
2c9bffd
7855cb2
b39b782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,8 @@ const wrapperRender = (...args) => (wrapper = render(...args)) | |
// Options | ||
// ---------------------------------------- | ||
const getOptions = (count = 5) => _.times(count, (i) => { | ||
const text = `${i}-${faker.hacker.noun}` | ||
const value = `${i}-${_.snakeCase(text)}` | ||
const text = `${i}-item-text` | ||
const value = `${i}-item-value` | ||
return { text, value } | ||
}) | ||
|
||
|
@@ -57,7 +57,7 @@ const dropdownMenuIsOpen = () => { | |
|
||
const nativeEvent = { nativeEvent: { stopImmediatePropagation: _.noop } } | ||
|
||
describe('Dropdown', () => { | ||
describe.only('Dropdown', () => { | ||
beforeEach(() => { | ||
attachTo = undefined | ||
wrapper = undefined | ||
|
@@ -1980,6 +1980,66 @@ describe('Dropdown', () => { | |
wrapper.should.have.state('selectedIndex', 0) | ||
}) | ||
|
||
it('retains the selected item after searching with no results', () => { | ||
wrapperMount(<Dropdown options={options} selection search />) | ||
|
||
// open the dropdown | ||
wrapper.simulate('click') | ||
dropdownMenuIsOpen() | ||
|
||
// select the second item in the list | ||
wrapper.find('DropdownItem').at(1).simulate('click') | ||
wrapper.find('DropdownItem').at(1).should.have.prop('active', true) | ||
wrapper.find('DropdownItem').at(1).should.have.prop('selected', true) | ||
|
||
wrapper.find('DropdownItem').at(0).should.have.prop('active', false) | ||
wrapper.find('DropdownItem').at(0).should.have.prop('selected', false) | ||
|
||
// search for a non-existent item, triggering the not found message | ||
const search = wrapper.find('input.search') | ||
search.simulate('change', { target: { value: '__nonExistingSearchQuery__' } }) | ||
|
||
// click outside, close the dropdown | ||
domEvent.click(document) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line isn't working really. I noted that once you added describe.only, the call domEvent.click(document) isn't really working, and would also cause a failure in the test
|
||
dropdownMenuIsClosed() | ||
|
||
// next time we open the dropdown, the active item at index 1 should be selected | ||
// even though our search query last set the selected index to 0 | ||
wrapper.simulate('click') | ||
dropdownMenuIsOpen() | ||
|
||
wrapper.find('DropdownItem').at(1).should.have.prop('active', true) | ||
wrapper.find('DropdownItem').at(1).should.have.prop('selected', true) | ||
|
||
wrapper.find('DropdownItem').at(0).should.have.prop('active', false) | ||
wrapper.find('DropdownItem').at(0).should.have.prop('selected', false) | ||
}) | ||
|
||
it('set right selected index when click on option with search', () => { | ||
wrapperMount(<Dropdown options={options} search selection />) | ||
|
||
// avoid testing item index 0, it is selected by default | ||
const itemIndex = 1 | ||
|
||
// open the menu | ||
wrapper.simulate('click') | ||
dropdownMenuIsOpen() | ||
|
||
// search for specific item, filtering the list and changing the index order | ||
const search = wrapper.find('input.search') | ||
search.simulate('change', { target: { value: `${itemIndex}-item` } }) | ||
|
||
// click the item | ||
wrapper.find('DropdownItem').simulate('click') | ||
|
||
// open the menu again | ||
wrapper.simulate('click') | ||
dropdownMenuIsOpen() | ||
|
||
// our selectedIndex should match that items index in the full list of items | ||
wrapper.state('selectedIndex').should.equal(itemIndex) | ||
}) | ||
|
||
it('still allows moving selection after blur/focus', () => { | ||
// open, first item is selected | ||
wrapperMount(<Dropdown options={options} selection search />) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unwise to add more state management, especially outside of this.state. I thought my PR addressed this issue quite well by ensuring this.state stayed in sync with prop changes. Did you have a chance to review my PR?