From 8683c297939b86adc286ca7a7f3d9717e7f514ba Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Thu, 21 Feb 2019 15:42:56 -0700 Subject: [PATCH 1/2] Fixes #28154 - Auto focus search bar when page mounts --- .../components/autocomplete_field/autocomplete_field.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx b/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx index 2a38885d491dd..51d94bc04de72 100644 --- a/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx +++ b/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx @@ -85,6 +85,10 @@ export class AutocompleteField extends React.Component< ); } + public componentDidMount() { + this.inputElement.focus(); + } + public componentDidUpdate(prevProps: AutocompleteFieldProps, prevState: AutocompleteFieldState) { const hasNewValue = prevProps.value !== this.props.value; const hasNewSuggestions = prevProps.suggestions !== this.props.suggestions; From e60b666d9fa5601e6a18bf163e56d2d6fd57a23b Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Thu, 21 Feb 2019 17:25:57 -0700 Subject: [PATCH 2/2] Adding check --- .../components/autocomplete_field/autocomplete_field.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx b/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx index 51d94bc04de72..4e90ea55e43c2 100644 --- a/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx +++ b/x-pack/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx @@ -86,7 +86,9 @@ export class AutocompleteField extends React.Component< } public componentDidMount() { - this.inputElement.focus(); + if (this.inputElement) { + this.inputElement.focus(); + } } public componentDidUpdate(prevProps: AutocompleteFieldProps, prevState: AutocompleteFieldState) {