Response feedback

Thumbs up and down under an AI answer, with copy and your own actions beside them. A thumbs down can ask what went wrong: reason chips and a comment.

Response feedback

Needs Alpine and the package's script when it has no action (a Livewire host saving the event). See getting started. With an action it is an ordinary form and works with no script at all.

Use it

As a form posting to your route:

<p id="answer-{{ $message->id }}">{{ $message->text }}</p>

<x-ds::response-feedback
    :action="route('messages.feedback', $message)"
    :value="$message->rating"
    :submitted="$message->rated_at !== null"
    :copy="'answer-'.$message->id"
    :reasons="['wrong' => 'Not correct', 'unhelpful' => 'Not helpful', 'unsafe' => 'Harmful']"
/>

It posts feedback (up, down, or empty when the reader took it back), reason[] and comment:

public function store(Request $request, Message $message)
{
    $message->update([
        'rating' => $request->input('feedback') ?: null,
        'rating_reasons' => $request->input('reason', []),
        'rating_comment' => $request->input('comment'),
        'rated_at' => now(),
    ]);

    return back();
}

In Livewire, with no action: every press dispatches feedback, and the component draws the result itself.

<x-ds::response-feedback :value="$rating" :reasons="$reasons" x-on:feedback="$wire.rate($event.detail)" />
public function rate(array $feedback): void
{
    // ['value' => 'down', 'reasons' => ['wrong'], 'comment' => '…']
}

More actions go in the slot, as toolbar buttons:

<x-ds::response-feedback :value="$rating" copy="answer-7">
    <x-ds::toolbar-button label="Regenerate" icon="arrow-path" :iconOnly="true" :tooltip="true" wire:click="regenerate" />
</x-ds::response-feedback>

Shown only on hover, as most chat apps do: mark the message group/message.

<article class="group/message">
    …
    <x-ds::response-feedback :showOnHover="true" … />
</article>

It stays visible on a touch screen, while focus is in it, and once anything is pressed.

Props

PropTypeDefaultWhat it does
valueup down or null—The saved rating, drawn pressed.
actionstring—A URL: the component is a form posting there (with the CSRF token).
namestringfeedbackThe field the rating posts under.
reasonsarray[]Chips offered after a thumbs down: words, or [value => words]. Post as reason[].
commentbooltrueA comment box after a thumbs down, posting as comment.
submittedboolfalseThe feedback was received: the thanks shows, the follow-up does not.
copystring—The id or selector of the answer's text: adds a copy button.
sizesm mdsm
variantghost muted floatingghostAs toolbar's; ghost has no tray.
showOnHoverboolfalseSee above.
labelstringResponse actionsThe toolbar's name.
upLabel, downLabel, copyLabelstringGood response, Bad response, CopyThe buttons' names (and tooltips).
moreLabel, reasonsLabel, commentLabel, sendLabelstringTell us more, What went wrong?, Anything else? (optional), SendThe follow-up's words.
thanksstringThanks for the feedback
SlotWhat it does
defaultMore toolbar buttons after copy: regenerate, share, a "more" menu.

Events

EventDetailWhen
feedback{ value, reasons, comment }A thumbs press (value is up, down, or '' for taken back), or Send after a thumbs down (value is down, with the reasons and comment). Bubbles. Cancelable: in a form with an action, cancelling stops the post and draws the result here instead.

How it behaves

  • Up and down are toggle buttons (aria-pressed), one at a time: pressing one releases the other, and pressing the pressed one takes the rating back.
  • With no script each is a submit button. The pressed one posts an empty value, so a second press clears, and the server's next page draws it.
  • A thumbs down opens the follow-up under the buttons: a native disclosure, in the page rather than floating, because its fields post with the rating in one form. The server opens it too, for a saved thumbs down not yet submitted.
  • Once a choice is final (a thumbs up, or Send) a polite status says "Thanks for the feedback".

Accessibility

  • A toolbar: one Tab stop, the arrow keys between the buttons.
  • The thumbs are named "Good response" and "Bad response" and say pressed or not; their tooltips repeat the name for sighted readers.
  • The thanks is a polite status outside the buttons, in the page from the start, so it is read once when it appears.

Don't

  • Don't ask for a comment on a thumbs up. It is the down that needs a reason.
  • Don't use showOnHover where people need to find it. It suits a transcript of many answers; on a single answer, show it.

From the package repo: edit this page on GitHub.

Was this page helpful?