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

VariantShape
chips (default)rounded-full, bordered, one line, truncated; the row wraps
cardsbordered 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:

  1. choose (not select: the native event a field fires when text in it is selected; renamed in 30B) dispatched from the suggestion, bubbling and cancelable, detail { prompt };
  2. cancelled: the press stops there (no fill, post or navigation);
  3. otherwise, with for naming a field that exists: the field's value is set, a native input Event 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;
  4. otherwise the link or submit goes ahead.

A row with no words is dropped. Rows are arrays, objects or bare strings.

Accessibility

Rolea list (ul) of buttons or links: not a listbox, each is one action
Namethe list by label (visible unless hideLabel); each item by its words
KeyboardTab between suggestions; Enter (and Space on a button) presses
Focusevery 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 for on a field the reader cannot see. Focus goes there.

From the package repo: edit this page on GitHub.

Was this page helpful?