JGuang

InputTag

InputTag · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

InputTag

An input box which will display your input as tags.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Prefix/addBefore/addAfter: Prefix / addBefore / addAfter
  • Different sizes: Use size to specify the size of InputTag
  • LabelInValue: Use labelInValue=true to get label of the selected option
  • Validate/format input: Use validate to enable custom validator for input value. Additionally, non-boolean can be returned to format user-entered strings in a specific value format.
  • Save on blur: Set saveOnBlur to automatically save the text being entered as a label when it loses focus.
  • Render tag: Use renderTag to customize tag rendering
  • Draggable: Specify the dragToSort property to allow sort the entered values by dragging.
  • Token Separator: Set tokenSeparators to use automatic word segmentation. Try copying text below into the input box.
  • MaxTagCount: Set the maximum number of displayed tags through maxTagCount, and customize the +x partially rendered nodes through maxTagCount.render.
  • Responsive Tags: Use maxTagCount=responsive to dynamically display the number of Tags based on the container size. It will monitor the size changes of all Tags and containers, so it is not recommended to use it when there are a large number of tags, as there may be performance issues. Drag and animation effects are not available at this time.

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

InputTag

PropertyDescriptionTypeDefaultValueVersion
allowClearWhether to allow clear input valueboolean--
animationWhether to add animation for internal label changesbooleantrue2.15.0
autoFocusWhether the input is focused by defaultboolean--
disabledWhether the input is disabledboolean--
dragToSortWeather it is possible to sort tags by dragboolean-2.27.0
errorWhether the input is error.(Deprecated, removed in the next major version, use status='error' instead)boolean--
labelInValueIf true, the incoming and callback values will be {label: '', value: '') formatboolean--
readOnlyWhether the input is read onlyboolean--
saveOnBlurWhether to automatically store the text entering when blur InputTagboolean-2.25.0
inputValueTo set input valuestring--
placeholderPlaceholder of input elementstring--
maxTagCountThe maximum number of tags is displayed| number| 'responsive'| {count: number | 'responsive';render?: (invisibleTagCount: number, value: T[]) => ReactNode;popoverProps?: Partial<PopoverProps>;}-2.59.0. responsive in 2.62.0
sizeDifferent sizes'mini' | 'small' | 'default' | 'large'--
statusStatus'error' | 'warning'-2.45.0
addAfterThe label text displayed after (on the right side of) the input-tag fieldReactNode-2.47.0
addBeforeThe label text displayed before (on the left side of) the input-tag fieldReactNode-2.47.0
prefixThe prefix icon or text for the input-tagReactNode-2.47.0
suffixThe suffix for the InputTagReactNode--
classNameAdditional css classstring | string[]--
defaultValueTo set default valueT[]--
iconCustom icons{ removeIcon?: ReactNode; clearIcon?: ReactNode }--
styleAdditional styleCSSProperties--
tokenSeparatorsSeparator used to tokenizestring[]-2.44.0
validateFunction to check user's input, which is triggered when Enter is pressed(inputValue: string, values: T[]) => boolean | Promise<boolean> | T | Promise<T>(inputValue, values) => inputValue && values.every((item) => item !== inputValue)return type T and Promise<T> in 2.37.0
valueTo set valueT[]--
onBlurCallback when input is blurred(e) => void--
onChangeCallback when value changes(value: T[], reason: ValueChangeReason) => void-reason in 2.27.0
onClearCallback when clear button is clicked() => void-2.20.0
onClickCallback when the component is clicked(e) => void--
onFocusCallback when input is focused(e) => void--
onInputChangeCallback when the value of input changes(inputValue: string, event?) => void--
onKeyDownCallback when the keyboard is pressed(e) => void--
onPasteCallback when you paste text in input box(e) => void--
onPressEnterCallback when Enter key is pressed(e) => void--
onRemoveCallback when a tag is removed(value: T, index: number, event) => void--
renderTagCustom tag rendering, props is the current tag attribute, index is the order of the current tag, values is the value of all tags(props: {value: any;label: ReactNode;closable: boolean;onClose: (event) => void;},index: number,values: ObjectValueType[]) => ReactNode-index、values added in 2.15.0

ObjectValueType

export type ObjectValueType = {
  value?: any;
  label?: ReactNode;
  closable?: boolean;
};

ValueChangeReason

export type ValueChangeReason = "add" | "remove" | "clear" | "sort";