PillChoiceGroup
Single or multiple choices presented as a group of Pills.
Usage
- Focus
- Calm
- Energy
<script>
import { PillChoiceGroup } from 'bref-ui';
const items = [
{ id: 'focus', label: 'Focus' },
{ id: 'calm', label: 'Calm' }
];
let selection = $state('focus');
</script>
<PillChoiceGroup {items} aria-label="Mood" bind:selection />
Playground
Live preview
- Focus
- Calm
- Energy
Settings
View generated code
<script lang="ts">
import { PillChoiceGroup } from 'bref-ui';
import type { PillDataProps } from 'bref-ui/types';
let items = $state<PillDataProps[]>([
{
id: 'focus',
label: 'Focus',
icon: {
name: 'center_focus_strong'
}
},
{
id: 'calm',
label: 'Calm'
},
{
id: 'energy',
label: 'Energy'
}
]);
let selection = $state<string | string[]>('focus');
const remove = (id: string) => {
items = items.filter((item) => item.id !== id);
selection = Array.isArray(selection)
? selection.filter((selected) => selected !== id)
: selection === id
? ''
: selection;
};
</script>
<PillChoiceGroup
{items}
bind:selection
aria-label="Interactive choices"
size="medium"
variant="neutral"
color="foreground"
disabled={false}
glass={false}
animateSelected={false}
onDelete={remove}
/>
<p role="status">
Selected: {Array.isArray(selection) ? selection.join(', ') || 'none' : selection || 'none'}
</p>
Native selection and form reset
Animated choices
- Focus
- Calm
- Energy
neutral
primary
- Focus
- Calm
- Energy
secondary
- Focus
- Calm
- Energy
foreground
- Focus
- Calm
- Energy
muted
- Focus
- Calm
- Energy
info
- Focus
- Calm
- Energy
success
- Focus
- Calm
- Energy
warning
- Focus
- Calm
- Energy
error
- Focus
- Calm
- Energy
soft
primary
- Focus
- Calm
- Energy
secondary
- Focus
- Calm
- Energy
foreground
- Focus
- Calm
- Energy
muted
- Focus
- Calm
- Energy
info
- Focus
- Calm
- Energy
success
- Focus
- Calm
- Energy
warning
- Focus
- Calm
- Energy
error
- Focus
- Calm
- Energy
x-small
- Focus
- Calm
- Energy
- Focus
- Calm
- Energy
small
- Focus
- Calm
- Energy
- Focus
- Calm
- Energy
medium
- Focus
- Calm
- Energy
- Focus
- Calm
- Energy
large
- Focus
- Calm
- Energy
- Focus
- Calm
- Energy
x-large
- Focus
- Calm
- Energy
- Focus
- Calm
- Energy
Props and native behavior
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
items | readonly PillDataProps[] | Yes | — | Choices with unique IDs and visible labels; icons are optional. |
selection | string | string[] | Yes | — | Bindable ID for radio choice, or IDs for checkboxes. |
disabled | boolean | No | false | Disable every choice. |
onDelete | (id: string) => void | No | Omitted | Show delete buttons and report the item ID; the consumer updates items and selection. |
size | Size | No | medium | Pill size. |
variant | Exclude<Variant, 'filled'> | No | neutral | Neutral selects soft; soft selects filled. |
color | Exclude<Color, 'background'> | No | foreground | Theme role for every pill, including selected choices. |
animateSelected | boolean | No | false | Enable the pill highlight animation. |
glass | boolean | No | false | Translucent paint and backdrop blur for the choices. |
Supply aria-label or aria-labelledby for the group name. A string selection uses native radio behavior; an array uses checkboxes. Tab
and arrow keys navigate radios; Space toggles focused checkboxes.