Skip to content

Commit

Permalink
fix(Search): disable not work
Browse files Browse the repository at this point in the history
  • Loading branch information
tao1991123 committed Jan 21, 2019
1 parent edafccd commit 1bedb19
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ class Search extends React.Component {
* 是否显示清除按钮
*/
hasClear: PropTypes.bool,
/**
* 是否禁用
*/
disabled: PropTypes.bool,
locale: PropTypes.object,
rtl: PropTypes.bool,

};

static defaultProps = {
Expand All @@ -125,6 +130,7 @@ class Search extends React.Component {
onSearch: func.noop,
onFilterChange: func.noop,
hasClear: false,
disabled: false,
};

constructor(props) {
Expand All @@ -151,6 +157,9 @@ class Search extends React.Component {
}

onChange = (value) => {
if (this.props.disabled) {
return;
}
if (!('value' in this.props)) {
this.setState({ value });
}
Expand All @@ -159,10 +168,16 @@ class Search extends React.Component {
};

onSearch = () => {
if (this.props.disabled) {
return;
}
this.props.onSearch(this.state.value, this.state.filterValue);
};

onFilterChange = (filterValue) => {
if (this.props.disabled) {
return;
}
if (!('filterValue' in this.props)) {
this.setState({ filterValue });
}
Expand All @@ -171,14 +186,17 @@ class Search extends React.Component {
};

onKeyDown = (e) => {
if (this.props.disabled) {
return;
}
if (e.keyCode !== KEYCODE.ENTER) {
return;
}
this.onSearch();
}
render() {
const {
shape, filter, hasIcon,
shape, filter, hasIcon, disabled,
placeholder, type, className,
style, size, prefix, searchText,
dataSource, filterProps, buttonProps,
Expand Down Expand Up @@ -206,7 +224,7 @@ class Search extends React.Component {
[`${prefix}search-btn`]: true,
[buttonProps.className]: !!buttonProps.className
});
searchBtn = (<Button {...buttonProps} tabIndex="0" className={cls} onClick={this.onSearch} onKeyDown={this.onKeyDown}>
searchBtn = (<Button {...buttonProps} tabIndex="0" className={cls} onClick={this.onSearch} onKeyDown={this.onKeyDown} disabled={disabled}>
{hasIcon ? <Icon type="search" /> : null}
{searchText ? <span className={`${prefix}search-btn-text`}>{searchText}</span> : null}
</Button>);
Expand All @@ -219,6 +237,7 @@ class Search extends React.Component {
hasBorder={false}
dataSource={filter}
size={size}
disabled={disabled}
value={this.state.filterValue}
onChange={this.onFilterChange}
/>
Expand Down Expand Up @@ -246,6 +265,7 @@ class Search extends React.Component {
value={this.state.value}
onChange={this.onChange}
popupContent={popupContent}
disabled={disabled}
/>
</Group>);

Expand Down

0 comments on commit 1bedb19

Please sign in to comment.