Skip to content

Commit

Permalink
[EuiSelectable] Fix focus management bug (#4152)
Browse files Browse the repository at this point in the history
Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
  • Loading branch information
Michail Yasonik and cchaos authored Oct 19, 2020
1 parent 33126c8 commit 9e028d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
- Updated types associated with `EuiMarkdownEditor` plugin dependencies ([4124](https://github.com/elastic/eui/pull/4124))
- Upgraded dependencies related to `EuiMarkdownEditor`: `react-dropzone`, `rehype-*`, `remark-*`, and `unified` ([#4124](https://github.com/elastic/eui/pull/4124))

**Bug fixes**
- Fixed focus management bug in `EuiSelectable` ([4152](https://github.com/elastic/eui/pull/4152))

**Breaking changes**

- Removed `EuiToggle` and `EuiButtonToggle` in favor of `aria-pressed` ([4056](https://github.com/elastic/eui/pull/4056))
Expand Down
8 changes: 6 additions & 2 deletions src/components/selectable/selectable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class EuiSelectable<T = {}> extends Component<
singleSelection: false,
searchable: false,
};

private containerRef = createRef<HTMLDivElement>();
private optionsListRef = createRef<EuiSelectableList<T>>();
rootId = htmlIdGenerator();
constructor(props: EuiSelectableProps<T>) {
Expand Down Expand Up @@ -335,7 +335,10 @@ export class EuiSelectable<T = {}> extends Component<
);
};

onContainerBlur = () => {
onContainerBlur = (e: React.FocusEvent) => {
// Ignore blur events when moving from search to option to avoid activeOptionIndex conflicts
if (this.containerRef.current!.contains(e.relatedTarget as Node)) return;

this.setState({
activeOptionIndex: undefined,
isFocused: false,
Expand Down Expand Up @@ -592,6 +595,7 @@ export class EuiSelectable<T = {}> extends Component<

return (
<div
ref={this.containerRef}
className={classes}
onKeyDown={this.onKeyDown}
onBlur={this.onContainerBlur}
Expand Down

0 comments on commit 9e028d8

Please sign in to comment.