Skip to content

Commit

Permalink
fix(selectable): use latest state in onChange (#4292)
Browse files Browse the repository at this point in the history
  • Loading branch information
smhutch authored Nov 24, 2020
1 parent d5f5d6f commit 1fdfca2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

**Bug fixes**

- Fixed stale state argument passed to `searchProps.onChange` in an `EuiSelectable`([#4292](https://github.com/elastic/eui/pull/4292))
- Fixed initial focus of an `EuiButtonGroup` when first item in a popover ([#4288](https://github.com/elastic/eui/pull/4288))

**Theme: Amsterdam**
Expand Down
15 changes: 7 additions & 8 deletions src/components/selectable/selectable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,18 +349,17 @@ export class EuiSelectable<T = {}> extends Component<
};

onOptionClick = (options: Array<EuiSelectableOption<T>>) => {
this.setState((state) => ({
visibleOptions: getMatchingOptions<T>(options, state.searchValue),
activeOptionIndex: this.state.activeOptionIndex,
}));
const { searchValue } = this.state;
const visibleOptions = getMatchingOptions<T>(options, searchValue);

this.setState({ visibleOptions });

if (this.props.onChange) {
this.props.onChange(options);
}

if (this.props.searchProps && this.props.searchProps.onChange) {
this.props.searchProps.onChange(
{ ...this.state.visibleOptions },
this.state.searchValue
);
this.props.searchProps.onChange(visibleOptions, searchValue);
}
};

Expand Down

0 comments on commit 1fdfca2

Please sign in to comment.