FeedbackReact
A graphical display of a numeric value within a known range, such as disk usage or a password's strength.
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:
<Meter.Root>
<Meter.Label />
<Meter.Value />
<Meter.Track>
<Meter.Indicator />
</Meter.Track>
</Meter.Root>Examples
The demo at the top is the one example this component has so far.
API reference
8 props across 5 parts, in React syntax. className, style, render are listed once, under Shared props.
IndicatorMeter.Indicator
Visualizes the position of the value along the range. Renders a <div>.
LabelMeter.Label
An accessible label for the meter. Renders a <span>.
RootMeter.Root
Groups all parts of the meter and provides the value for screen readers. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
valuerequiredThe current value. | number | — |
aria-valuetextA string value that provides a user-friendly name for aria-valuenow, the current value of the meter. | string | — |
getAriaValueTextA function that returns a string value that provides a human-readable text alternative for aria-valuenow, the current value of the meter. | ((formattedValue: string, value: number) => string) | — |
localeThe locale used by Intl.NumberFormat when formatting the value. | Intl.LocalesArgument | — |
minThe minimum value | number | 0 |
maxThe maximum value | number | 100 |
formatOptions to format the value. | Intl.NumberFormatOptions | — |
TrackMeter.Track
Contains the meter indicator and represents the entire range of the meter. Renders a <div>.
ValueMeter.Value
A text element displaying the current value. 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
Meter takes no focus and has no keys of its own.
Accessibility
| Part | Sets | So that |
|---|---|---|
| Root | role="meter", aria-valuenow, aria-valuemin, aria-valuemax | a screen reader reads the value within its range |
| Root | aria-valuetext from format, getAriaValueText or aria-valuetext | the value is read as written, such as "75%" |
| Root | aria-labelledby to Label | the meter is read with its name |
| Value | aria-hidden="true" | the visible number is not read twice |
Focus order
- Meter is not focusable; focus passes over it.