Axon 911 Frontend DocsAxon 911 Frontend Docs
Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Token
  3. API and Development

Token

API and Development

View SourceOpens in a new tabSubmit IssueOpens in a new tab
Import Token, TokenIntent, TokenSize, announceTokenRemoval, shouldRemoveLastTokenOnBackspace from @prepared911/ui/token.
PropTypeDefault
labelLocalizedMessage | DisplayValuerequired
intentTokenIntentNeutral
sizeTokenSizeLarge
iconGlyph (not with avatar);
avatar{ src?: string; fallback: AvatarName } (not icon);
onRemove(details: TokenRemoveDetails) => void;
removeLabelLocalizedMessage (required with onRemove);
removedAnnouncementLocalizedMessage (required with onRemove);
removeButtonRefref to the remove button (with onRemove);
selectedboolean;
defaultSelectedboolean;
onSelectedChange(selected, details: ChangeDetails) => void;
disabledbooleanfalse
idstring;
aria-describedbystring;
classNamestring;
refref to the shell span;
aria-describedby sits on the toggle button when the token is selectable, so the description is read when the toggle takes focus; otherwise it sits on the shell. data-* attributes pass through to the shell, except the reserved design-system state names. Token takes no style, role, children, tabIndex, aria-label or other on* handler. TokenIntent: Neutral, Informative, Success, Warning, Destructive. TokenSize: Small, Medium, Large.
Removal details
onRemove receives ChangeDetails<ChangeReason.ItemPress>. details.event is the click or the keydown, details.source is the shell, and the change is cancelable: details.cancel() keeps the token's announcement from firing. A press that changes the selection reports ChangeReason.ItemPress too.
Helpers
ExportUse
shouldRemoveLastTokenOnBackspace(event)In a composer entry's onKeyDown: true when Backspace should remove the last token
announceTokenRemoval(message, node?)Polite announcement for a removal the composer performs itself, in node's owner document
Anatomy
The shell is a span with no role. It holds a label part (a span, or a button with aria-pressed when selectable) and the remove Button as siblings. Without onRemove and selection a token is a static label with no control.
Props
NameTypeDefaultDescription
labelTokenLabel—Visible label. It is the token's name; meaning lives in this text, not in color.
aria-describedbystring—Id of the element that describes the token. Set on the toggle button when selectable, otherwise on the shell.
avatarTokenAvatar—Decorative avatar before the label. The label stays the name.
classNamestring—Classes appended after the generated classes. Put overrides in @layer chroma.overrides.
defaultSelectedboolean—Initial selected state when uncontrolled.
disabledboolean—Inert state. Disables the selection button and the remove button, and ignores Backspace and Delete.
iconGlyph—Decorative glyph before the label. It is aria-hidden; the label stays the name.
idstring—Element id of the shell.
intentTokenIntent—Status or neutral intent for shell paint and label color. Defaults to {@link TokenIntent.Neutral}.
onRemove((details: TokenRemoveDetails) => void)—Called when the person removes the token with the remove button or with Backspace or Delete. The consumer removes the token from its own state and decides where focus goes next; the token that held focus unmounts. @param details - Change metadata; event is the click or key event, and cancel() keeps the token and the announcement
onSelectedChange((selected: boolean, details: ChangeDetails<ChangeReason>) => void)—Called when a press changes the selection. @param selected - Next selected state @param details - Change metadata; cancel to keep the previous state
refRef<HTMLSpanElement>—Ref to the shell span.
removeButtonRefRef<HTMLButtonElement>—Ref to the remove Button. A consumer that moves focus after a removal keeps the Button of the token it moves to, so it never has to search the shell.
removedAnnouncementLocalizedMessage—Announced politely after a removal that was not canceled, for example "Unit 12 removed".
removeLabelLocalizedMessage—Accessible name of the remove button. Name the subject, for example "Remove Unit 12", not just "Remove".
selectedboolean—Whether the token is selected (controlled).
sizeTokenSize—Height from the shared control heights. Defaults to {@link TokenSize.Large}.
Storybook
Interactive examples and edge cases for this component are in Storybook.
DefaultOpens in a new tab
Previous
Token / Usage
Next
Token / Accessibility
On this page
Removal details
Helpers
Anatomy
Props
Storybook