Fix search input margin bug

This commit is contained in:
afc163 2016-05-12 11:38:49 +08:00
parent 8da28d82fe
commit 7b7f846161
3 changed files with 21 additions and 14 deletions

View File

@ -6,7 +6,7 @@ title: 搜索框
带有搜索按钮。 带有搜索按钮。
````jsx ````jsx
import { Icon, Input, Button } from 'antd'; import { Input, Button } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
const InputGroup = Input.Group; const InputGroup = Input.Group;
@ -33,6 +33,7 @@ const SearchInput = React.createClass({
} }
}, },
render() { render() {
const { style, size, ...restProps } = this.props;
const btnCls = classNames({ const btnCls = classNames({
'ant-search-btn': true, 'ant-search-btn': true,
'ant-search-btn-noempty': !!this.state.value.trim(), 'ant-search-btn-noempty': !!this.state.value.trim(),
@ -42,21 +43,21 @@ const SearchInput = React.createClass({
'ant-search-input-focus': this.state.focus, 'ant-search-input-focus': this.state.focus,
}); });
return ( return (
<InputGroup className={searchCls} style={this.props.style}> <div className="ant-search-input-wrapper" style={style}>
<Input {...this.props} value={this.state.value} onChange={this.handleInputChange} <InputGroup className={searchCls}>
<Input {...restProps} value={this.state.value} onChange={this.handleInputChange}
onFocus={this.handleFocusBlur} onBlur={this.handleFocusBlur} onPressEnter={this.handleSearch} /> onFocus={this.handleFocusBlur} onBlur={this.handleFocusBlur} onPressEnter={this.handleSearch} />
<div className="ant-input-group-wrap"> <div className="ant-input-group-wrap">
<Button className={btnCls} size={this.props.size} onClick={this.handleSearch}> <Button icon="search" className={btnCls} size={size} onClick={this.handleSearch} />
<Icon type="search" />
</Button>
</div> </div>
</InputGroup> </InputGroup>
</div>
); );
}, },
}); });
ReactDOM.render( ReactDOM.render(
<SearchInput placeholder="input search text" <SearchInput placeholder="input search text"
onSearch={(value) => console.log(value)} style={{ width: 200 }} /> onSearch={value => console.log(value)} style={{ width: 200 }} />
, mountNode); , mountNode);
```` ````

View File

@ -22,7 +22,7 @@ english: Form
这里我们分别封装了表单域 `<Form.Item />` 和输入控件 `<Input />` 这里我们分别封装了表单域 `<Form.Item />` 和输入控件 `<Input />`
```html ```jsx
<Form.Item {...props}> <Form.Item {...props}>
{children} {children}
</Form.Item> </Form.Item>
@ -30,7 +30,7 @@ english: Form
## Input 输入框 ## Input 输入框
```html ```jsx
<Input {...props} /> <Input {...props} />
``` ```

View File

@ -200,14 +200,20 @@ form {
} }
} }
.ant-search-input-wrapper {
display: inline-block;
vertical-align: middle;
}
.ant-search-input { .ant-search-input {
&.ant-input-group .ant-input:first-child { &.ant-input-group .ant-input:first-child {
border-radius: @border-radius-base; border-radius: @border-radius-base;
position: absolute;
top: -1px;
} }
.ant-search-btn { .ant-search-btn {
.btn-default; .btn-default;
border-radius: 0 @border-radius-base - 1 @border-radius-base - 1 0; border-radius: 0 @border-radius-base - 1 @border-radius-base - 1 0;
margin-left: -100%;
left: -1px; left: -1px;
position: relative; position: relative;
border-width: 0 0 0 1px; border-width: 0 0 0 1px;