<focsd-tag-inputlabel="Skills"value="Accessibility,CSS"max="6"placeholder="Add a skill"></focsd-tag-input>
import { TagInput } from'@focsd-dev/react';
exportfunctionExample() {
return<TagInputonChange={(e) => console.log(e.target)}label="Skills"value="Accessibility,CSS"max="6"placeholder="Add a skill"></TagInput>;
}
<scriptsetup>
import'@focsd-dev/components/focsd-tag-input.js';
</script>
<template>
<focsd-tag-input@change="onChange"label="Skills"value="Accessibility,CSS"max="6"placeholder="Add a skill"></focsd-tag-input>
</template>
// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:
import'@focsd-dev/components/focsd-tag-input.js';
// template
<focsd-tag-input (change)="onChange($event)" label="Skills" value="Accessibility,CSS" max="6" placeholder="Add a skill"></focsd-tag-input>
<script>
import'@focsd-dev/components/focsd-tag-input.js';
</script>
<focsd-tag-inputonchange={(e) => console.log(e.target)}label="Skills"value="Accessibility,CSS"max="6"placeholder="Add a skill"></focsd-tag-input>
API
Attributes
Attribute
Property
Type
Default
name
name
string
—
disabled
disabled
boolean
false
required
required
boolean
false
readonly
readOnly
boolean
false
aria-label
hostAriaLabel
string | null
null
aria-description
hostAriaDescription
string | null
null
aria-labelledby
hostAriaLabelledBy
string | null
null
aria-describedby
hostAriaDescribedBy
string | null
null
label-position
labelPosition
'top' | 'start' | 'end' | undefined
—
hint
hint
string
—
error
error
—
—
warning
warning
string | undefined
—
success
success
string | undefined
—
error-message
errorMessage
string | undefined
—
warning-message
warningMessage
string | undefined
—
warning-pattern
warningPattern
string | undefined
—
label
label
string
—
value
value
string
—
separator
separator
string
,
max
max
number
0
placeholder
placeholder
string
—
allow-duplicates
allowDuplicates
boolean
false
sortable
sortable
boolean
false
Methods
Method
Description
describedByIds()
IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()
True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()
Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)
Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)
For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()
Show (or clear) the error from the control's own checks: required, type, pattern, min,
max and the like. Uses error-message, else the browser's localized message. An error the
author set (a server error, say) is left as it is.
clearValidation()
Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)
For subclasses: fire the value events, as a native control does on a user edit: input
(bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)
For subclasses: the text of the elements an ID reference list names, resolved in the host's
tree (ID references cannot cross a shadow root), joined by spaces.
add(text)
Add the tags in text (split on the separator and new lines). Returns true when any was added.
removeAt(index)
Remove the tag at index.
Events
Event
Description
input
Fired when a tag is added, removed or moved.
change
Fired when a tag is added, removed or moved.
Slots
Slot
Description
(default)
focsd-option suggestions (data only).
CSS parts
Style the inside of the component with ::part(), for example focsd-tag-input::part(label).
Part
Description
label
The label.
layout
The label and the body (see label position).
body
The box with its hint and message.
hint
The author hint.
message
The shown error, warning or success message.
message-icon
The icon of the message.
field
The box holding the tags and the input.
tags
The list of tags.
tag
One tag.
remove
A tag's remove button.
handle
A tag's reorder button (sortable only).
control
The text input.
popup
The suggestions popup.
listbox
The suggestions list.
option
One suggestion.
status
The live status (visually hidden).
announcer
The visually hidden status region that announces a new message.
Accessibility
Tags are a list; each has a "Remove {tag}" button.
Adding, removing, duplicates and the maximum are announced in a polite status.
Pasting a list (commas or new lines) adds every item at once.
With focsd-option suggestions the input is an APG combobox with aria-activedescendant.
The form gets one entry per tag under name, so servers never split a string.
Keyboard
Key
Action
Enter, comma (the `separator`) or Tab
Add the typed text as a tag
Shift+Tab (in the input)
Move to the tags: the one last visited, or the last tag
Tab / Shift+Tab (on a tag)
Move to the input / leave the component: the tags are one tab stop
Backspace (empty input)
Move to the last tag
Backspace / Delete on a tag
Remove it
Left / Right
Move between tags and the input
Home / End (on a tag)
First tag / back to the input
Down / Up
Move through suggestions
Escape
Close the suggestions
Sortable
With sortable, each tag gets a "Reorder {tag}" button before its text. It shares the one tab stop of the remove buttons; the arrow keys move between all tag buttons.
Grabbing, each move, the drop and a cancel are announced in the tag input’s polite status.
A drop updates values (the form gets the tags in the new order) and fires input and change, after a cancelable focsd-reorder with detail.from, detail.to and detail.value.
Keyboard
Key
Action
Space / Enter (on a handle)
Grab the tag, or drop it
Arrow keys
Move the grabbed tag one place (Left and Right mirrored right to left)
Escape
Put the tag back where it was
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.