ant-design/components/mentions/index.en-US.md
Eden Wang 28aaeafbbc
feat(mentions): supports 'allowClear' option (#46396)
* feat(mentions): supports 'allowClear' option

* feat(mentions): add allowClear testcase

* feat(mentions): update package and styles

* feat(mentions): update lint and styles

* fix: fixed lint error

* test: add case for custom clearIcon

* feat: add useAllowClear hook

* feat: rename useAllowClear to getAllowClear

* feat: rename useAllowClear to getAllowClear

* feat(mentions): add demo for allowClear

* feat(mentions): update demo desc

* feat(mentions): update demo desc

* feat(mentions): style align middle

* feat: add multi line mentions demo and update icon position

* feat: fixing visual regression report

---------

Co-authored-by: afc163 <afc163@gmail.com>
2023-12-25 10:37:26 +08:00

4.2 KiB
Raw Blame History

category group title cover coverDark demo
Components Data Entry Mentions https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*e4bXT7Uhi9YAAAAAAAAAAAAADrJ8AQ/original https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*pxR2S53P_xoAAAAAAAAAAAAADrJ8AQ/original
cols
2

Mention component.

When To Use

When you need to mention someone or something.

Usage upgrade after 5.1.0

// works when >=5.1.0, recommended ✅
const options = [{ value: 'sample', label: 'sample' }];
return <Mentions options={options} />;

// works when <5.1.0, deprecated when >=5.1.0 🙅🏻‍♀️
return (
  <Mentions onChange={onChange}>
    <Mentions.Option value="sample">Sample</Mentions.Option>
  </Mentions>
);

Examples

Basic Variants Asynchronous loading With Form Customize Trigger Token disabled or readOnly Placement With clear icon autoSize Status _InternalPanelDoNotUseOrYouWillBeFired Component Token

API

Common props refCommon props

Mention

Property Description Type Default Version
allowClear Show clear button boolean | { clearIcon?: ReactNode } false 5.13.0
autoFocus Auto get focus when component mounted boolean false
autoSize Textarea height autosize feature, can be set to true | false or an object { minRows: 2, maxRows: 6 } boolean | object false
defaultValue Default value string -
filterOption Customize filter option logic false | (input: string, option: OptionProps) => boolean -
getPopupContainer Set the mount HTML node for suggestions () => HTMLElement -
notFoundContent Set mentions content when not match ReactNode Not Found
placement Set popup placement top | bottom bottom
prefix Set trigger prefix keyword string | string[] @
split Set split string before and after selected mention string
status Set validation status 'error' | 'warning' | 'success' | 'validating' - 4.19.0
validateSearch Customize trigger search logic (text: string, props: MentionsProps) => void -
value Set value of mentions string -
variant Variants of Input outlined | borderless | filled outlined 5.13.0
onBlur Trigger when mentions lose focus () => void -
onChange Trigger when value changed (text: string) => void -
onFocus Trigger when mentions get focus () => void -
onResize The callback function that is triggered when textarea resize function({ width, height }) -
onSearch Trigger when prefix hit (text: string, prefix: string) => void -
onSelect Trigger when user select the option (option: OptionProps, prefix: string) => void -
options Option Configuration Options [] 5.1.0

Mention methods

Name Description
blur() Remove focus
focus() Get focus

Option

Property Description Type Default
label Title of the option React.ReactNode -
key The key value of the option string -
disabled Optional boolean -
className className string -
style The style of the option React.CSSProperties -

Design Token