Tags
Badges, removable tag chips, and a selector for choosing, creating and removing tags from a list.
@patternmode/tags
Open the list, type to filter, then press Enter or a comma to add a tag.
Reference
States and variants
Badge matches shadcn. Tag adds a remove button. TagSelector puts them together.
- DefaultSecondaryOutline
Badge
variant - Large
Removable tag
Tag onRemove Empty selector
placeholderChosen tags, each removable
valueCreate a new tag
onCreateItemCommas commit a tag
separators
Install and use
Controlled. Pass onCreateItem to let people add tags that aren't in the list.
npm i @patternmode/tagsimport { TagSelector } from "@patternmode/tags";
import type { TagItem } from "@patternmode/tags";
import "@patternmode/tags/styles.css";
const options: TagItem[] = [
{ id: "accessible", label: "Accessible" },
{ id: "keyboard", label: "Keyboard first" },
];
export function Example() {
const [value, setValue] = useState<TagItem[]>([]);
return (
<TagSelector
aria-label="Project tags"
onChange={setValue}
options={options}
placeholder="Select tags"
value={value}
/>
);
}Core API
Badge
Shadcn-compatible badge base with variant and render support.
variant- "default" | "secondary" | "destructive" | "outline" | "ghost" | "link""default"Matches the normal shadcn Badge variant names.
render- ReactElement | ((props, state) => ReactElement)Renders the badge styles through a provided element (Base UI render prop).
Tag
Badge extension for selected filters, labels, metadata, and removable tokens.
variant- "default" | "secondary" | "destructive" | "outline" | "ghost" | "link""secondary"Inherited from the Badge base.
size- "sm" | "base" | "lg""base"Controls compact, default, or large sizing.
onRemove- () => voidAdds an accessible remove button inside the tag.
selected- booleanfalseAdds a selected treatment without changing semantics.
TagSelector
Controlled object-based tag selector with Popover content, ScrollFrame selected tags, creation, keyboard navigation, paste parsing, and Stacksheet-style parts.
value- readonly TagItem[]The selected items. Selection order follows this array order.
onChange- (items: TagItem[]) => voidCalled with the next selected item objects.
options- readonly TagItem[]The consumer-owned option catalog. Selected options stay visible and toggle off by id.
onCreateItem- (label: string) => Promise<TagItem> | TagItemEnables creation through the create option, Enter/comma, and paste. The consumer returns the new object.
renderTag- (props: TagRenderProps) => ReactNodeRenders selected items with any component. Patternmode provides Tag as the convenient default.
renderOption- (props: TagOptionRenderProps) => ReactNodeRenders command options while preserving provided props.
emptyMessage- ReactNode"No tags found."Empty command-list state when no option can be shown.
TagSelector parts
Composable selector parts for Stacksheet-style layouts: Root, Trigger, Content, Search, List, Option, and Empty.
TagSelector.Root- TagSelectorRootPropsOwns state wiring, filtering, creation, serialization, and Popover context.
TagSelector.Trigger- TagSelectorTriggerPropsRenders selected tags in a horizontal ScrollFrame by default.
TagSelector.Content- TagSelectorContentPropsPopover-backed command surface.
TagSelector.Search | List | Option | Empty- component partsSearch input, option list, explicit option renderer, and empty state.
Keyboard and accessibility
A combobox you can run from the keyboard alone.
- Enter, Space
- On the trigger, open the list and move focus to search.
- ArrowUp, ArrowDown
- Move through options. Focus stays in search; aria-activedescendant follows.
- Enter
- Selects the active option, or creates the typed tag.
- Comma
- Commits what you've typed as a tag.
- Backspace
- In an empty search, removes the last tag.
Package
- Package
- @patternmode/tags
- Version
- 2.0.9
- Needs
- react, react-dom
- Licence
- MIT