diff --git a/public/app/features/dashboard/panel_editor/VisualizationTab.tsx b/public/app/features/dashboard/panel_editor/VisualizationTab.tsx index 847e185f9f9..884615821eb 100644 --- a/public/app/features/dashboard/panel_editor/VisualizationTab.tsx +++ b/public/app/features/dashboard/panel_editor/VisualizationTab.tsx @@ -17,7 +17,7 @@ import { FadeIn } from 'app/core/components/Animations/FadeIn'; import { PanelModel } from '../state'; import { DashboardModel } from '../state'; import { PanelPlugin } from 'app/types/plugins'; -import { FilterInput } from 'app/core/components/FilterInput/FilterInput'; +import { VizPickerSearch } from './VizPickerSearch'; interface Props { panel: PanelModel; @@ -39,7 +39,6 @@ interface State { export class VisualizationTab extends PureComponent { element: HTMLElement; angularOptions: AngularComponent; - searchInput: HTMLElement; constructor(props) { super(props); @@ -164,7 +163,7 @@ export class VisualizationTab extends PureComponent { this.props.updateLocation({ query: { openVizPicker: null }, partial: true }); } - this.setState({ isVizPickerOpen: false }); + this.setState({ isVizPickerOpen: false, hasBeenFocused: false }); }; onSearchQueryChange = (value: string) => { @@ -173,34 +172,18 @@ export class VisualizationTab extends PureComponent { }); }; - setSearchInputRef = (element: HTMLInputElement) => { - if (!this.state.hasBeenFocused) { - if (element) { - element.focus(); - } - } - this.setState({ hasBeenFocused: true }); - }; - renderToolbar = (): JSX.Element => { const { plugin } = this.props; const { isVizPickerOpen, searchQuery } = this.state; if (isVizPickerOpen) { return ( - <> - this.setSearchInputRef(element)} - /> - - + ); } else { return ( diff --git a/public/app/features/dashboard/panel_editor/VizPickerSearch.tsx b/public/app/features/dashboard/panel_editor/VizPickerSearch.tsx new file mode 100644 index 00000000000..ddf9485dab9 --- /dev/null +++ b/public/app/features/dashboard/panel_editor/VizPickerSearch.tsx @@ -0,0 +1,33 @@ +import React, { PureComponent } from 'react'; + +import { FilterInput } from 'app/core/components/FilterInput/FilterInput'; + +import { PanelPlugin } from 'app/types'; + +interface Props { + plugin: PanelPlugin; + searchQuery: string; + onChange: (query: string) => void; + onClose: () => void; +} + +export class VizPickerSearch extends PureComponent { + render() { + const { searchQuery, onChange, onClose } = this.props; + return ( + <> + element && element.focus()} + /> + + + ); + } +}