Tag
Chips for labels and filters: closable, checkable, and groupable.
"use client";
import { useState } from "react";
import { Tag, HStack } from "astralis-ui";
export function TagDemo() {
const [tags, setTags] = useState(["Design", "Engineering", "Research"]);
return (
<HStack gap="2" wrap="wrap" justifyContent="center">
<Tag colorScheme="purple">Astralis</Tag>
<Tag variant="outline" colorScheme="blue">v0.1</Tag>
{tags.map((tag) => (
<Tag key={tag} closable onClose={() => setTags(tags.filter((t) => t !== tag))}>
{tag}
</Tag>
))}
</HStack>
);
}Label
variant
size
colorScheme
import { Tag } from "astralis-ui";
<Tag>Design</Tag>
Import#
import { Tag } from "astralis-ui";
// Tag.Checkable, Tag.GroupTag or Badge?#
Tag is a label the thing carries (a topic, a category, a filter, a
selected value), which is why it can be removed, selected and grouped. If
you're describing a state the thing is in (Active, Beta, 3 unread),
that's Badge. The two chips look nearly identical,
so the component name is what tells a reader which you meant.
Checkable groups#
Tag.Checkable is a chip with checkbox semantics; Tag.Group manages a
whole set from an options array: multiple for filters, single-select
for exclusive choices.
Following: react
"use client";
import { useState } from "react";
import { Tag, Text, VStack } from "astralis-ui";
export function TagCheckable() {
const [topics, setTopics] = useState<Array<string | number>>(["react"]);
return (
<VStack gap="3" alignItems="center">
<Tag.Group
multiple
value={topics}
onChange={setTopics}
options={[
{ label: "React", value: "react" },
{ label: "Vue", value: "vue" },
{ label: "Svelte", value: "svelte" },
{ label: "Solid", value: "solid" },
]}
/>
<Text size="xs" color="muted">
Following: {topics.length ? topics.join(", ") : "nothing yet"}
</Text>
</VStack>
);
}Props#
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "solid" | "subtle" | "surface" | "outline" | "subtle" | Same family as Button/Badge. |
size | "xs" | "sm" | "md" | "lg" | "md" | Chip size (same scale as Badge). |
colorScheme | all 15 schemes | "gray" | Hue. |
startElement / endElement | ReactNode | None | Leading / trailing slots (endElement yields to the close button). |
closable / onClose | boolean / () => void | None | Adds the ✕ remove button. |
Tag.Checkable#
Takes Tag's props except variant, closable and onClose, plus:
| Prop | Type | Default | Description |
|---|---|---|---|
checked / onChange | boolean / (checked: boolean) => void | None | Selected state and its change callback. |
colorScheme | all 15 schemes | "brand" | Hue used while checked. |
Tag.Group#
| Prop | Type | Default | Description |
|---|---|---|---|
options | { label, value }[] | (string | number)[] | None | The chips to render. Required. |
value / onChange | (string | number)[] / (value) => void | None | The selected values and their change callback. The group is always controlled, so pass both. |
multiple | boolean | false | Allow several selected at once. Otherwise selecting one clears the rest. |
size | "xs" | "sm" | "md" | "lg" | "md" | Size of every chip. |
colorScheme | all 15 schemes | "brand" | Checked hue of every chip. |
Keyboard#
Every checkable tag is its own tab stop.
| Key | Action |
|---|---|
Tab / Shift+Tab | Move to the next / previous tag |
Enter / Space | Toggle the focused tag |
On a closable tag, the remove button is a separate tab stop and activates
with Enter or Space.
Accessibility#
Checkable tags carry role="checkbox" + aria-checked and toggle with
Enter/Space; the close button is labeled "Remove".