Semantic-Org/Semantic-UI-React

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

Open

#3,648 建立於 2019年6月7日

在 GitHub 查看
 (2 留言) (1 反應) (0 負責人)JavaScript (13,136 star) (4,065 fork)batch import
bughelp wantedstale

描述

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

貢獻者指南