Data display
RatingBreakdown
Free12.0 KB gzippedThe summary above a review list: the average rating as a big number with stars, the review count, and one bar per level showing its share. Each row reads "5 stars: 920 reviews, 72%"; with onLevelSelect the rows are toggle buttons for filtering by level.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space · Full report
More in Pro
RatingBreakdown is free. ReviewsSection, in the paid Pro add-on, uses it as the summary of a complete reviews section, where its rows filter the list.Import
import { RatingBreakdown } from "@vjdesigns/vjdesigns-ui";
Importing only RatingBreakdown adds about 12.0 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
The average, the review count and one bar per star level. Each row reads "5 stars: 920 reviews, 72%" to screen readers. average and total are worked out from counts when you leave them out.
- 5 stars: 920 reviews, 72%
- 4 stars: 210 reviews, 16%
- 3 stars: 80 reviews, 6%
- 2 stars: 40 reviews, 3%
- 1 star: 34 reviews, 3%
import { RatingBreakdown } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<div style={{ width: "100%", maxWidth: "26rem" }}>
<RatingBreakdown counts={{ 5: 920, 4: 210, 3: 80, 2: 40, 1: 34 }} recommendPercent={92} />
</div>
);
}
Filter by level
With onLevelSelect, each row is a toggle button (aria-pressed) for filtering reviews by star level. Press the selected row again to clear the filter.
Showing all reviews
import { useState } from "react";
import { RatingBreakdown, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function FilterByLevel() {
const [level, setLevel] = useState<number | null>(null);
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "26rem" }}>
<RatingBreakdown counts={{ 5: 64, 4: 22, 3: 9, 2: 3, 1: 2 }} selectedLevel={level} onLevelSelect={setLevel} />
<Text tone="muted">{level === null ? "Showing all reviews" : `Showing ${level}-star reviews`}</Text>
</Stack>
);
}
Inline
layout="inline" puts the average beside the bars, and wraps on narrow screens.
- 5 stars: 120 reviews, 62%
- 4 stars: 48 reviews, 25%
- 3 stars: 15 reviews, 8%
- 2 stars: 6 reviews, 3%
- 1 star: 4 reviews, 2%
import { RatingBreakdown } from "@vjdesigns/vjdesigns-ui";
export function Inline() {
return (
<div style={{ width: "100%", maxWidth: "40rem" }}>
<RatingBreakdown layout="inline" counts={{ 5: 120, 4: 48, 3: 15, 2: 6, 1: 4 }} />
</div>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
- 5 نجوم: 920 مراجعة، 72%
- 4 نجوم: 210 مراجعات، 16%
- 3 نجوم: 80 مراجعة، 6%
- نجمتان: 40 مراجعة، 3%
- نجمة واحدة: 34 مراجعة، 3%
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
API reference
RatingBreakdown
New in 3.8.4| Prop | Type | Default |
|---|---|---|
countsRequiredReviews per level, e.g. | Record<number, number> | — |
averageThe average rating. Computed from | number | — |
totalTotal reviews. The sum of | number | — |
maxThe highest level (number of stars). | number | 5 |
onLevelSelectCalled when a level row is pressed, with that level, or | (level: number | null) => void | — |
selectedLevelThe level currently filtered on (shown pressed). Use with | number | null | — |
recommendPercentShare of reviewers who would recommend, 0 to 100. Shown as "92% would recommend". | number | — |
layout
| "stacked""inline" | "stacked" |
sizeText size. | "sm""md""lg" | "md" |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
RatingBreakdown targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | With onLevelSelect: moves through the level rows. |
| EnterSpace | Filters by that level, or clears the filter on the pressed row. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Levels | list | aria-label ("Rating distribution") |
| Level row | none (or button) | Read as "5 stars: 920 reviews, 72%"; with onLevelSelect a toggle button with aria-pressed |
| Big average, bars and percents | none | aria-hidden; the same values are in the text read aloud |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |