From 4d6bca69bc6e856011c2d70b28f77b78386170bc Mon Sep 17 00:00:00 2001 From: wiadev Date: Sat, 12 Aug 2017 20:49:17 +0200 Subject: [PATCH] Fix improper handling of initialFocus in conjunction with clear value #1130 --- src/components/widget/Lookup/RawLookup.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/widget/Lookup/RawLookup.js b/src/components/widget/Lookup/RawLookup.js index c1ab74c15..0f0f2cf8b 100644 --- a/src/components/widget/Lookup/RawLookup.js +++ b/src/components/widget/Lookup/RawLookup.js @@ -29,7 +29,7 @@ class RawLookup extends Component { } componentDidMount() { - const { selected, defaultValue } = this.props; + const { selected, defaultValue, initialFocus } = this.props; this.handleValueChanged(); @@ -44,6 +44,10 @@ class RawLookup extends Component { let defaultKey = Object.keys(defaultValue)[0]; this.inputSearch.value = defaultValue[defaultKey]; } + + if (initialFocus && !this.inputSearch.value) { + this.inputSearch.focus(); + } } componentDidUpdate(prevProps) { @@ -51,8 +55,7 @@ class RawLookup extends Component { const { autoFocus, defaultValue, fireClickOutside, handleInputEmptyStatus, - filterWidget, initialFocus, lookupEmpty, localClearing, - resetLocalClearing, fireDropdownList + filterWidget, lookupEmpty, localClearing, resetLocalClearing, fireDropdownList } = this.props; const { shouldBeFocused } = this.state; @@ -69,10 +72,6 @@ class RawLookup extends Component { }); } - if (initialFocus && !this.inputSearch.value) { - this.inputSearch.focus(); - } - defaultValue && prevProps.defaultValue !== defaultValue && handleInputEmptyStatus(false);