ant-design/components/mentions/demo/prefix.md
zombieJ ecb2eb6ede
feat: Add Mentions component (#16532)
* init

* first demo

* support empty

* add loading support

* add form sample

* update form sample

* omit value & defaultValue

* add 2 rest demo

* placement support

* update docs

* fix test

* update docs

* add test case

* fix lint

* follow textarea style

* update docs style
2019-05-17 12:05:03 +08:00

1.0 KiB

order title
3
zh-CN en-US
自定义触发字符 Customize Trigger Token

zh-CN

通过 prefix 属性自定义触发字符。默认为 @, 可以定义为数组。

en-US

Customize Trigger Token by prefix props. Default to @, Array<string> also supported.

import { Mentions } from 'antd';

const { Option } = Mentions;

const MOCK_DATA = {
  '@': ['afc163', 'zombiej', 'yesmeck'],
  '#': ['1.0', '2.0', '3.0'],
};

class App extends React.Component {
  state = {
    prefix: '@',
  };

  onSearch = (_, prefix) => {
    this.setState({ prefix });
  };

  render() {
    const { prefix } = this.state;

    return (
      <Mentions
        style={{ width: '100%' }}
        placeholder="input @ to mention people, # to mention tag"
        prefix={['@', '#']}
        onSearch={this.onSearch}
      >
        {(MOCK_DATA[prefix] || []).map(value => (
          <Option key={value} value={value}>
            {value}
          </Option>
        ))}
      </Mentions>
    );
  }
}

ReactDOM.render(<App />, mountNode);