Skip to content

[progress] Fix custom min/max semantics to match the indicator - #5095

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:claude/charming-keller-d872ee
Jun 22, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:claude/charming-keller-d872ee

Conversation

@atomiks

@atomiks atomiks commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Progress.Indicator already normalized the value against min/max (valueToPercent), but the rest of Progress.Root used the raw value, so custom-range progress bars were inconsistent. With min={20} max={40} value={30} the indicator filled to 50% while Progress.Value and aria-valuetext reported 30%.

This mirrors the fix Meter already shipped (#4904): compute a single clamped value and normalized percentage once in the Root and use it everywhere.

What changed

  • ProgressRoot.tsx — for finite values, compute one clampedValue and one clamped percentageValue, then use them consistently:
    • completion status is now clampedValue === max (an overshoot like value=45, max=40 correctly reports complete instead of progressing);
    • aria-valuenow is clampedValue, so it can no longer fall outside aria-valuemin/aria-valuemax;
    • the formatted text / default aria-valuetext use formatNumber(percentageValue / 100, …, { style: 'percent' }) when no format is given, so they match the indicator for any range;
    • format is read directly instead of through useValueAsRef, removing the one-commit lag when format changes.
  • ProgressRootContext.tsx — exposes percentageValue (clamped, null while indeterminate).
  • ProgressIndicator.tsx — reads percentageValue from context instead of recomputing it, making the Root the single source of truth (this also clamps the indicator width).
  • formatNumber.ts — removed the now-unused formatNumberValue helper that hard-coded value / 100 and ignored min/max.

value={null} (indeterminate) behavior is unchanged.

Tests

Added regression tests in ProgressRoot.test.tsx (verified failing before the fix, passing after):

  • custom range min=20 max=40 value=30 normalizes the value text, aria-valuetext, and indicator width to 50%;
  • aria-valuenow is clamped to max when the value overshoots;
  • complete is reported when the value reaches/exceeds max;
  • a format change is reflected immediately (no stale-ref lag).

Full Progress and Meter jsdom suites pass; pnpm typescript, pnpm eslint, and pnpm prettier are clean.

@atomiks atomiks added type: bug It doesn't behave as expected. component: progress Changes related to the progress component. labels Jun 22, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5095
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5095
    

commit: b65d7be

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-7B(0.00%) 🔺+23B(+0.02%)

Details of bundle changes

Performance

Total duration: 1,179.36 ms -63.42 ms(-5.1%) | Renders: 78 (+0)

No significant changes — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b65d7be
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a3917597258ff0008dd56ca
😎 Deploy Preview https://deploy-preview-5095--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks marked this pull request as ready for review June 22, 2026 05:45

@flaviendelangle flaviendelangle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR review

This is a clean, well-scoped fix that makes Progress.Root normalize value/percentage once and use it everywhere, mirroring the Meter fix (#4904). For the common default range (min=0, max=100) the output is byte-for-byte identical to before (clamp(valueToPercent(v,0,100),0,100) === v for in-range v), so there's no regression on the hot path; the changes only affect custom ranges and overshoot, which is the intended fix. The useValueAsRef removal genuinely fixes the one-commit format lag (confirmed: useValueAsRef updates .current in a layout effect, so the render reading .current sees the stale value). Tests cover the new cases, and no orphaned references to the removed formatNumberValue remain in source. Nothing is merge-blocking.

Bugs (0)

No findings.

Tests (0)

No findings.

Simplifications (0)

No findings.

Docs (1)

1. ℹ️ ${value}% fallback in getDefaultAriaValueText is now unreachable and would be wrong for custom ranges

Location: packages/react/src/progress/root/ProgressRoot.tsx:16

function getDefaultAriaValueText(formattedValue: string | null, value: number | null) {
  if (value == null) {
    return 'indeterminate progress';
  }
  return formattedValue || `${value}%`;
}

After this PR formattedValue is always a non-empty string for any finite value (it's a percent or formatted number), and value == null returns early — so the `${value}%` branch is dead. It's pre-existing and harmless, but it's now also semantically stale: it hard-codes the old "raw value as percent" assumption the PR deliberately moves away from, so if it ever did fire on a custom range it'd contradict the indicator. Not introduced by this PR and safe to leave; worth dropping to return formattedValue while this file is being touched.

Failure scenario: Future refactor that allows an empty formattedValue would silently resurrect the inconsistent 30%-style text this PR fixed.

Fix: Simplify to return formattedValue; (the value == null guard already handles the only empty case).

Verdict

Approve — correctness-improving fix with matching tests; no 🔴 or 🟡 findings, only one optional dead-code cleanup. I reasoned through the behavior rather than executing the suite (the working tree is on master, so the PR's new tests can't run against the unmodified source locally); the logic and the Meter parity check out.


🤖 Review generated with Claude Code

@atomiks
atomiks merged commit 0778339 into mui:master Jun 22, 2026
6 checks passed
@atomiks
atomiks deleted the claude/charming-keller-d872ee branch June 22, 2026 11:19
markhayden added a commit to markhayden/bakin that referenced this pull request Oct 4, 2026
…st, WebKit abort wording) (#955)

* chore(deps): @base-ui/react 1.4.1 → 1.8.0 (root + packages/ui)

The only breaking changes in 1.5–1.8 are the OTP Field renames, unused
here. Observable changes (controlled-open detection, submenu hover-open,
Form focusing the first invalid field, Dialog/Popover ignoring outside
clicks from presses that began before open, Select/Menu a11y tree) are
why this PR runs the full visual + conformance lanes. Base UI's
BASE_UI_ANIMATIONS_DISABLED switch (PR 1) is unchanged in 1.8 and the
teeth test passes. SDK UI reachable bytes +5 KB; ratchet + embedded
manifest regenerated. TODO row 5 ticked.

Refs #760

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* test(build): assert Base UI modules are unique per chunk, not "one chunk total"

The split-vendor test took "the data-base-ui string appears in exactly one
chunk" as its no-duplication check. Base UI 1.8's Tooltip module introduces
data-base-ui-tooltip-trigger and bun's splitter places that module in a
different shared chunk from the core Base UI chunk — spread, not
duplicated (every data-base-ui-* attribute still lives in exactly one
chunk). The test now checks three Base UI module markers each appear in
exactly one chunk, which is the property #422 guards.

Refs #760

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* chore(ui): re-capture five snapshots for Base UI 1.8; sweep log for PR 6

feedback-progress-markers (desktop + mobile): the story's bar is
value=140 max=200 — 1.4's Progress.Value printed "140%" over a 70 % fill;
1.8 formats the real percentage ("70%"; Base UI 1.7.0 "Fix custom
min/max semantics to match the indicator", mui/base-ui#5095). The old
baseline encoded the bug. collection-same-records (desktop + mobile):
row-menu triggers moved by a pixel. overlays-tooltip (mobile): sub-pixel
popup shift. All rendered in the canonical container; four other
sub-threshold rewrites left as committed.

Refs #760

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* test(ui): accept WebKit's wording for navigation-cancelled lazy chunks

The story-smoke behavior tests already treat navigation-cancelled chunk
loads as non-errors (NS_BINDING_ABORTED, net::ERR_ABORTED); WebKit
reports the same event as "Load request cancelled" and tripped once on
the axe chunk during a story navigation. All 27 copies of the handler
now carry the third wording. WebKit lane re-run: 57 passed.

Refs #760

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: progress Changes related to the progress component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants