Skip to content

Commit

Permalink
fix Input prefix and suffix vertical align style
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Jan 5, 2017
1 parent d4132ac commit c4ac4d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 87 deletions.
74 changes: 16 additions & 58 deletions components/input/demo/presuffix.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title:

## en-US

Add a prefix or suffix icon on the input.
Add prefix or suffix icons inside input.

````jsx
import { Input, Icon } from 'antd';
Expand All @@ -21,69 +21,27 @@ class App extends React.Component {
super(props);
this.state = {
userName: '',
domain: '',
};
this.onChangeUserName = this.emitChange.bind(this, 'userName');
this.onChangeDomain = this.emitChange.bind(this, 'domain');
}
emitEmpty(type) {
this[`${type}Input`].focus();
this.setState({
[type]: '',
});
emitEmpty = () => {
this.userNameInput.focus();
this.setState({ userName: '' });
}
emitChange(type, e) {
this.setState({
[type]: e.target.value,
});
}
renderClearIcon(type) {
const value = this.state[type];
const empty = this.emitEmpty.bind(this, type);
return value ? (
<Icon
type="close-circle"
onClick={empty}
/>
) : null;
}
renderUserNameInput() {
const { userName } = this.state;
return (
<div style={{ marginBottom: 16 }}>
<Input
placeholder="Enter your userName"
prefix={<Icon type="user" />}
suffix={this.renderClearIcon('userName')}
value={userName}
onChange={this.onChangeUserName}
ref={node => this.userNameInput = node}
/>
</div>
);
}
renderDomainInput() {
const { domain } = this.state;
return (
<div style={{ marginBottom: 16 }}>
<Input
placeholder="Input your domain"
addonBefore="Http://"
addonAfter=".com"
suffix={this.renderClearIcon('domain')}
value={domain}
onChange={this.onChangeDomain}
ref={node => this.domainInput = node}
/>
</div>
);
onChangeUserName = (e) => {
this.setState({ userName: e.target.value });
}
render() {
const { userName } = this.state;
const suffix = userName ? <Icon type="close-circle" onClick={this.emitEmpty} /> : null;
return (
<div>
{this.renderUserNameInput()}
{this.renderDomainInput()}
</div>
<Input
placeholder="Enter your userName"
prefix={<Icon type="user" />}
suffix={suffix}
value={userName}
onChange={this.onChangeUserName}
ref={node => this.userNameInput = node}
/>
);
}
}
Expand Down
37 changes: 8 additions & 29 deletions components/input/style/mixin.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "../../style/themes/default";
@import "../../style/mixins/index";

@input-presuffix-width: 16;
@input-presuffix-width: 17;

// size mixins for input
.input-lg() {
Expand Down Expand Up @@ -85,23 +85,6 @@
}
}

// Input with icons, you can define @height if you wish to change the input size
.input-with-icon(@height: @input-height-base) {
position: relative;

.@{iconfont-css-prefix} {
position: absolute;
bottom: 0;
right: 0;
z-index: 2;
.square(@height);
font-size: @font-size-lg;
line-height: @height;
text-align: center;
pointer-events: none;
}
}

// label input
.input-group(@inputClass) {
position: relative;
Expand Down Expand Up @@ -302,20 +285,17 @@
z-index: 1;
}

&:hover .@{inputClass} {
.hover();
}

.@{inputClass}-prefix,
.@{inputClass}-suffix {
position: absolute;
top: 0;
bottom: 0;
top: 50%;
transform: translateY(-50%);
z-index: 2;

&:after {
content: '';
display: inline-block;
width: 0;
height: 100%;
vertical-align: middle;
}
line-height: 1.2;
}

.@{inputClass}-prefix {
Expand All @@ -334,4 +314,3 @@
padding-right: @input-padding-horizontal + @input-presuffix-width;
}
}

0 comments on commit c4ac4d1

Please sign in to comment.