Tags input
Type text and press Enter or comma to add it as a removable tag.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- A native text input; Enter or comma adds the tag, and leaving the field adds pending text.
- Backspace in an empty field removes the last tag.
- Each tag has a button named "Remove <tag>"; the field takes its name from a label or aria-label.
- Styles in one file:
19-avatar.css
Import
import '@monoline/css';
import {TagsInput} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add tags-input
Usage
import {Field, TagsInput} from '@monoline/react';
<div style={{maxWidth: '360px'}}>
<Field label="Keywords">
<TagsInput placeholder="Add a keyword" defaultValue={['design', 'css']} />
</Field>
</div>
Examples
Props
TagsInputProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | string[] | – | The current tags when controlled. Pair with `onValueChange`. |
defaultValue | string[] | [] | The tags present at first when uncontrolled. Default empty. |
onValueChange | ((value: string[]) => void) | – | Called with the full list of tags after one is added or removed. |
size | "sm" | "md" | "lg" | 'md' | `md` (default), `sm` for dense layouts or `lg` for prominent forms. Heights match Button, Input and Select at each size. |
invalid | boolean | – | Marks the field as having an error: sets `aria-invalid` and shows the error border. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-disabled] | tags-input.css |
[data-invalid] | tags-input.css |
[data-size="lg"] | tags-input.css |
[data-size="sm"] | tags-input.css |
CSS classes
| Class | Stylesheet |
|---|---|
.avatar | 19-avatar.css |
.avatar-group | 19-avatar.css |
.avatar-lg | 19-avatar.css |
.avatar-line | 19-avatar.css |
.avatar-sm | 19-avatar.css |
.stat | 19-avatar.css |
.stat-note | 19-avatar.css |
.stat-value | 19-avatar.css |
.tag | 19-avatar.css |
.tags-input | tags-input.css |
.tags-input-field | tags-input.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.avatar {
border-color: var(--accent);
}
.avatar[data-disabled] {
background: var(--wash);
}
Accessibility
- A native text input; Enter or comma adds the tag, and leaving the field adds pending text.
- Backspace in an empty field removes the last tag.
- Each tag has a button named "Remove <tag>"; the field takes its name from a label or aria-label.
Keyboard
| Keys | Action |
|---|---|
| Backspace | In an empty field removes the last tag |