diff --git a/src/components/HeaderSearch/index.js b/src/components/HeaderSearch/index.js index 49b9072f836cdbc74b776e3c01585c7b6dc903e5..295a837a6716c129622e93e9ec985ffdb1895b7a 100644 --- a/src/components/HeaderSearch/index.js +++ b/src/components/HeaderSearch/index.js @@ -12,6 +12,7 @@ export default class HeaderSearch extends PureComponent { className: '', placeholder: '', dataSource: [], + defaultOpen: false, }; static propTypes = { className: PropTypes.string, @@ -20,9 +21,10 @@ export default class HeaderSearch extends PureComponent { onPressEnter: PropTypes.func, defaultActiveFirstOption: PropTypes.bool, dataSource: PropTypes.array, + defaultOpen: PropTypes.bool, }; state = { - searchMode: false, + searchMode: this.props.defaultOpen, value: '', }; componentWillUnmount() { @@ -56,6 +58,7 @@ export default class HeaderSearch extends PureComponent { }; render() { const { className, placeholder, ...restProps } = this.props; + delete restProps.defaultOpen; // for rc-select not affected const inputClass = classNames(styles.input, { [styles.show]: this.state.searchMode, }); diff --git a/src/components/HeaderSearch/index.md b/src/components/HeaderSearch/index.md index 5c8fd7019885488efa17590ff4194be0892e0c6c..3d4d3c222d92ed7de315fe88a0268ac94e9936b2 100644 --- a/src/components/HeaderSearch/index.md +++ b/src/components/HeaderSearch/index.md @@ -18,3 +18,4 @@ dataSource | 当前提示内容列表 | string[] | - onSearch | 选择某项或按下回车时的回调 | function(value) | - onChange | 输入搜索字符的回调 | function(value) | - onPressEnter | 按下回车时的回调 | function(value) | - +defaultOpen | 输入框首次显示是否打开 | boolean | false