Playground

Tags input

Type text and press Enter or comma to add it as a removable tag.

  • 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

Add keywords

Press Enter or comma to add. Backspace removes the last one.

Props

TagsInputProps

PropTypeDefaultDescription
valuestring[]–The current tags when controlled. Pair with `onValueChange`.
defaultValuestring[][]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.
invalidboolean–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.

AttributeStylesheet
[data-disabled]tags-input.css
[data-invalid]tags-input.css
[data-size="lg"]tags-input.css
[data-size="sm"]tags-input.css

CSS classes

ClassStylesheet
.avatar19-avatar.css
.avatar-group19-avatar.css
.avatar-lg19-avatar.css
.avatar-line19-avatar.css
.avatar-sm19-avatar.css
.stat19-avatar.css
.stat-note19-avatar.css
.stat-value19-avatar.css
.tag19-avatar.css
.tags-inputtags-input.css
.tags-input-fieldtags-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

KeysAction
BackspaceIn an empty field removes the last tag