Response feedback
Thumbs up and down under an AI answer, copy, the host's own actions, and the
follow-up a thumbs down opens. An ordinary form with action; host-driven by
the feedback event without.
Anatomy
form[method=post][action][data-ds-feedback][x-data=dsFeedback] div with no action
├── input[name=_token] with a session
├── ds::toolbar (variant ghost|muted|floating)
│ ├── toolbar-button[type=submit][name=feedback][value=up|''][aria-pressed][data-ds-feedback-choice=up]
│ ├── toolbar-button … down
│ ├── ds::copy-button[data-ds-toolbar-item] with `copy`
│ └── slot more toolbar buttons
├── details[data-ds-feedback-more] open under a saved, unsent down; else hidden
│ ├── summary "Tell us more"
│ └── chip-group (reason[]) · input textarea (comment) · button[type=submit][name=feedback][value=down][data-ds-feedback-send]
└── p[role=status][data-ds-feedback-thanks] "Thanks for the feedback" once final
Behaviour
With no script: each thumb is a submit button; the pressed one posts an
empty value, so a second press clears. The server's next page draws the
rating, opens the follow-up under a saved thumbs down that is not yet
submitted, and shows the thanks once it is.
dsFeedback (Alpine and the script): a press on a thumb or on Send
dispatches feedback from the root, bubbling and cancelable, with
{ value, reasons, comment } (value up, down or '' for cleared; reasons
and comment only from Send). In a form with an action, if nobody cancelled
it, the form posts as it would without the script. Otherwise the press is
the host's to save and the behaviour draws it: aria-pressed and each
button's posted value, the follow-up opened (and unhidden) under a thumbs
down, the thanks written when the choice is final (a thumbs up, or Send). It
exposes nothing.
The follow-up is in the page, not a popover: its fields must post in the one form with the rating (a floating copy beside a no-script copy would post twice), and a floating panel in a scrolling transcript is cut off by it.
showOnHover: opacity-0, shown on hover or focus-within of itself or of
the nearest group/message ancestor, and always on pointer-coarse, with
anything aria-pressed, or with the follow-up open.
Accessibility
| Role | toolbar named by label; the thumbs are toggle buttons (aria-pressed) |
| Name | "Good response", "Bad response", "Copy", each with a tooltip |
| Keyboard | one Tab stop into the toolbar; Left/Right (Home/End) move; Enter or Space press; Tab moves on to the follow-up |
| Focus | every button draws the ring; a press keeps focus where it is |
| Announcement | the thanks is a polite status, in the page from the start (empty:sr-only, never display: none), so it is read once |
Do not
- Do not use radios for the thumbs. A rating can be taken back; a radio cannot be unchosen.
- Do not move focus into the follow-up on a thumbs down: pressing a toggle should not take the reader somewhere. It is next in Tab order.
From the package repo: edit this page on GitHub.