← All proposals

Feedback Bar

A small atomic component: a thumbs-up and thumbs-down pair with one piece of state, built from the local IconButton (its existing isPressed toggle, which maps to aria-pressed).

Net-new componentOpen in Storybook

proposals/FeedbackBar/FeedbackBar.mdx47 lines · View on GitHub
import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';

import * as FeedbackBarStories from './FeedbackBar.stories';

<Meta of={FeedbackBarStories} name='Usage' />

<Title />

## Purpose

Thumbs up and down for rating agent output. The component is UI only: it reports the choice and nothing else.

It is built on the `IconButton` primitive: two toggle icon buttons (`thumbsUp`, `thumbsDown`) in a labelled group. The buttons themselves (size, focus, tooltip and the pressed state) are the `IconButton`'s; this component adds the pairing (choosing one unpresses the other, pressing the chosen one clears it), the group label and the status text.

## Usage

Put it under an agent message, in the `actionsEnd` slot of a Suggestion Card, or under other agent output.

- It is controlled: pass `value` (`up`, `down` or nothing) and `onValueChange`. Pressing the chosen thumb again passes `null`.
- `upLabel`, `downLabel` and `groupLabel` are required. They are the screen-reader text and tooltips; the bar holds no copy. Word the labels so they do not promise what happens to the answer.
- `statusLabel` replaces the thumbs (and any `children`) with text (for example a thank-you). It is meant to be announced to screen readers; that has not been tested.
- The `children` slot takes extra actions after the thumbs, such as the PDS `ClipboardButton` (copy, which turns into a check when pressed) or a retry button.
- What the screen does with the choice, and any follow-up such as a reason, is not part of this component. The same goes for how long the status text shows; the Interactive story uses a timer only to demonstrate it.

Do not use it for:

- Rating something that is not agent output, or a survey with more than a thumbs choice.
- Collecting a reason or free text; that is a separate step the screen builds.

## Accessibility

- The bar is a `role='group'` named by `groupLabel` (for example "Rate this response"). Each thumb is a toggle button with `aria-pressed`, named by `upLabel` or `downLabel`, with a tooltip. Names stay the same when the choice changes; the pressed state is the only change a screen reader hears.
- Keyboard: Tab moves between the thumbs and any extra actions; Enter or Space presses one. Pressing the chosen thumb again clears the choice. Focus styles are the `IconButton`'s.
- The status text sits in a `role='status'` element, so the thank-you is meant to be announced when it appears. The element is hidden with `display: none` while empty, and whether that still announces reliably is not verified. Do not add a second live region for the same message.
- While `statusLabel` is set, the thumbs are removed from the page. If a thumb had focus, focus is lost, so the screen should decide where focus goes.
- The fade between the thumbs and the status text is turned off when the user prefers reduced motion.
- Not checked: the a11y panel, screen reader announcements, and the pressed contrast in light and dark.

## Implementation

See the table below for the available props. The Interactive story lets you press the thumbs and watch the status text appear and fade back (the wiring and the 4.5 second timer are story-only). The All States story shows each state: no choice, a chosen thumb, the status text and extra actions (the copy button is the PDS Clipboard Button, which turns into a check when pressed).

<hr />

<Canvas of={FeedbackBarStories.Interactive} />
<Controls of={FeedbackBarStories.Interactive} />