Skip to content

Commit

Permalink
Re-focus EuiSuperSelect input after making a value change (#3734)
Browse files Browse the repository at this point in the history
* Re-focus EuiSuperSelect input after making a value change

* changelog
  • Loading branch information
chandlerprall authored Jul 14, 2020
1 parent 9dacc39 commit f7d5843
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Fixed a bug in `EuiResizableContainer` preventing nested containers ([#3699](https://github.com/elastic/eui/pull/3699))
- Fixed a bug in `EuiResizableContainer` preventing resizing by arrow keys in some cases ([#3699](https://github.com/elastic/eui/pull/3699))
- Fixed `EuiHorizontalSteps` rendering over `EuiHeader` ([#3707](https://github.com/elastic/eui/pull/3707))
- Fixed bug where `EuiSuperSelect` lost focus after a value selection ([#3734](https://github.com/elastic/eui/pull/3734))

**Breaking changes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ exports[`EuiColorPalettePicker more props are propagated to each option 2`] = `
value="paletteFixed"
/>
}
buttonRef={[Function]}
className="euiSuperSelect"
closePopover={[Function]}
display="block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
value="1"
/>
}
buttonRef={[Function]}
className="euiSuperSelect"
closePopover={[Function]}
display="block"
Expand Down
12 changes: 12 additions & 0 deletions src/components/form/super_select/super_select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ export class EuiSuperSelect<T extends string> extends Component<

private itemNodes: Array<HTMLButtonElement | null> = [];
private popoverRef: HTMLDivElement | null = null;
private buttonRef: HTMLElement | null = null;
private setButtonRef = (popoverButtonRef: HTMLDivElement | null) => {
if (popoverButtonRef) {
this.buttonRef = popoverButtonRef.querySelector('button')!;
} else {
this.buttonRef = null;
}
};
private _isMounted: boolean = false;

state = {
Expand Down Expand Up @@ -178,6 +186,9 @@ export class EuiSuperSelect<T extends string> extends Component<
if (this.props.onChange) {
this.props.onChange(value);
}
if (this.buttonRef) {
this.buttonRef.focus();
}
};

onSelectKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
Expand Down Expand Up @@ -339,6 +350,7 @@ export class EuiSuperSelect<T extends string> extends Component<
anchorPosition="downCenter"
ownFocus={false}
popoverRef={this.setPopoverRef}
buttonRef={this.setButtonRef}
hasArrow={false}
buffer={0}>
<EuiScreenReaderOnly>
Expand Down

0 comments on commit f7d5843

Please sign in to comment.