Skip to content

Commit

Permalink
fix(SearchBar): cancel should blur. close #1721 (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoidjk authored Aug 29, 2017
1 parent 36b82ce commit 99c9c32
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions components/search-bar/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ export default class SearchBar extends React.Component<SearchBarProps, SearchBar
this.props.onBlur();
}
}

onClear = () => {
this.blurFromOnClear = true;
this.doClear();
}
doClear = (blurFromOnClear = true) => {
this.blurFromOnClear = blurFromOnClear;

if (!('value' in this.props)) {
this.setState({ value: '' });
Expand All @@ -161,14 +163,16 @@ export default class SearchBar extends React.Component<SearchBarProps, SearchBar
if (this.props.onChange) {
this.props.onChange('');
}
this.refs.searchInput.focus();
if (blurFromOnClear) {
this.refs.searchInput.focus();
}
}

onCancel = () => {
if (this.props.onCancel) {
this.props.onCancel(this.state.value);
} else {
this.onClear();
this.doClear(false);
}
}

Expand Down

0 comments on commit 99c9c32

Please sign in to comment.