Skip to content

Commit

Permalink
Improve search bar (#4189)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Feb 20, 2023
1 parent 0c3fb49 commit 0710a4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions scripts/core/ui/components/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ export default class SearchBar extends React.Component<IProps, IState> {
)
: (
<ManualSearch
value={this.state.searchInputValue}
actionButtons={actionButtons}
onInputChange={(value) => this.setState({
searchInputValue: value,
})}
onSearch={() => this.props.onSearch(this.state.searchInputValue)}
onSearch={() => {
this.props.onSearch(this.state.searchInputValue);
}}
/>
)
}
Expand All @@ -160,6 +163,5 @@ export default class SearchBar extends React.Component<IProps, IState> {
}

SearchBar.defaultProps = {
timeout: 800,
allowCollapsed: true,
};
15 changes: 14 additions & 1 deletion scripts/core/ui/components/SearchBar/manual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@ interface IProps {
onSearch(): void;
onInputChange(value: string): void;
actionButtons: React.ReactNode;
value: string;
}

export class ManualSearch extends React.PureComponent<IProps> {
inputRef: HTMLInputElement;

componentDidMount() {
if (this.props.value !== '' || this.props.value != null) {
this.inputRef.focus();
}
}

render(): React.ReactNode {
return (
<div
className="sd-display--flex sd-flex--grow sd-flex--items-center sd-flex--align-self-stretch"
>
<input
ref={(e) => this.inputRef = e}
onKeyUp={(e) => {
if (e.key === 'Enter') {
this.props.onSearch();
}
}}
onChange={(e) => this.props.onInputChange(e.target.value)}
value={this.props.value}
onChange={(e) => {
this.props.onInputChange(e.target.value);
}}
type="text"
placeholder={gettext('Search...')}
/>
Expand Down

0 comments on commit 0710a4c

Please sign in to comment.