2015-12-02 19:33:26 +08:00
|
|
|
# 搜索框
|
|
|
|
|
|
|
|
- order: 10
|
|
|
|
|
|
|
|
带有搜索按钮。
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
````jsx
|
|
|
|
import { Icon, Input, Button } from 'antd';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
const InputGroup = Input.Group;
|
|
|
|
|
|
|
|
const SearchInput = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
value: '',
|
2016-03-25 19:58:57 +08:00
|
|
|
focus: false,
|
2015-12-02 19:33:26 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
handleInputChange(e) {
|
|
|
|
this.setState({
|
|
|
|
value: e.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleFocusBlur(e) {
|
|
|
|
this.setState({
|
|
|
|
focus: e.target === document.activeElement,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleSearch() {
|
|
|
|
if (this.props.onSearch) {
|
|
|
|
this.props.onSearch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
const btnCls = classNames({
|
|
|
|
'ant-search-btn': true,
|
|
|
|
'ant-search-btn-noempty': !!this.state.value.trim(),
|
|
|
|
});
|
|
|
|
const searchCls = classNames({
|
|
|
|
'ant-search-input': true,
|
|
|
|
'ant-search-input-focus': this.state.focus,
|
|
|
|
});
|
2016-01-07 16:29:12 +08:00
|
|
|
return (
|
|
|
|
<InputGroup className={searchCls} style={this.props.style}>
|
|
|
|
<Input {...this.props} value={this.state.value} onChange={this.handleInputChange}
|
2016-01-08 14:41:05 +08:00
|
|
|
onFocus={this.handleFocusBlur} onBlur={this.handleFocusBlur} />
|
2016-04-11 14:03:31 +08:00
|
|
|
<div className="ant-input-group-wrap">
|
|
|
|
<Button className={btnCls} size={this.props.size} onClick={this.handleSearch}>
|
|
|
|
<Icon type="search" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</InputGroup>
|
2016-01-07 16:29:12 +08:00
|
|
|
);
|
2015-12-02 19:33:26 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ReactDOM.render(
|
2016-01-27 16:44:50 +08:00
|
|
|
<SearchInput placeholder="input search text" style={{ width: 200 }} />
|
2015-12-29 12:08:58 +08:00
|
|
|
, mountNode);
|
2015-12-02 19:33:26 +08:00
|
|
|
````
|