2017-01-01 01:06:19 +08:00
|
|
|
---
|
|
|
|
order: 8
|
|
|
|
title:
|
|
|
|
zh-CN: 前缀和后缀
|
|
|
|
en-US: prefix and suffix
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
在输入框上添加前缀或后缀图标。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2017-01-05 15:19:42 +08:00
|
|
|
Add prefix or suffix icons inside input.
|
2017-01-01 01:06:19 +08:00
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
````jsx
|
2017-01-01 01:06:19 +08:00
|
|
|
import { Input, Icon } from 'antd';
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
userName: '',
|
|
|
|
};
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-01-05 15:19:42 +08:00
|
|
|
emitEmpty = () => {
|
|
|
|
this.userNameInput.focus();
|
|
|
|
this.setState({ userName: '' });
|
2017-01-01 01:06:19 +08:00
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-01-05 15:19:42 +08:00
|
|
|
onChangeUserName = (e) => {
|
|
|
|
this.setState({ userName: e.target.value });
|
2017-01-01 01:06:19 +08:00
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-01-01 01:06:19 +08:00
|
|
|
render() {
|
2017-01-05 15:19:42 +08:00
|
|
|
const { userName } = this.state;
|
|
|
|
const suffix = userName ? <Icon type="close-circle" onClick={this.emitEmpty} /> : null;
|
2017-01-01 01:06:19 +08:00
|
|
|
return (
|
2017-01-05 15:19:42 +08:00
|
|
|
<Input
|
2017-10-18 17:16:14 +08:00
|
|
|
placeholder="Enter your username"
|
2017-11-06 21:28:51 +08:00
|
|
|
prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
2017-01-05 15:19:42 +08:00
|
|
|
suffix={suffix}
|
|
|
|
value={userName}
|
|
|
|
onChange={this.onChangeUserName}
|
|
|
|
ref={node => this.userNameInput = node}
|
|
|
|
/>
|
2017-01-01 01:06:19 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
|
|
|
````
|
|
|
|
|
|
|
|
````css
|
|
|
|
.anticon-close-circle {
|
|
|
|
cursor: pointer;
|
|
|
|
color: #ccc;
|
|
|
|
transition: color 0.3s;
|
2017-01-09 14:24:08 +08:00
|
|
|
font-size: 12px;
|
2017-01-01 01:06:19 +08:00
|
|
|
}
|
|
|
|
.anticon-close-circle:hover {
|
|
|
|
color: #999;
|
|
|
|
}
|
2017-03-05 20:01:52 +08:00
|
|
|
.anticon-close-circle:active {
|
|
|
|
color: #666;
|
|
|
|
}
|
2017-01-01 01:06:19 +08:00
|
|
|
````
|