Skip to content

Commit

Permalink
fix(Dropdown): do not select disabled items on blur (#4199)
Browse files Browse the repository at this point in the history
* added a variable to recognize if a country is blocked or not

* remove lock file

* add a comment & unit test

Co-authored-by: Loic Cesar Boubeji Tiangueu <loic.cesar.boubeji.tiangueu@mni.thm.de>
Co-authored-by: Oleksandr Fediashov <olfedias@microsoft.com>
  • Loading branch information
3 people committed Jan 21, 2022
1 parent ba0b20e commit e500234
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ export default class Dropdown extends Component {

const item = this.getSelectedItem(selectedIndex)
const selectedValue = _.get(item, 'value')
const disabled = _.get(item, 'disabled')

// prevent selecting null if there was no selected item value
// prevent selecting duplicate items when the dropdown is closed
if (_.isNil(selectedValue) || !open) {
// prevent selecting disabled items
if (_.isNil(selectedValue) || !open || disabled) {
return value
}

Expand Down
19 changes: 19 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,25 @@ describe('Dropdown', () => {

wrapper.should.have.state('focus', true)
})

it('does not selected "disabled" item after blur', () => {
const customOptions = [
{ key: 'foo', text: 'foo', value: 'foo' },
{ key: 'bar', text: 'bar', value: 'bar', disabled: true },
]

wrapperMount(<Dropdown options={customOptions} selection search />)

wrapper.simulate('focus')
dropdownMenuIsOpen()

wrapper.find('input.search').simulate('change', { target: { value: 'bar' } })
wrapper.find('input.search').getDOMNode().blur()
wrapper.simulate('blur')

dropdownMenuIsClosed()
wrapper.find('.item.disabled').should.have.not.className('selected')
})
})

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

0 comments on commit e500234

Please sign in to comment.