Starter prompts
Suggested prompts on an empty chat. A list of buttons (or links); a press sends the prompt, fills the reader's message field, or follows a link. Host-driven: the suggestions are props.
Anatomy
div[data-ds-starter-prompts][x-data][x-ds-prompt="field-id"] @container
├── p#label sr-only with hideLabel
└── ul[aria-labelledby=label] chips: flex-wrap | cards: grid
└── li
└── button[type=submit][name][value][data-ds-prompt] or a[href][data-ds-prompt]
├── icon tile (cards) or icon (chips) aria-hidden
├── label
└── description (cards) line-clamp-2
Variants
| Variant | Shape |
|---|---|
chips (default) | rounded-full, bordered, one line, truncated; the row wraps |
cards | bordered cards: an icon on an accent tint, the label, a two-line description; a grid of 1 column, 2 from @sm, columns (3 or 4) from @2xl of the container |
Behaviour
Without the script each suggestion is a link (href) or a submit button
posting name=prompt (the full prompt, the label when none) in the host's
form; outside a form a button does nothing natively, and the event is the way
in. x-ds-prompt (an enhancement, in ENHANCEMENTS) adds:
choose(notselect: the native event a field fires when text in it is selected; renamed in 30B) dispatched from the suggestion, bubbling and cancelable, detail{ prompt };- cancelled: the press stops there (no fill, post or navigation);
- otherwise, with
fornaming a field that exists: the field's value is set, a nativeinputEvent is dispatched (not a CustomEvent, whose detail x-model and wire:model would take as the value), the field is focused with the caret at the end, and the click's default is prevented; - otherwise the link or submit goes ahead.
A row with no words is dropped. Rows are arrays, objects or bare strings.
Accessibility
| Role | a list (ul) of buttons or links: not a listbox, each is one action |
| Name | the list by label (visible unless hideLabel); each item by its words |
| Keyboard | Tab between suggestions; Enter (and Space on a button) presses |
| Focus | every item draws the system ring outside; a fill moves focus to the field |
Do not
- Do not make it a listbox or a radio group: nothing is selected, each press is an action.
- Do not use
foron a field the reader cannot see. Focus goes there.
From the package repo: edit this page on GitHub.