mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-01 05:06:53 +08:00
fix Input prefix and suffix vertical align style
This commit is contained in:
parent
d4132ac558
commit
c4ac4d1eca
@ -11,7 +11,7 @@ title:
|
|||||||
|
|
||||||
## en-US
|
## en-US
|
||||||
|
|
||||||
Add a prefix or suffix icon on the input.
|
Add prefix or suffix icons inside input.
|
||||||
|
|
||||||
````jsx
|
````jsx
|
||||||
import { Input, Icon } from 'antd';
|
import { Input, Icon } from 'antd';
|
||||||
@ -21,69 +21,27 @@ class App extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
userName: '',
|
userName: '',
|
||||||
domain: '',
|
|
||||||
};
|
};
|
||||||
this.onChangeUserName = this.emitChange.bind(this, 'userName');
|
|
||||||
this.onChangeDomain = this.emitChange.bind(this, 'domain');
|
|
||||||
}
|
}
|
||||||
emitEmpty(type) {
|
emitEmpty = () => {
|
||||||
this[`${type}Input`].focus();
|
this.userNameInput.focus();
|
||||||
this.setState({
|
this.setState({ userName: '' });
|
||||||
[type]: '',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
emitChange(type, e) {
|
onChangeUserName = (e) => {
|
||||||
this.setState({
|
this.setState({ userName: e.target.value });
|
||||||
[type]: e.target.value,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
renderClearIcon(type) {
|
render() {
|
||||||
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;
|
const { userName } = this.state;
|
||||||
|
const suffix = userName ? <Icon type="close-circle" onClick={this.emitEmpty} /> : null;
|
||||||
return (
|
return (
|
||||||
<div style={{ marginBottom: 16 }}>
|
|
||||||
<Input
|
<Input
|
||||||
placeholder="Enter your userName"
|
placeholder="Enter your userName"
|
||||||
prefix={<Icon type="user" />}
|
prefix={<Icon type="user" />}
|
||||||
suffix={this.renderClearIcon('userName')}
|
suffix={suffix}
|
||||||
value={userName}
|
value={userName}
|
||||||
onChange={this.onChangeUserName}
|
onChange={this.onChangeUserName}
|
||||||
ref={node => this.userNameInput = node}
|
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{this.renderUserNameInput()}
|
|
||||||
{this.renderDomainInput()}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@import "../../style/themes/default";
|
@import "../../style/themes/default";
|
||||||
@import "../../style/mixins/index";
|
@import "../../style/mixins/index";
|
||||||
|
|
||||||
@input-presuffix-width: 16;
|
@input-presuffix-width: 17;
|
||||||
|
|
||||||
// size mixins for input
|
// size mixins for input
|
||||||
.input-lg() {
|
.input-lg() {
|
||||||
@ -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
|
// label input
|
||||||
.input-group(@inputClass) {
|
.input-group(@inputClass) {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -302,20 +285,17 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:hover .@{inputClass} {
|
||||||
|
.hover();
|
||||||
|
}
|
||||||
|
|
||||||
.@{inputClass}-prefix,
|
.@{inputClass}-prefix,
|
||||||
.@{inputClass}-suffix {
|
.@{inputClass}-suffix {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 50%;
|
||||||
bottom: 0;
|
transform: translateY(-50%);
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
line-height: 1.2;
|
||||||
&:after {
|
|
||||||
content: '';
|
|
||||||
display: inline-block;
|
|
||||||
width: 0;
|
|
||||||
height: 100%;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.@{inputClass}-prefix {
|
.@{inputClass}-prefix {
|
||||||
@ -334,4 +314,3 @@
|
|||||||
padding-right: @input-padding-horizontal + @input-presuffix-width;
|
padding-right: @input-padding-horizontal + @input-presuffix-width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user