TagInput
TagInput component is a robust, minimal and performant input field for creating multiple tags.
Import
Usage
Here's a basic usage of the TagInput component.
Editable Example
example tag
Sizes
Editable Example
example tag
Max tags
Editable Example
example tag
Editable
Editable Example
example tag
Read Only
Editable Example
example tag
Remove on backspace
Editable Example
example tag
Allow line break
Editable Example
example tag
Validator
Editable Example
example tag
Add tag on blur
Editable Example
example tag
Props
The TagInput component composes PseudoBox so you can pass all
PseudoBox
props, and React.InputHTMLAttributes
.
Name | Type | Default | Description |
---|---|---|---|
tags | string[] | required | A string array containing a list of tags. |
onChange | function | required | A function that receives the updated tags, used to update your state. |
placeholder | string | The placeholder for the inner input field. | |
size | sm , md | md | The size of the input field. |
maxTags | number | Set the maximum number of tags allowed. Once reached, the inner input field will be hidden. Defaults to undefined which is unlimited. | |
editable | boolean | false | If enabled, a user can click a tag and change it's value directly. |
readOnly | boolean | false | If enabled, tags cannot be edited or removed and the inner input field is hidden. |
removeOnBackspace | boolean | true | If enabled, a user can delete a tag if they press backspace when focused on the inner input field or a specific tag input field. |
allowLineBreak | boolean | false | If enabled, tags will be broken into a new line when the container is overflow. |
validator | function | A function that receives a specific tag value that a user is attempting to add and returns a boolean indicating if it is valid. If invalid, the tag will not be added. | |
tagRender | (props: {tag: string, onUpdate: function, onDelete: function, index: number}) => JSX.Element | Custom render view for tags. | |
hasInputWrapper | boolean | true | If true, use form input style. |
splitChar | string | Add multiple items by splitting the input value by the provided string. | |
addTagsOnBlur | boolean | false | If enabled, a tag will be added or updated on blur. |
onInputChange | (string) => void | A callback function when the input changes. |