A react tag input built on mantine component library and it adapts well with the theme of the library.
npm install mantine-tag-input
Installation
------------
To start using mantine Tag Input in your React project, follow these simple steps:
1. Install the package via npm or yarn:
bash
``bash`
npm install mantine-tag-input
or
bash
`bash`
yarn add mantine-tag-input
or
bash
`bash`
pnpm add mantine-tag-input
2. Import the component in your desired file:
javascript
`javascript`
import { TagsInput } from 'mantine-tag-input';
Props
-----
* Type: stringundefined
* Default:
The name prop allows you to specify the name attribute for the input field. This can be useful for form submission or accessing the input value via JavaScript.
* Type: stringundefined
* Default:
The placeHolder prop defines the placeholder text that appears in the input field when no tags are present.
* Type: string[][]
* Default:
The value prop accepts an array of strings representing the initial tags to be displayed in the input field.
* Type: (tags: string[]) => voidundefined
* Default:
The onChange prop is a callback function that is triggered whenever there is a change in the tags. It receives an array of strings representing the updated tags as a parameter.
* Type: anyundefined
* Default:
The onBlur prop allows you to define a function that is called when the input field loses focus.
* Type: string[]undefined
* Default:
The separators prop allows you to specify an array of strings that will act as separators for creating multiple tags. By default, the tags are separated by commas.
* Type: booleanfalse
* Default:
The disableBackspaceRemove prop, when set to true, prevents the removal of tags by pressing the Backspace key.
* Type: (tag: string) => voidundefined
* Default:
The onExisting prop is a callback function that is triggered when an existing tag is added. It receives the added tag as a parameter.
* Type: (tag: string) => voidundefined
* Default:
The onRemoved prop is a callback function that is triggered when a tag is removed. It receives the removed tag as a parameter.
* Type: booleanfalse
* Default:
The disabled prop, when set to true, disables the input field and prevents any further interaction with the component.
* Type: booleanfalse
* Default:
The isEditOnRemove prop, when set to true, allows users to edit tags after they have been added.
* Type: (tag: string, existingTags: string[]) => booleanundefined
* Default:
The beforeAddValidate prop allows you to define a validation function that is called before a tag is added. The function receives the tag to be added and the existing tags as parameters, and should return a boolean value (true to allow the addition and false to prevent it).
* Type: (e: React.KeyboardEventundefined
* Default:
The onKeyUp prop is a callback function that is triggered when a key is released within the input field.
* Type: 'xs' | 'sm' | 'md' | 'lg' | 'xl'undefined
* Default:
The size prop allows you to specify the size of the input field. It accepts one of the following values: 'xs', 'sm', 'md', 'lg', or 'xl'.
* Type: React.ReactNodeundefined
* Default:
The error prop allows you to display an error message below the input field. It accepts a React node as a value.
* Type: BadgePropsundefined
* Default:
The badgeProps prop allows you to pass mantine badge props to the badge component.
* Type: CloseButtonPropsundefined
* Default:
The closeButtonProps prop allows you to pass mantine close button props to the close button component.
Example Usage
-------------
`javascript
import { MantineTagsInput } from 'mantine-tag-input';
const MyComponent = () => {
const handleTagChange = (tags) => {
// Handle tag change logic here
};
const handleTagRemove = (tag) => {
// Handle tag removal logic here
};
return (
placeHolder="Enter tags..."
value={['tag1', 'tag2', 'tag3']}
onChange={handleTagChange}
onRemoved={handleTagRemove}
separators={[' ', ',']}
disableBackspaceRemove={true}
isEditOnRemove={true}
/>
);
};
``