ChipInput
import { ChipInput } from 'svogg-components';
Component for manipulating a list of strings represented by chips/badges. Uses the WAI-ARIA grid
pattern for structuring the list of chips. Value can either be bound directly via
bind:chips
, or retrieved natively from form data by passing a name
attribute to the component.
Note that if used in conjunction with Svelte form actions, the value must be manually converted to a value compatible with FormData before posting (for example by modifying the value in a submit function when using progressive enhancement).
In addition to the declared props, the component accepts any props valid as attributes for a
native input
HTML element.
Demo
Code
Bats Scorpions
ChipInput
Name | Type | Required | Default | Description |
---|---|---|---|---|
chips | string[] | false | [] | |
placeholder | string | undefined | false | - | HTML `placeholder` attribute |
Name | Detail | Type | Description |
---|---|---|---|
change | {chips: string[]} | dispatched | Fires whenever a chip is added or removed, dispatching the new value. |
CSS
Class | Description |
---|---|
.svogg-input | Applied to the text input |
.svogg-chip | Applied to input chips |
Keyboard navigation
- Tab
- When focus moves into the component, places focus on the text input.
- If text input has focus, moves focus to the first column of the first chip.
- When a chip contains focus, moves focus to the next element in the document tab sequence.
- Shift + Tab
- When focus moves into the component, places focus on the first column of the first chip.
- If a chip contains focus, places focus on the text input.
- If the text chip has focus, moves focus to the previous element in the document tab sequence.
- ← or →
- If a chip contains focus, moves focus horizontally to the next or previous column respectively.
- ↑ or ↓
- If a chip contains focus, moves focus horizontally to the next or previous column with the same column index.