Skip to content

[number field] Add allowOutOfRange prop - #3919

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:atomiks/numberfield-clamp
Feb 4, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:atomiks/numberfield-clamp

Conversation

@atomiks

@atomiks atomiks commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1845. Adds an allowOutOfRange prop so native rangeOverflow/rangeUnderflow validation can be triggered.

@atomiks atomiks added component: number field Changes related to the number field component. type: new feature Expand the scope of the product to solve a new problem. labels Feb 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 1, 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@3919
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3919
    

commit: b4ae1c7

@mui-bot

mui-bot commented Feb 1, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+130B(+0.03%) 🔺+110B(+0.08%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b4ae1c7
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698318951208960008e458d8
😎 Deploy Preview https://deploy-preview-3919--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@atomiks
atomiks force-pushed the atomiks/numberfield-clamp branch 3 times, most recently from 0fc8997 to 8cac98f Compare February 1, 2026 20:15
@atomiks
atomiks marked this pull request as ready for review February 1, 2026 20:19
@greptile-apps

greptile-apps Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR adds an allowOutOfRange prop to the Number Field component, enabling native HTML range validation (rangeOverflow/rangeUnderflow) for form validation use cases.

Key changes:

  • Added allowOutOfRange boolean prop (default: false) to NumberFieldRoot
  • Modified validation logic to skip clamping for direct text entry when enabled
  • Step-based interactions (keyboard arrows, increment/decrement buttons, wheel, scrub) still enforce min/max bounds
  • Comprehensive test coverage for both enabled and disabled states
  • Updated API documentation and JSDoc comments

Implementation details:
The logic correctly distinguishes between text-based input (which can be out of range when allowOutOfRange is true) and step-based interactions (which always clamp to maintain expected behavior). The change uses reason codes (inputChange, inputBlur, inputPaste, inputClear, none) to determine when to allow out-of-range values, matching native input behavior.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-designed, thoroughly tested, and follows established patterns in the codebase. The logic correctly distinguishes between text-based and step-based interactions, maintaining expected UX while enabling native validation. All changes are properly documented and tested.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/number-field/root/NumberFieldRoot.tsx Added allowOutOfRange prop with logic to conditionally skip clamping for text-based input while maintaining clamping for step-based interactions
packages/react/src/number-field/utils/validate.ts Added clamp parameter to toValidatedNumber function to conditionally apply range clamping
packages/react/src/number-field/root/NumberFieldRoot.test.tsx Added comprehensive tests for allowOutOfRange prop covering both enabled and disabled states with validation checks

@mj12albert mj12albert 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.

This wouldn't work for slider but it's not that important since the native input type="range" doesn't go out of bounds either

@atomiks
atomiks force-pushed the atomiks/numberfield-clamp branch from e8659d3 to 538ff15 Compare February 4, 2026 07:58
@atomiks
atomiks force-pushed the atomiks/numberfield-clamp branch from 538ff15 to f805900 Compare February 4, 2026 09:08
@atomiks
atomiks merged commit c8fa087 into mui:master Feb 4, 2026
7 checks passed
@atomiks
atomiks deleted the atomiks/numberfield-clamp branch February 4, 2026 10:06
@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2026
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: number field Changes related to the number field component. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[field][number field][slider] min/max props conflict with field min/max validation

3 participants