Skip to content

Commit

Permalink
Merge e43fcb2 into 21c7ade
Browse files Browse the repository at this point in the history
  • Loading branch information
ryouaki committed Jan 4, 2017
2 parents 21c7ade + e43fcb2 commit 4dbb2b7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/searchbar/searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ class SearchBar extends React.Component {

this.setState({text: '', clearing: true});
if(this.props.onClear) this.props.onClear(e);
ReactDOM.findDOMNode(this.refs.searchInput).focus()
// In most cases, you can attach a ref to the DOM node and avoid using findDOMNode at all.
// When render returns null or false, findDOMNode returns null.
// 这里是截取官网的说明,在ref回调函数内确实会返回null,尤其是配合redux使用的时候,这个时候需要对其进行null判断
this.refs.searchInput.focus();
// ReactDOM.findDOMNode(this.refs.searchInput).focus()
if(this.props.onChange) this.props.onChange('',e);
}

Expand Down Expand Up @@ -134,7 +138,12 @@ class SearchBar extends React.Component {
</div>
<label
className='weui-search-bar__label'
onClick={e=>ReactDOM.findDOMNode(this.refs.searchInput).focus()}
onClick={()=>{
let searchInput = this.refs.searchInput;
if (searchInput) {
searchInput.focus();
}
}}
style={{display: this.state.text ? 'none': null}}
>
<Icon value='search'/>
Expand Down

0 comments on commit 4dbb2b7

Please sign in to comment.