2016-10-20 13:51:44 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title:
|
|
|
|
zh-CN: 受控模式
|
|
|
|
en-US: Controlled
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
受控模式.
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Controlled mode.
|
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
````jsx
|
2016-10-20 13:51:44 +08:00
|
|
|
import { Mention } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-05-05 14:53:46 +08:00
|
|
|
const { toContentState } = Mention;
|
2016-10-20 13:51:44 +08:00
|
|
|
|
2017-02-20 21:39:07 +08:00
|
|
|
class App extends React.Component {
|
2017-02-20 21:47:57 +08:00
|
|
|
state = {
|
2017-05-05 14:53:46 +08:00
|
|
|
value: toContentState('@afc163'),
|
2017-02-20 21:39:07 +08:00
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-06-28 16:02:38 +08:00
|
|
|
componentDidMount() {
|
|
|
|
this.mention.focus();
|
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-02-20 21:39:07 +08:00
|
|
|
handleChange = (editorState) => {
|
2016-10-20 13:51:44 +08:00
|
|
|
this.setState({
|
|
|
|
value: editorState,
|
|
|
|
});
|
2017-02-20 21:39:07 +08:00
|
|
|
}
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2016-10-20 13:51:44 +08:00
|
|
|
render() {
|
2017-02-20 21:39:07 +08:00
|
|
|
return (
|
|
|
|
<Mention
|
2017-06-28 16:02:38 +08:00
|
|
|
ref={ele => this.mention = ele}
|
2018-12-18 18:32:21 +08:00
|
|
|
defaultSuggestions={['afc163', 'benjycui', 'yiminghe', 'RaoHai', '中文', 'にほんご']}
|
2017-02-20 21:39:07 +08:00
|
|
|
value={this.state.value}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
/>
|
|
|
|
);
|
2017-02-20 22:09:13 +08:00
|
|
|
}
|
2017-02-20 22:11:39 +08:00
|
|
|
}
|
2016-10-20 13:51:44 +08:00
|
|
|
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
|
|
|
````
|