Semantic-Org/Semantic-UI-React

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

Open

Aperta il 7 giu 2019

Vedi su GitHub
 (2 commenti) (1 reazione) (0 assegnatari)JavaScript (13.136 star) (4065 fork)batch import
bughelp wantedstale

Descrizione

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()
     }

Guida contributor