A text input that allows values to be grouped as tags.
You should have the chayns-components
package installed. If that is not the
case already, run
yarn add chayns-components
or
npm i chayns-components
After the chayns-components
package is installed, you can import the component
and use it with React:
import React from 'react'
import { TagInput } from 'chayns-components';
// ...
<TagInput {...} />
The TagInput
-component takes the following props:
Name | Type | Default | Required |
---|---|---|---|
tags | Array<{ text: string | ReactNode }> |
||
value | string |
'' |
|
onAddTag | function |
||
onRemoveTag | function |
||
onChange | function |
||
placeholder | string |
||
className | string |
||
style | { [key: string]: string | number } |
||
disableRemove | boolean |
false |
|
design | number |
TagInput.DEFAULT_DESIGN |
|
max | number |
||
addTagOnBlur | boolean |
false |
|
left | ReactNode |
||
onKeyDown | function |
tags?: Array<{ text: string | ReactNode }>
An array of the current tags.
value?: string
The text value of the tag input.
onAddTag?: function
A callback that is invoked when the user adds a new tag (hits the enter
-key).
onRemoveTag?: function
A callback that is invoked when the user removes a tag.
onChange?: function
A callback that is invoked when the user changes the text inside the tag input.
placeholder?: string
A placeholder that is shown when the tag input is empty (does neither container a tag or text).
className?: string
A classname string that will be applied to the outer-most wrapper of the input.
style?: { [key: string]: string | number }
A React style object that will be applied to the outer-most wrapper of the input.
disableRemove?: boolean
Prevents removal of selected users and hides remove icon.
design?: number
The design of the input. Use either TagInput.DEFAULT_DESIGN
or
TagInput.BORDER_DESIGN
.
max?: number
The maximum number of tags selected at once.
addTagOnBlur?: boolean
Adds a tag on blur
left?: ReactNode
A string or ReactNode
that will be rendered on the left side of the tag input.
onKeyDown?: function
A callback for the keydown
-event.