Introducing PrimeReact v11-alpha 🎉Discover Now

MeterGroup

Unstyled meter group primitive for scalar measurements within a range.

Bring your own markup and styles. MeterGroup handles the math and the data attributes.

  1. Apps (16%)
  2. Messages (8%)
  3. Media (24%)
  4. System (10%)
basic-demo

Pre-styled Versions

Choose a pre-styled library to use MeterGroup with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound parts: Root, Meters, Meter, Labels, Label, Marker, Text
  • No index prop. Target individual rows with :nth-child(n) on [data-part="meter"], [data-part="marker"] or [data-part="label"]
  • Percentages computed from min / max; pass aria-valuenow on the root for screen readers
  • Color flows through one --p-metergroup-color CSS 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.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

MeterGroupRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupRootInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupRootInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
minnumber0
Minimum boundary value.
maxnumber100
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.
AttributeValue
data-scope"metergroup"
data-part"root"
data-orientationCurrent orientation value

Defines passthrough(pt) options of MeterGroup component.

labeltypedescription
rootMeterGroupRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
metersMeterGroupRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the meters' DOM element.
meterMeterGroupRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the meter's DOM element.
labelsMeterGroupRootPassThroughType<HTMLAttributes<HTMLOListElement>>Used to pass attributes to the labels' DOM element.
labelMeterGroupRootPassThroughType<HTMLAttributes<HTMLLIElement>>Used to pass attributes to the label's DOM element.
markerMeterGroupRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the label marker's DOM element.
textMeterGroupRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the label text's DOM element.

MeterGroupMeters#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupMetersInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupMetersInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupMetersInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupMetersPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupMetersInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
AttributeValue
data-scope"metergroup"
data-part"meters"
data-orientationCurrent orientation value

Defines passthrough(pt) options of MeterGroupMeters component.

labeltypedescription
rootMeterGroupMetersPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

MeterGroupMeter#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupMeterInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupMeterInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupMeterInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupMeterPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupMeterInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
valuenumber—
Numeric value of the meter.
colorstring—
Color of the meter.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"metergroup"
data-part"meter"
data-orientationCurrent orientation value

Defines passthrough(pt) options of MeterGroupMeter component.

labeltypedescription
rootMeterGroupMeterPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

MeterGroupLabels#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupLabelsInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupLabelsInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupLabelsInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupLabelsPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupLabelsInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
AttributeValue
data-scope"metergroup"
data-part"labels"
data-orientationCurrent orientation value

Defines passthrough(pt) options of MeterGroupLabels component.

labeltypedescription
rootMeterGroupLabelsPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

MeterGroupLabel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupLabelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupLabelInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupLabelInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupLabelPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupLabelInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
AttributeValue
data-scope"metergroup"
data-part"label"

Defines passthrough(pt) options of MeterGroupLabel component.

labeltypedescription
rootMeterGroupLabelPassThroughType<HTMLAttributes<HTMLLIElement>>Used to pass attributes to the root's DOM element.

MeterGroupMarker#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupMarkerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupMarkerInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupMarkerInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupMarkerPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupMarkerInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
colorstring—
Color of the marker.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"metergroup"
data-part"marker"

Defines passthrough(pt) options of MeterGroupMarker component.

labeltypedescription
rootMeterGroupMarkerPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

MeterGroupText#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: MeterGroupTextInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: MeterGroupTextInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceMeterGroupTextInstance—
The instance to pass to the component.
ptSafeRecord<MeterGroupTextPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: MeterGroupTextInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
AttributeValue
data-scope"metergroup"
data-part"text"

Defines passthrough(pt) options of MeterGroupText component.

labeltypedescription
rootMeterGroupTextPassThroughType<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.