Skip to content

Commit 3754f7b

Browse files
authored
Merge pull request #179 from input-output-hk/fix/ddw-662-fix-react-polymorph-select-search-issues
[DDW-662] Fixes React Polymorph Select search issues
2 parents 5b5c204 + def81c8 commit 3754f7b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ vNext
2424

2525
### Fixes :muscle:
2626

27+
- Fixed Select search issues([PR 179](https://github.com/input-output-hk/react-polymorph/pull/179))
2728
- Fixed Select Search styles and minor code issues ([PR 175](https://github.com/input-output-hk/react-polymorph/pull/175))
2829
- Fixed a wrong variable name for the select search highlight color ([PR 170](https://github.com/input-output-hk/react-polymorph/pull/170))
2930
- Fixed an issue related to Numeric Input when entering numbers after having selected the decimal separator ([PR 167](https://github.com/input-output-hk/react-polymorph/pull/167))

source/components/Options.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Props = {
4545
optionRenderer?: Function,
4646
optionsRef?: ElementRef<any>,
4747
optionsMaxHeight?: number,
48+
persistSearchValue?: boolean,
4849
render?: Function,
4950
resetOnClose: boolean,
5051
searchHeight: ?number,
@@ -179,7 +180,8 @@ class OptionsBase extends Component<Props, State> {
179180
};
180181

181182
isSelectedOption = (optionIndex: number) => {
182-
const { options, isOpeningUpward } = this.props;
183+
const { isOpeningUpward } = this.props;
184+
const options = this.getFilteredOptions() || []
183185
const index = isOpeningUpward
184186
? options.length - 1 - optionIndex
185187
: optionIndex;
@@ -197,25 +199,29 @@ class OptionsBase extends Component<Props, State> {
197199
};
198200

199201
handleClickOnOption = (option: ?Object, event: SyntheticEvent<>) => {
202+
const { onChange, onBlur, persistSearchValue } = this.props;
200203
if (option) {
201204
if (option.isDisabled) return;
202-
if (this.props.onChange) this.props.onChange(option, event);
205+
if (onChange) onChange(option, event);
206+
}
207+
if (onBlur) onBlur(event);
208+
if (!persistSearchValue) {
209+
this.handleClearSearchValue();
203210
}
204-
if (this.props.onBlur) this.props.onBlur(event);
205211
this.close();
206212
};
207213

208214
handleSearch = (searchValue: string) => {
209215
this.setState({
210216
searchValue
211217
});
212-
}
218+
};
213219

214220
handleClearSearchValue = () => {
215221
this.setState({
216222
searchValue: '',
217223
});
218-
}
224+
};
219225

220226
getFilteredOptions = () => {
221227
const { hasSearch, onSearch, options, highlightSearch, optionRenderer } = this.props;
@@ -232,7 +238,7 @@ class OptionsBase extends Component<Props, State> {
232238
return regex.test(label);
233239
});
234240
return filteredOptions;
235-
}
241+
};
236242

237243
// returns an object containing props, theme, and method handlers
238244
// associated with rendering this.props.options, the user can call

0 commit comments

Comments
 (0)