feat: Add search input to collection and home (#1149)

* feat: Add search input to collection and home

* Tweak spacing

* Add input to drafts/starred too
This commit is contained in:
Tom Moor
2020-01-09 19:14:34 -08:00
committed by GitHub
parent 0ccbc6126b
commit cd3035a692
9 changed files with 150 additions and 12 deletions

View File

@ -6,12 +6,21 @@ import Flex from 'shared/components/Flex';
type Props = {
onChange: string => void,
defaultValue?: string,
theme: Object,
};
class SearchField extends React.Component<Props> {
input: ?HTMLInputElement;
componentDidMount() {
if (this.props && this.input) {
// ensure that focus is placed at end of input
const len = (this.props.defaultValue || '').length;
this.input.setSelectionRange(len, len);
}
}
handleChange = (ev: SyntheticEvent<HTMLInputElement>) => {
this.props.onChange(ev.currentTarget.value ? ev.currentTarget.value : '');
};
@ -34,7 +43,7 @@ class SearchField extends React.Component<Props> {
ref={ref => (this.input = ref)}
onChange={this.handleChange}
spellCheck="false"
placeholder="search…"
placeholder="Search…"
type="search"
autoFocus
/>