fix issues in typeahead

This commit is contained in:
uzairr
2021-06-11 16:25:06 +05:00
committed by Waheed Ahmed
parent a68fb310ed
commit 496f3857c0

View File

@@ -21,7 +21,7 @@ class CountryDropdown extends React.Component {
}
shouldComponentUpdate(nextProps) {
if (this.props.value !== nextProps.value) {
if (this.props.value !== nextProps.value && nextProps.value !== null) {
const opt = this.props.options.find((o) => o[this.props.valueKey] === nextProps.value);
if (opt && opt[this.props.displayValueKey] !== this.state.displayValue) {
this.setState({ displayValue: opt[this.props.displayValueKey], showFieldError: false });
@@ -87,13 +87,16 @@ class CountryDropdown extends React.Component {
}
}
handleClick = () => {
handleClick = (e) => {
if (!this.props.value) {
const dropDownItems = this.getItems();
const dropDownItems = this.getItems(e.target.value);
this.setState({
dropDownItems, icon: ExpandLess, errorMessage: '', showFieldError: false,
});
}
if (this.state.dropDownItems?.length > 0) {
this.setState({ dropDownItems: '', icon: ExpandMore });
}
}
handleOnChange = (e) => {