Bring your own markup and styles. MeterGroup handles the math and the data attributes.
- Apps (16%)
- Messages (8%)
- Media (24%)
- System (10%)
Pre-styled Versions
Features#
- Compound parts:
Root,Meters,Meter,Labels,Label,Marker,Text - No
indexprop. Target individual rows with:nth-child(n)on[data-part="meter"],[data-part="marker"]or[data-part="label"] - Percentages computed from
min/max; passaria-valuenowon the root for screen readers - Color flows through one
--p-metergroup-colorCSS variable. The primitive never picks a color itself - Horizontal or vertical orientation for both meters and labels
Usage#
import { MeterGroup } from 'primereact/metergroup';<MeterGroup.Root aria-valuenow={total}>
<MeterGroup.Meters>
<MeterGroup.Meter />
</MeterGroup.Meters>
<MeterGroup.Labels>
<MeterGroup.Label>
<MeterGroup.Marker />
<MeterGroup.Text></MeterGroup.Text>
</MeterGroup.Label>
</MeterGroup.Labels>
</MeterGroup.Root>The primitive does not look at the children to total their values. Compute the sum where the data lives and pass it as aria-valuenow. When omitted, the attribute is 0.
Behavior#
Polymorphic Rendering#
Every part takes an as prop. Pass an element or another component to swap the rendered tag.
<MeterGroup.Root as="section"></MeterGroup.Root>
<MeterGroup.Labels as="ul"></MeterGroup.Labels>
<MeterGroup.Label as="div"></MeterGroup.Label>Defaults: Root=div, Meters=div, Meter=div, Labels=ol, Label=li, Marker=span, Text=span.
Per-item styling#
No per-child index is emitted. Use :nth-child(n) on [data-part="meter"], [data-part="marker"] or [data-part="label"]. If you really need a stable index attribute, pass it through pt: pt={{ root: { 'data-index': i } }}.
Color via CSS variable#
color on Meter and Marker accepts any CSS color value. The primitive writes it to --p-metergroup-color on the element; the styles layer renders background: var(--p-metergroup-color, var(--p-primary-color)). Set the variable on any ancestor to repaint the whole group:
<div style={{ '--p-metergroup-color': 'magenta' } as React.CSSProperties}>
<MeterGroup.Root values={values}>{/* ... */}</MeterGroup.Root>
</div>Render Function Children#
Root accepts a render function as its child. The function receives the component instance.
<MeterGroup.Root>{(instance) => <span>{instance.props['aria-valuenow']}%</span>}</MeterGroup.Root>Pass Through#
Some parts may not be visible in the preview depending on the component's current state.
/* Select a part to see its CSS selector for custom styling */API#
MeterGroupRoot#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupRootInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupRootInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupRootInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupRootPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupRootInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
min | number | 0 |
| Minimum boundary value. | ||
max | number | 100 |
| Maximum boundary value. | ||
orientation | "horizontal" | "vertical" | 'horizontal' |
| Specifies the layout of the component. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "root" |
data-orientation | Current orientation value |
Defines passthrough(pt) options of MeterGroup component.
| label | type | description |
|---|---|---|
| root | MeterGroupRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
| meters | MeterGroupRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the meters' DOM element. |
| meter | MeterGroupRootPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the meter's DOM element. |
| labels | MeterGroupRootPassThroughType<HTMLAttributes<HTMLOListElement>> | Used to pass attributes to the labels' DOM element. |
| label | MeterGroupRootPassThroughType<HTMLAttributes<HTMLLIElement>> | Used to pass attributes to the label's DOM element. |
| marker | MeterGroupRootPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the label marker's DOM element. |
| text | MeterGroupRootPassThroughType<HTMLAttributes<HTMLSpanElement>> | Used to pass attributes to the label text's DOM element. |
MeterGroupMeters#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupMetersInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupMetersInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupMetersInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupMetersPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupMetersInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "meters" |
data-orientation | Current orientation value |
Defines passthrough(pt) options of MeterGroupMeters component.
| label | type | description |
|---|---|---|
| root | MeterGroupMetersPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
MeterGroupMeter#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupMeterInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupMeterInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupMeterInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupMeterPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupMeterInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
value | number | — |
| Numeric value of the meter. | ||
color | string | — |
| Color of the meter. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "meter" |
data-orientation | Current orientation value |
Defines passthrough(pt) options of MeterGroupMeter component.
| label | type | description |
|---|---|---|
| root | MeterGroupMeterPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
MeterGroupLabels#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupLabelsInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupLabelsInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupLabelsInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupLabelsPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupLabelsInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
orientation | "horizontal" | "vertical" | horizontal |
| Specifies the label orientation of the component. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "labels" |
data-orientation | Current orientation value |
Defines passthrough(pt) options of MeterGroupLabels component.
| label | type | description |
|---|---|---|
| root | MeterGroupLabelsPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
MeterGroupLabel#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupLabelInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupLabelInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupLabelInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupLabelPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupLabelInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "label" |
Defines passthrough(pt) options of MeterGroupLabel component.
| label | type | description |
|---|---|---|
| root | MeterGroupLabelPassThroughType<HTMLAttributes<HTMLLIElement>> | Used to pass attributes to the root's DOM element. |
MeterGroupMarker#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupMarkerInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupMarkerInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupMarkerInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupMarkerPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupMarkerInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
color | string | — |
| Color of the marker. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "marker" |
Defines passthrough(pt) options of MeterGroupMarker component.
| label | type | description |
|---|---|---|
| root | MeterGroupMarkerPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
MeterGroupText#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: MeterGroupTextInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: MeterGroupTextInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | MeterGroupTextInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<MeterGroupTextPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: MeterGroupTextInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "metergroup" |
data-part | "text" |
Defines passthrough(pt) options of MeterGroupText component.
| label | type | description |
|---|---|---|
| root | MeterGroupTextPassThroughType<HTMLAttributes<HTMLDivElement>> | Used to pass attributes to the root's DOM element. |
Accessibility#
Screen Reader#
The root uses role="meter" with aria-valuemin, aria-valuemax and aria-valuenow. aria-valuenow defaults to 0; override it with the native attribute on Root. Label the group with aria-labelledby or aria-label.
Keyboard Support#
Nothing inside MeterGroup is focusable or interactive.