Skip to content

ProgressBar and Meter produce NaN percentage when minValue === maxValue #10042

@lixiaoyan

Description

@lixiaoyan

Provide a general summary of the issue here

When <ProgressBar> or <Meter> is rendered with minValue === maxValue (e.g. value={0}, maxValue={0} with the default minValue={0}), the internally computed percentage is NaN. This propagates into the render-prop percentage value and into aria-valuetext.

🤔 Expected Behavior?

When the range is empty (minValue === maxValue), percentage should resolve to 0 rather than NaN.

😯 Current Behavior

In both packages/react-aria-components/src/ProgressBar.tsx and packages/react-aria-components/src/Meter.tsx, the computation is:

let percentage = ((value - minValue) / (maxValue - minValue)) * 100;

With value = 0, minValue = 0, maxValue = 0, this evaluates to 0 / 0 = NaN. There is no guard. Consequences:

  • The render-prop {({ percentage }) => …} receives NaN. Consumer code such as style={{ width: `${percentage}%` }} produces the string "NaN%", which browsers reject — the fill collapses.
  • aria-valuetext is formatted from NaN via Intl.NumberFormat, so screen readers announce "NaN%".

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

https://stackblitz.com/edit/hg7dmnxk?file=src%2FExample.tsx

Version

react-aria-components@1.17.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions