Semantic-Org/Semantic-UI-React

Dropdown: Blurring the field doesn't trigger `onChange`

Open

#3648 opened on Jun 7, 2019

View on GitHub
 (2 comments) (1 reaction) (0 assignees)JavaScript (13,136 stars) (4,065 forks)batch import
bughelp wantedstale

Description

Bug Report

Steps

  1. Create a Dropdown field with value, allowAdditions, search props.
  2. Type something in the SearchInput and press Tab to blur the field.

Expected Result

Blurring the field should trigger an onChange with the value typed in the dropdown.

Actual Result

onChange is not triggered and Dropdown keeps the old value.

Version

0.85.0 f735a58f - this commit is the first one that makes the issue appear

Testcase

https://codesandbox.io/s/semantic-ui-react-hcc64

As far as I checked the problem arises from the fact that setSelectedIndex is not being called before a call to makeSelectedItemActive.

Not sure if that is the right solution but I fixed it with


diff --git i/src/modules/Dropdown/Dropdown.js w/src/modules/Dropdown/Dropdown.js
index 7bb644d0..675ea2da 100644
--- i/src/modules/Dropdown/Dropdown.js
+++ w/src/modules/Dropdown/Dropdown.js
@@ -734,6 +734,7 @@ export default class Dropdown extends Component {
     _.invoke(this.props, 'onBlur', e, this.props)
 
     if (selectOnBlur && !multiple) {
+      this.setSelectedIndex(e.target.value)
       this.makeSelectedItemActive(e)
       if (closeOnBlur) this.close()
     }

Contributor guide