<c-tags>
A group of `c-tag` elements laid out in a wrapping row, with an optional group label above them.
Usage
Put the tags in the default slot; the row wraps onto further lines when it runs out of width. The group holds no value and fires no event of its own: what a tag means, whether it is active and when it is removed are up to you.
<c-tags label="Research fields">
<c-tag active>All</c-tag>
<c-tag>Biosciences</c-tag>
<c-tag>Chemistry</c-tag>
</c-tags>
When to use
- Showing a set of keywords, categories or applied filters, one tag each.
- For picking several values in a form, use
c-selectorc-autocompletewithmultiple; they show each pick as a tag inside the field. - For a small set of choices that holds a value, use
c-button-group.
Tags
A c-tag takes its text in the default slot. These props combine:
activepaints the filled, selected look. A tag never sets it itself: listen forclickand toggle it.badgeshows a number or a short text in a small pill at the tag's start.flatmakes the tag a plain label: no hover effect, not a button, and out of the Tab order.closeableadds a close button.
Pressing the close button fires close on that tag. The event does not
bubble, so listen on each tag; removing the tag stays your job:
<c-tags label="Topics">
<c-tag
v-for="topic in topics"
:key="topic.id"
:close-label="`Remove ${topic.label}`"
closeable
@close="remove(topic.id)"
>
{{ topic.label }}
</c-tag>
</c-tags>
Size
Set size on the group, not on its tags: size="small" renders every tag
in the group compact, and the group's size overrides a tag's own size.
Accessibility
- With a
label, the group is arole="group"named by it, andrequiredadds the required marker. Without one,aria-labeloraria-labelledbyon the element names the group; with neither the row is a plain container. - A plain tag — neither
closeablenorflat— is a toggle button: a Tab stop that Enter and Space press, each firingclickas a mouse click does, and announced withactiveas its pressed state. Toggleactivein yourclickhandler. - A closeable tag is not a Tab stop itself: its close button is. The button's
accessible name is
close-label, "Remove" by default, so give each tag a label naming what it removes, as in the example above. - A flat tag is skipped by Tab.
Customization
Restyle via CSS parts: ::part(root) stacks the label above the row,
::part(label) is the group label and ::part(items) is the wrapping row.
The tags stay in your own markup, so style them directly through their
root part, the tag's visible box:
c-tags::part(items) {
gap: 0.5rem;
}
c-tag::part(root) {
font-weight: 600;
}
Examples
<template>
<div style="display: grid; gap: 1rem">
<c-tags>
<c-tag active>All</c-tag>
<c-tag>Biosciences</c-tag>
<c-tag>Chemistry</c-tag>
<c-tag>Physics</c-tag>
</c-tags>
<c-tags size="small">
<c-tag active>All</c-tag>
<c-tag>Biosciences</c-tag>
<c-tag>Chemistry</c-tag>
<c-tag>Physics</c-tag>
</c-tags>
</div>
</template>
<template>
<c-tags label="Research fields" required>
<c-tag active>All</c-tag>
<c-tag>Biosciences</c-tag>
<c-tag>Chemistry</c-tag>
<c-tag>Physics</c-tag>
</c-tags>
</template>
<template>
<div class="example-row">
<c-tag>Default</c-tag>
<c-tag active>Active</c-tag>
<c-tag badge="3">With badge</c-tag>
<c-tag flat>Flat</c-tag>
<c-tag size="small">Small</c-tag>
</div>
</template>
<template>
<div class="example-grid">
<!-- A closeable tag's close button is its only control; it emits `close`. -->
<c-tags>
<c-tag
v-for="topic in topics"
:key="topic.id"
closeable
@close="onRemoveTopic(topic.id)"
>
{{ topic.label }}
</c-tag>
</c-tags>
<div>
<c-button @click="onResetTopics()">Reset topics</c-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const createTopics = () => {
return [
{ id: 'biosciences', label: 'Biosciences' },
{ id: 'chemistry', label: 'Chemistry' },
{ id: 'physics', label: 'Physics' },
];
};
const topics = ref(createTopics());
const onRemoveTopic = (topic: string) => {
topics.value = topics.value.filter((t) => t.id !== topic);
};
const onResetTopics = () => {
topics.value = createTopics();
};
</script>
API reference
<c-tags>
A group of `c-tag` elements laid out in a wrapping row, with an optional group label above them.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
label | label | string | '' | Label of the tag group, shown above the tags |
required | required | boolean | false | Set as required — shows the required marker on the label |
size | size | CTagsSize | 'default' | Size of every tag in the group: `small` renders them compact. Overrides each tag's own `size` |
Slots
| Slot | Description |
|---|---|
default | The `c-tag` elements of the group |
CSS parts
Style from outside with c-tags::part(name) — parts are the library's only styling customization API.
| Part | Description |
|---|---|
root | The wrapper stacking the group label above the tags |
label | The group label rendered above the tags |
items | The wrapping row that lays out the slotted tags |
Types
Importable from the package root: import type { … } from '@cscfi/csc-ui'
CTagsSize
Size propagated to every slotted `<c-tag>`. `small` renders compact tags; omitting the attribute leaves the tags at their default size.
export type CTagsSize = 'default' | 'small';<c-tag>
A pill-shaped tag naming one item — a keyword, a category, an applied filter — authored inside `c-tags`, or on its own where a single tag is needed, such as a status in a table cell. With `closeable` it shows a close button that fires `close` and leaves removing the tag to you; name that button with `close-label`, for example "Remove Chemistry".
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
active | active | boolean | false | Paint the filled, selected look, announced as the pressed state of a plain tag. The tag never sets it itself: toggle it on `click` |
badge | badge | null | number | string | null | A number or short text shown in a small pill at the start of the tag |
closeable | closeable | boolean | false | Add a close button that fires `close`; removing the tag stays your job. The button, not the tag, is then the Tab stop |
closeLabel | close-label | string | 'Remove' | Accessible name of the close button rendered when `closeable` |
flat | flat | boolean | false | Make the tag a plain label: no hover effect, not a button, and out of the Tab order |
size | size | CTagSize | 'default' | Size of the tag: `small` renders a compact pill. Inside `c-tags`, the group's `size` overrides it |
Events
| Event | Detail | Description |
|---|---|---|
close | void | Fired when the tag's close button is activated. |
Slots
| Slot | Description |
|---|---|
default | The tag's text |
CSS parts
Style from outside with c-tag::part(name) — parts are the library's only styling customization API.
| Part | Description |
|---|---|
root | The tag's visible pill-shaped box |
Types
Importable from the package root: import type { … } from '@cscfi/csc-ui'
CTagSize
Size of the tag. `small` renders a more compact pill; omitting the attribute renders the default size.
export type CTagSize = 'default' | 'small';