FeedbackReact
Shows several measurements that share one range on a single bar, such as storage used by apps, photos and the system.
Rendered by React 19.3.1
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<MeterGroup.Root>
<MeterGroup.Label />
<MeterGroup.Value />
<MeterGroup.Track>
<MeterGroup.Indicator />
</MeterGroup.Track>
<MeterGroup.Item>
<MeterGroup.ItemLabel />
<MeterGroup.ItemValue />
</MeterGroup.Item>
</MeterGroup.Root>Examples
Overflow
A monthly budget in dollars that a trip pushes past its limit, with the total marked by [data-overflow].
API reference
10 props across 8 parts, in React syntax. className, style, render are listed once, under Shared props.
IndicatorMeterGroup.Indicator
Draws the segment of one value along the track. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
indexrequiredThe position in value of the amount this segment draws. | number | — |
ItemMeterGroup.Item
The meter of one value, named by its item label: the group's legend entry. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
aria-valuetextA string value that provides a user-friendly name for aria-valuenow, the current value of | string | — |
indexrequiredThe position in value of the amount this meter reads. | number | — |
ItemLabelMeterGroup.ItemLabel
An accessible label for the meter. Renders a <span>.
ItemValueMeterGroup.ItemValue
A text element displaying the current value. Renders a <span>.
| Prop | Type | Default |
|---|---|---|
children | ((formattedValue: string, value: number) => React.ReactNode) | null | — |
LabelMeterGroup.Label
An accessible label for the group. Renders a <span>.
RootMeterGroup.Root
Groups the meters of several values that share one capacity, named by its label. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
formatOptions to format each value and the total. | Intl.NumberFormatOptions | — |
getAriaValueTextA function that returns the aria-valuetext of each item, from its formatted value, its entry | MeterGroupGetAriaValueText | — |
localeThe locale used by Intl.NumberFormat when formatting the values. | Intl.LocalesArgument | — |
maxThe capacity every value is measured against. | number | 100 |
valuerequiredThe amounts, in segment order. | readonly number[] | — |
TrackMeterGroup.Track
Contains the indicators and represents the whole capacity. Renders a <div>.
ValueMeterGroup.Value
A text element displaying the total of the values. Renders a <span>.
| Prop | Type | Default |
|---|---|---|
children | ((formattedValue: string, value: number) => React.ReactNode) | null | — |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
MeterGroup takes no focus and has no keys of its own.
Accessibility
| Part | Sets | So that |
|---|---|---|
| Root | role="group", aria-labelledby to Label | the values are read as one named group |
| Item | role="meter", aria-valuemin="0", aria-valuemax, aria-valuenow (clamped to max) | a screen reader reads each value within its range |
| Item | aria-valuetext from format, getAriaValueText or aria-valuetext, aria-labelledby to ItemLabel | each value is read with its name and as written, such as "20%" |
| Value | the formatted total as text, unclamped | the total is read in place, above the range of any one value |
| ItemValue | aria-hidden="true" | the visible number is not read twice |
Focus order
- MeterGroup is not focusable; focus passes over it.