Skip to content

[number field] Create component from the Base UI equivalent - #49275

Open
silviuaavram wants to merge 135 commits into
mui:masterfrom
silviuaavram:feat/number-field
Open

silviuaavram wants to merge 135 commits into
mui:masterfrom
silviuaavram:feat/number-field

Conversation

@silviuaavram

@silviuaavram silviuaavram commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes #48335

Adds @mui/material/NumberField, replacing the docs-only implementation. Base UI handles numeric input, formatting, and stepping. Material UI provides the input variants, labels, controls, and theme integration.

Documentation preview

Features

  • Supports outlined, filled, and standard variants with labels, helper text, sizes, colors, and form states. Unlabeled filled fields match TextField sizing, with hiddenLabel available as an opt-in.
  • Supports controlled and uncontrolled values, bounds, configurable steps, locale-aware formatting, keyboard adjustments, and optional wheel scrubbing.
  • onValueChange and onValueCommitted receive a number or null and a details.reason identifying the interaction. Text edits commit on blur, keyboard and wheel steps commit immediately, and pointer adjustments commit on release.
  • controlsPosition places the stepper buttons at the end (default), splits them across both sides, stacks them as chevrons, or hides them with false. scrubAreaPosition independently places a drag handle at the start or end.
  • startAdornment and endAdornment accept text, icons, or buttons directly. For example, startAdornment="$" and endAdornment="/hr" display an hourly rate. Adornments sit closest to the editable input when they share a side with a scrub handle or stepper, and stay mounted when the controls move.
  • Typed slots, utility classes, sx, and MuiNumberField theme overrides support customization. The root and slot render props change the rendered element while preserving Material styling and Base UI behavior.

Base UI component mapping

Base UI part Material slot Integration
Root root Renders through FormControl and owns numeric state and form submission.
Group input Shares the Material input root and supplies role="group" without an extra wrapper.
Input htmlInput Connects Base UI behavior to the visible text input.
Increment / Decrement incrementButton / decrementButton Render through IconButton with plus/minus icons or stacked chevrons.
ScrubArea scrubArea Provides the drag handle with configurable direction, sensitivity, and content.
ScrubAreaCursor scrubAreaCursor Renders the custom cursor in a portal during mouse scrubbing when supported.

Material UI supplies the inputLabel, formHelperText, and controls slots. Split controls reuse the controls slot on each side, with ownerState.position identifying which side is rendering. Consumer adornment wrappers can be styled with MuiNumberField-startAdornment and MuiNumberField-endAdornment. The scrub handle and cursor are customized through their own slots.

Implementation and suggested review order

Files are under packages/mui-material/src/NumberField/.

File Review focus
NumberField.types.ts and NumberField.tsx Public API, variant-specific input props, defaults, and slot owner state.
NumberFieldRootSlot.tsx FormControl composition, label and helper text associations, and initial filled and adorned state during SSR.
NumberFieldInputSlot.tsx and NumberFieldInputRootSlot.tsx Shared Group and input root, adornment ordering, and placement of controls and the scrub handle.
NumberFieldControlsSlot.tsx, NumberFieldButtonSlot.tsx, and NumberFieldScrubAreaSlot.tsx Stepper layout, keyboard activation, and drag behavior.
RenderElement.tsx and utils/resolveInputProps.ts Shared render handling, slot replacement precedence, and native input prop resolution.

Set name directly on NumberField to submit the unformatted value once. A field displaying $5.00 submits "5". Supplying name only through an input slot triggers a development warning. The forwarded ref targets the FormControl root, and inputRef targets the visible input.

Shared changes

  • Adds @base-ui/react@^1.9.0 with deep imports.
  • Registers component exports, theme types, utility classes, and generated API documentation.
  • Adds localized accessible labels for the stepper buttons and a localized role description for the input.

Documentation and validation

The 18 demos cover variants, formatting, constraints, control placement, scrubbing, adornments, forms, rendering, and theme customization. The anatomy section shows the rendered HTML, including the input group and its label and helper text associations.

Interaction tests verify callback values and reasons for typing, clearing, pasting, blurring, keyboard steps, button presses, wheel steps, and dragging. Other tests cover slot replacement, event and ref composition, form submission, SSR and hydration, and public types.

Visual regression coverage includes all 18 demos and four additional fixtures for empty fields, unlabeled filled fields alongside TextField, stacked controls at a larger font size, and filled split controls with an end scrub handle. The PR’s unit, browser, type, lint, and regression checks passed.

Known limitations

  • Uncontrolled fields retain their value on native form reset. The form demo shows how to restore a controlled value in onReset. Base UI #1346
  • Base UI renders a visually hidden native input immediately after the field root, which affects selectors such as :last-child. The anatomy docs recommend gap on the parent to space adjacent fields. Base UI follow-up

@silviuaavram silviuaavram self-assigned this Oct 1, 2026
@silviuaavram silviuaavram added type: new feature Expand the scope of the product to solve a new problem. scope: number field Changes related to the number field. labels Oct 1, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 1, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+47.5KB(+8.29%) 🔺+16.9KB(+10.30%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±9.4% (±13.4% at worst) · ran 4m 06s · details


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

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 5, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 13, 2026
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Oct 27, 2026
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Oct 31, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 3, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 5, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 5, 2026
@silviuaavram
silviuaavram marked this pull request as ready for review November 5, 2026 16:14
Copilot AI balanced review requested due to automatic review settings November 5, 2026 16:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The color and size PropTypes validators reject supported custom values, causing development warnings on React versions that check PropTypes.

2 open issues
1 file not reviewed
  • pnpm-lock.yaml: Generated file
What changed in this PR

Promotes the documentation’s NumberField example into a public Material UI component, addressing #48335. It combines Base UI numeric behavior with Material inputs, form styling, and customization APIs.

Changes:

  • Adds NumberField with three variants, numeric formatting, stepping, scrubbing, typed slots, and theme integration.
  • Replaces copy-and-paste implementations with component demos and generated API documentation.
  • Adds public-type and augmentation checks, adapts documentation tests, and coordinates ButtonBase keyboard cancellation with Base UI.
File Description
test/​moduleAugmentation/​material/​numberFieldCustomProps.tsconfig.json Isolates augmentation checks.
test/​moduleAugmentation/​material/​numberFieldCustomProps.spec.tsx Checks custom props, slots, and theme types.
test/​e2e-website/​demo-docs-production.spec.ts Moves multi-file demo checks to Autocomplete.
pnpm-lock.yaml Records the Material package’s Base UI dependency.
packages/​mui-material/​src/​styles/​props.ts Registers NumberField theme prop types.
packages/​mui-material/​src/​styles/​overrides.ts Registers NumberField style override keys.
packages/​mui-material/​src/​styles/​components.ts Adds NumberField theme configuration.
packages/​mui-material/​src/​NumberField/​utils/​useUtilityClasses.ts Composes NumberField utility classes.
packages/​mui-material/​src/​NumberField/​utils/​resolveInputProps.ts Resolves native prop precedence before merging.
packages/​mui-material/​src/​NumberField/​utils/​index.ts Exports internal helpers.
packages/​mui-material/​src/​NumberField/​utils/​getControlElements.tsx Places controls in input adornments.
packages/​mui-material/​src/​NumberField/​NumberFieldRootSlot.tsx Composes form structure and initial label state.
packages/​mui-material/​src/​NumberField/​NumberFieldInputSlot.tsx Integrates Material inputs, controls, and scrubbing.
packages/​mui-material/​src/​NumberField/​numberFieldClasses.ts Defines public utility classes.
packages/​mui-material/​src/​NumberField/​NumberFieldButtonSlot.tsx Merges button behavior, refs, and state.
packages/​mui-material/​src/​NumberField/​NumberField.types.ts Defines public props and slot types.
packages/​mui-material/​src/​NumberField/​NumberField.tsx Implements the public component.
packages/​mui-material/​src/​NumberField/​NumberField.spec.tsx Checks public TypeScript contracts.
packages/​mui-material/​src/​NumberField/​index.ts Exports component, types, and classes.
packages/​mui-material/​src/​internal/​svg-icons/​Remove.tsx Adds the decrement icon.
packages/​mui-material/​src/​internal/​svg-icons/​OpenInFull.tsx Adds the scrub cursor icon.
packages/​mui-material/​src/​internal/​svg-icons/​ImportExport.tsx Adds the scrub handle icon.
packages/​mui-material/​src/​InputAdornment/​InputAdornment.d.ts Adds a NumberField demo documentation link.
packages/​mui-material/​src/​Input/​Input.d.ts Adds a NumberField demo documentation link.
packages/​mui-material/​src/​index.js Exports NumberField from the package.
packages/​mui-material/​src/​index.d.ts Exports NumberField declarations.
packages/​mui-material/​src/​FormLabel/​FormLabel.d.ts Removes the obsolete demo documentation link.
packages/​mui-material/​src/​FilledInput/​FilledInput.d.ts Adds a NumberField demo documentation link.
packages/​mui-material/​src/​ButtonBase/​useButtonBase.ts Honors Base UI keyboard-handler cancellation.
packages/​mui-material/​src/​Button/​Button.d.ts Removes the obsolete demo documentation link.
packages/​mui-material/​package.json Adds Base UI and the NumberField entry point.
docs/​translations/​api-docs/​number-field/​number-field.json Adds API descriptions.
docs/​public/​static/​error-codes.json Registers the invalid control-position error.
docs/​pages/​material-ui/​api/​number-field.json Adds generated API metadata.
docs/​pages/​material-ui/​api/​number-field.js Adds the API page.
docs/​pages/​material-ui/​api/​input.json Adds the NumberField demo link.
docs/​pages/​material-ui/​api/​input-adornment.json Adds the NumberField demo link.
docs/​pages/​material-ui/​api/​form-label.json Removes the obsolete demo link.
docs/​pages/​material-ui/​api/​filled-input.json Adds the NumberField demo link.
docs/​pages/​material-ui/​api/​button.json Removes the obsolete demo link.
docs/​pages/​experiments/​number-field.tsx Adds a manual integration playground.
docs/​data/​material/​pagesApi.js Registers the NumberField API route.
docs/​data/​material/​components/​number-field/​number-field.md Documents the component and customization APIs.
docs/​data/​material/​components/​number-field/​demos/​validation/​ValidationNumberField.tsx Demonstrates controlled validation.
docs/​data/​material/​components/​number-field/​demos/​validation/​index.ts Registers the validation demo.
docs/​data/​material/​components/​number-field/​demos/​validation/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​theme/​NumberFieldTheme.tsx Demonstrates theme defaults and overrides.
docs/​data/​material/​components/​number-field/​demos/​theme/​index.ts Registers the theme demo.
docs/​data/​material/​components/​number-field/​demos/​theme/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​steps/​NumberFieldSteps.tsx Demonstrates steps, modifiers, and snapping.
docs/​data/​material/​components/​number-field/​demos/​steps/​index.ts Registers the stepping demo.
docs/​data/​material/​components/​number-field/​demos/​steps/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​state/​NumberFieldState.tsx Demonstrates values and commit callbacks.
docs/​data/​material/​components/​number-field/​demos/​state/​index.ts Registers the state demo.
docs/​data/​material/​components/​number-field/​demos/​state/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​stacked-controls/​StackedNumberField.tsx Demonstrates stacked chevron controls.
docs/​data/​material/​components/​number-field/​demos/​stacked-controls/​index.ts Registers the stacked-controls demo.
docs/​data/​material/​components/​number-field/​demos/​stacked-controls/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​spinner-demo/​SpinnerDemo.tsx Rebuilds the spinner using NumberField.
docs/​data/​material/​components/​number-field/​demos/​spinner-demo/​NumberSpinner.tsx Removes the standalone spinner implementation.
docs/​data/​material/​components/​number-field/​demos/​sizes/​NumberFieldSizes.tsx Demonstrates sizes across variants.
docs/​data/​material/​components/​number-field/​demos/​sizes/​index.ts Registers the sizes demo.
docs/​data/​material/​components/​number-field/​demos/​sizes/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-placement/​NumberFieldScrubAreaPlacement.tsx Demonstrates independent handle placement.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-placement/​index.ts Registers the placement demo.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-placement/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-options/​NumberFieldScrubAreaOptions.tsx Demonstrates drag direction and sensitivity.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-options/​index.ts Registers the scrub-options demo.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-options/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-customization/​index.ts Registers the scrub-customization demo.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-customization/​CustomizedNumberFieldScrubArea.tsx Demonstrates custom handles and cursors.
docs/​data/​material/​components/​number-field/​demos/​scrub-area-customization/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​full-width/​index.ts Registers the full-width demo.
docs/​data/​material/​components/​number-field/​demos/​full-width/​FullWidthNumberField.tsx Demonstrates container-width sizing.
docs/​data/​material/​components/​number-field/​demos/​full-width/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​format/​index.ts Registers the formatting demo.
docs/​data/​material/​components/​number-field/​demos/​format/​FormattedNumberFields.tsx Demonstrates localized currencies and percentages.
docs/​data/​material/​components/​number-field/​demos/​format/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​form/​NumberFieldForm.tsx Demonstrates submission and controlled reset.
docs/​data/​material/​components/​number-field/​demos/​form/​index.ts Registers the form demo.
docs/​data/​material/​components/​number-field/​demos/​form/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​form-props/​index.ts Registers the form-props demo.
docs/​data/​material/​components/​number-field/​demos/​form-props/​FormPropsNumberFields.tsx Demonstrates required, disabled, and read-only states.
docs/​data/​material/​components/​number-field/​demos/​form-props/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​field-demo/​NumberField.tsx Removes the standalone field implementation.
docs/​data/​material/​components/​number-field/​demos/​field-demo/​index.ts Removes the obsolete demo registration.
docs/​data/​material/​components/​number-field/​demos/​field-demo/​FieldDemo.tsx Removes the previous field demo.
docs/​data/​material/​components/​number-field/​demos/​controls-position/​NumberFieldControlPositions.tsx Demonstrates start, end, and split controls.
docs/​data/​material/​components/​number-field/​demos/​controls-position/​index.ts Registers the control-position demo.
docs/​data/​material/​components/​number-field/​demos/​controls-position/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​constraints/​NumberFieldConstraints.tsx Demonstrates bounds and out-of-range input.
docs/​data/​material/​components/​number-field/​demos/​constraints/​index.ts Registers the constraints demo.
docs/​data/​material/​components/​number-field/​demos/​constraints/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​color/​NumberFieldColors.tsx Demonstrates focus colors.
docs/​data/​material/​components/​number-field/​demos/​color/​index.ts Registers the color demo.
docs/​data/​material/​components/​number-field/​demos/​color/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​basic/​index.ts Registers the basic demo.
docs/​data/​material/​components/​number-field/​demos/​basic/​client.ts Adds its client boundary.
docs/​data/​material/​components/​number-field/​demos/​basic/​BasicNumberFields.tsx Demonstrates the three variants.
docs/​data/​material/​components/​number-field/​demos/​adornments/​NumberFieldAdornments.tsx Demonstrates consumer prefixes and suffixes.
docs/​data/​material/​components/​number-field/​demos/​adornments/​index.ts Registers the adornments demo.
docs/​data/​material/​components/​number-field/​demos/​adornments/​client.ts Simplifies the client-provider export.

Review effort: Balanced

@silviuaavram

Copy link
Copy Markdown
Member Author

@claude review xhigh

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR review

This adds a large new public component (NumberField) plus a change to useButtonBase, a hook shared by every Material button. The merge-blocking item is that shared hook change: it teaches useButtonBase to short-circuit keyboard activation on an undocumented baseUIHandlerPrevented flag that Base UI sets on the synthetic event, which affects all ButtonBase consumers and has no test. Also blocking-adjacent: resolveInputProps silently drops the callback form of slotProps.input.slotProps.input, and a generated JSDoc demo list is stale.

Verification limits: @base-ui/react is not installed in this checkout, so Base UI internals (the exact semantics and lifetime of baseUIHandlerPrevented, and whether NumberField.Root's id lands only on the input) could not be confirmed from source — those findings are reasoned from the Material-side code and are labelled accordingly. No tests were run. This review was also capped by the turn budget, so coverage of the ~3600-line test file and the 20 new demo folders is partial.

Bugs (7)

1. 🔴 useButtonBase now keys global keyboard activation off a Base UI–private event flag

Location: packages/mui-material/src/ButtonBase/useButtonBase.ts:105

function isBaseUIHandlerPrevented(event: React.KeyboardEvent<HTMLElement>) {
  return 'baseUIHandlerPrevented' in event && event.baseUIHandlerPrevented === true;
}
if (
  event.target !== event.currentTarget ||
  hasNativeKeyboardActivation() ||
  isBaseUIHandlerPrevented(event)
) {
  return;
}

This is a behavior change in a hook used by Button, IconButton, MenuItem, Tab, ListItemButton, ToggleButton and every other ButtonBase consumer — not just by NumberField. Three concerns compound:

  • Scope. The flag lives on the React synthetic event, which is the same object as it bubbles. Any Base UI handler on a descendant that calls preventBaseUIHandler() marks the event, and an ancestor Material ButtonBase rendered as a non-native button (component="span" / nativeButton={false}) will then skip both event.preventDefault() on Space and the synthesized currentTarget.click() on Enter/Space — so the button stops responding to the keyboard entirely.
  • Coupling. baseUIHandlerPrevented is an internal detail of @base-ui/react's mergeProps, not a documented contract. A rename upstream silently reverts this to the old behavior (double activation) with no type error and no test failure.
  • Semantics. The flag means "an external handler asked Base UI not to run its own handler." Re-reading it as "ButtonBase should not run its handler" is a different statement that happens to produce the right result for the NumberField stepper buttons.

Failure scenario: A consumer composes a Material <IconButton component="span" nativeButton={false}> inside a Base UI component (or passes it as a Base UI render target) where some handler in the chain calls event.preventBaseUIHandler(). Pressing Space or Enter on the button no longer fires onClick, and Space scrolls the page because preventDefault() is skipped. Nothing in NumberField's tests or ButtonBase.test.js / useButtonBase.test.tsx would catch it.

Fix: Keep the shared hook free of Base UI internals. NumberFieldButtonSlot already controls what reaches the button — pass an explicit opt-out (e.g. forward onBeforeKeyDown/a disableKeyboardActivation-style internal prop, or render the stepper with nativeButton so hasNativeKeyboardActivation() already short-circuits) instead of sniffing the event. If the sniff must stay, narrow it to the keydown path only, document the Base UI version the contract comes from, and add useButtonBase/ButtonBase tests that pin both the prevented and non-prevented branches.

2. 🟠 resolveInputProps silently drops slotProps.input.slotProps.input when it is a callback

Location: packages/mui-material/src/NumberField/utils/resolveInputProps.ts:49

const { input: nestedNativeProps, ...remainingMaterialSlotProps } = materialSlotProps ?? {};

// Resolve callback slot props so their returned props participate in precedence.
const selectedNativeProps = resolveComponentProps(effectiveHtmlInputSlotProps, ownerState);

const consumerNativeProps = {
  onKeyDown,
  onKeyUp,
  ...selectedNativeProps,
  ...nestedNativeProps,
};

effectiveHtmlInputSlotProps is run through resolveComponentProps, but nestedNativeProps is spread raw. Material UI's slotProps entries are documented as accepting (ownerState) => props as well as a plain object, and InputBaseProps['slotProps']['input'] is typed that way. Spreading a function yields zero own enumerable properties, so the props vanish — no error, no warning.

Failure scenario:

<NumberField
  slotProps={{
    input: {
      slotProps: { input: (ownerState) => ({ 'aria-label': `Amount (${ownerState.size})` }) },
    },
  }}
/>

The aria-label never reaches the native input, leaving the field unnamed. The equivalent object form works, so the bug looks like a typo in the consumer's code.

Fix: const nestedNativeProps = resolveComponentProps(materialSlotProps?.input, ownerState); (destructuring the key out separately so it is still removed from remainingMaterialSlotProps).

3. 🟠 There is no way to render a NumberField without the stepper buttons

Location: packages/mui-material/src/NumberField/NumberField.types.ts:23

export type ControlsPosition = 'stacked' | 'end' | 'split';

scrubArea accepts 'start' | 'end' | false, where false hides the handle — but controlsPosition has no false. The increment/decrement buttons are always rendered. The most common reason to reach for this component over <TextField type="number"> is the locale-aware formatting, clamping and parsing; many of those users do not want spinners. Today their only escape is slotProps={{ incrementButton: { sx: { display: 'none' } }, decrementButton: { ... } }}, which leaves two buttons in the DOM and keeps the adornment spacing.

Failure scenario: A consumer migrating a currency field from TextField renders <NumberField format={{ style: 'currency', currency: 'EUR' }} /> and gets two unwanted −/+ icon buttons inside the field with no documented way to remove them.

Fix: Accept controlsPosition={false} and skip getControlElements entirely in that case, mirroring scrubArea. This is much cheaper to add now than after the API ships.

4. 🟡 Invalid controlsPosition throws at render instead of degrading

Location: packages/mui-material/src/NumberField/utils/getControlElements.tsx:83

default:
  throw /* minify-error */ new Error(
    `MUI: Cannot position NumberField controls because "controlsPosition" is invalid: ${controlsPosition}. Use "stacked", "end", or "split".`,
  );

Every other Material enum prop (variant, size, color) degrades on an unexpected value. This one takes the whole tree down, in production, from a single typo — and the likeliest source is untyped config rather than JSX: createTheme({ components: { MuiNumberField: { defaultProps: { controlsPosition: 'right' } } } }).

Failure scenario: A JavaScript consumer (or a theme written in JS) sets controlsPosition="right". The app renders a blank screen with minified error 26 instead of a field with default-positioned controls.

Fix: console.error in development and fall back to 'end'; drop the error-code entry if the throw goes away.

5. 🟡 slotProps.htmlInput keyboard handlers silently replace slotProps.input ones

Location: packages/mui-material/src/NumberField/utils/resolveInputProps.ts:39

const { onKeyDown, onKeyUp, ...materialInputProps } = inputProps;
...
const consumerNativeProps = {
  onKeyDown,
  onKeyUp,
  ...selectedNativeProps,
  ...nestedNativeProps,
};

The JSDoc states this precedence deliberately, but lifting the wrapper's handlers to the lowest precedence means passing both slotProps.input.onKeyDown and slotProps.htmlInput.onKeyDown drops the first one entirely. Everywhere else in this file handlers compose (via mergeProps / extractEventHandlers), so the asymmetry is surprising.

Failure scenario: A consumer sets slotProps.input.onKeyDown to intercept Escape and later adds slotProps.htmlInput.onKeyDown for a data-entry shortcut. The Escape handler stops firing with no warning.

Fix: Compose the two rather than overwrite — chain onKeyDown from the wrapper before the native one, the way mergeProps does for the Base UI handlers.

6. ℹ️ Dead variant fallback that disagrees with the component's default

Location: packages/mui-material/src/NumberField/NumberFieldInputSlot.tsx:181

const InputComponent = variantComponent[materialProps.variant ?? 'standard'];

variant is defaulted to 'outlined' in NumberField.tsx:65 and ownerState.variant is typed NumberFieldVariants (non-optional), so ?? 'standard' is unreachable — and if it ever became reachable it would silently pick a different variant than the documented default. Note the neighbouring if (variant === 'outlined') block reads variant directly, so the two disagree. Drop the fallback.

7. ℹ️ labelId uses truthiness while label rendering uses a null check

Location: packages/mui-material/src/NumberField/NumberFieldRootSlot.tsx:51

const labelId = label && id ? `${id}-label` : undefined;
...
const hasLabel = label != null && label !== '';

label={0} satisfies hasLabel but not label &&, so the <InputLabel> renders without an id. There is a test for label={0} (renders zero as label and helper content) and it passes only because nothing currently references labelId — the input is named via htmlFor, not aria-labelledby. Harmless today, but it will bite whoever wires aria-labelledby later. Use hasLabel && id for both.

Tests (4)

1. 🟠 The useButtonBase change has no test anywhere

Location: packages/mui-material/src/ButtonBase/useButtonBase.ts:282

The diff touches a shared hook but leaves packages/mui-material/src/ButtonBase/useButtonBase.test.tsx and packages/mui-material/src/ButtonBase/ButtonBase.test.js untouched. Those files already have the scaffolding (nativeButton={false} renders, keydown/keyup cases) to pin this.

Failure scenario: Base UI renames or stops setting baseUIHandlerPrevented; the early return becomes dead code and the double-activation it was added to prevent returns — and the whole suite stays green. Conversely, if the flag ever appears on an unrelated event, keyboard activation silently breaks for every non-native Material button with no failing test.

Fix: Add two useButtonBase cases — a non-native button whose keydown/keyup event carries baseUIHandlerPrevented: true must not synthesize a click nor call preventDefault() on Space; without the flag it must still do both.

2. 🟡 No assertion that the root element does not share the input's id

Location: packages/mui-material/src/NumberField/NumberField.test.tsx:3105

expect(input).to.have.attribute('id', 'amount');

id is handed to BaseNumberField.Root (NumberField.tsx:104) and to the Material input slot (NumberFieldInputSlot.tsx:431). NumberFieldRootSlot merges Base UI's root props straight onto the FormControl via mergeProps(baseProps, externalHandlers), so if Base UI puts id on its root element the document ends up with two elements sharing it. The SSR test at line 3579 checks uniqueness only across input/label/helper ids, not against the root.

Failure scenario: A duplicate id on the wrapper div and the <input> breaks document.getElementById, label[for] resolution in some AT, and any consumer query by id — and nothing here would catch it.

Fix: Add expect(root).not.to.have.attribute('id', 'amount') (or assert whatever the intended root id is) to the existing labels/helper-text test.

3. 🟡 The controlsPosition error path is untested

Location: packages/mui-material/src/NumberField/utils/getControlElements.tsx:83

A new entry was reserved in docs/public/static/error-codes.json ("26"), but nothing renders a NumberField with an invalid controlsPosition. Error-code entries that are never exercised drift out of sync with the message text they encode.

Failure scenario: The message wording changes and error-codes.json is not regenerated; the minified build then emits a code that maps to stale text.

Fix: Add a case asserting the throw (or, if finding 4 is taken, the dev warning plus the 'end' fallback).

4. 🟡 The documented slotProps precedence rules are only tested in their object form

Location: packages/mui-material/src/NumberField/utils/resolveInputProps.ts:17

The JSDoc specifies a three-level precedence order including slotProps.input.slotProps.input, and slotProps.input.inputProps replacing slotProps.htmlInput "even if undefined". The callback form of the deepest level is the one that is actually broken (finding 2), and there is no test for it.

Failure scenario: Exactly the bug in finding 2 — the callback form drops all props and the suite stays green.

Fix: Parameterize the existing precedence tests over both the object and the (ownerState) => props form for each of the three levels.

Simplifications (3)

1. 🟡 The "drop nullish event handlers" idiom is copy-pasted three times and re-runs every render

Location: packages/mui-material/src/NumberField/utils/resolveInputProps.ts:64

Object.fromEntries(
  Object.entries(consumerNativeProps).filter(
    ([key, value]) => !(/^on[A-Z]/.test(key) && value == null),
  ),
)

The same expression appears at NumberFieldInputSlot.tsx:315 and NumberFieldButtonSlot.tsx:36 (the last one with an extra nativeButton clause). Three literal copies of a subtle rule, each allocating a new object plus an intermediate entries array on every render of every instance, and each with its own cast back to the source type.

Failure scenario: Someone fixes the regex or the nullish check in one place; the other two keep the old behavior, and the "unset handler must not erase Base UI's" invariant silently holds in two of three merge paths.

Fix: One exported helper in NumberField/utils, e.g. omitNullishEventHandlers(props, extraOmit?), used by all three call sites.

2. ℹ️ @base-ui/react becomes a hard runtime dependency of @mui/material

Location: packages/mui-material/package.json:37

"@base-ui/react": "^1.8.0",

This lands in every @mui/material install, including apps that never import NumberField. It is worth calling out explicitly in the PR description and release notes rather than letting it arrive as a lockfile diff — it changes the dependency footprint of the package for all consumers, and it is the first such dependency here. Two smaller points: the range ^1.8.0 is hand-written while the rest of the workspace consumes Base UI through catalog:docs (docs/package.json:22), so the two can drift and resolve to different copies; and it would be worth stating in the PR what the measured bundle delta is for an app that imports only, say, Button.

3. ℹ️ A 1575-line experiments page ships with the feature

Location: docs/pages/experiments/number-field.tsx:1

Experiment pages are normal in this repo, but this one is larger than the component, its tests' conformance block and all 20 demos combined, and it duplicates much of what the demos now cover. Consider trimming it to the cases the public demos do not exercise, or landing it separately so the feature diff stays reviewable.

Docs (4)

1. 🟠 The removal of the Number Field link from Button.d.ts is stale

Location: packages/mui-material/src/Button/Button.d.ts:136

- * - [Number Field](https://next.mui.com/material-ui/react-number-field/)

These "Demos:" lists are generated by pnpm docs:api from the components each demo actually uses, and one of the new demos does use Button:

// docs/data/material/components/number-field/demos/form/NumberFieldForm.tsx:3
import Button from '@mui/material/Button';

So the line should still be there. (The FormLabel.d.ts removal is correct — no new demo imports FormLabel.) This suggests pnpm docs:api was last run against an earlier state of the demos, which means other generated files may be stale too.

Failure scenario: The Button API page loses a valid demo cross-link, and the next unrelated PR that runs pnpm docs:api picks up an unexplained diff in Button.d.ts.

Fix: Re-run pnpm docs:api and commit the result.

2. 🟠 Native form reset is documented as not working, with no tracking link

Location: docs/data/material/components/number-field/number-field.md:156

Native form reset does not currently restore uncontrolled fields to their defaultValue.

Every other Material form control restores on <form> reset. Shipping a form field where the browser's reset button silently does nothing for the uncontrolled case is a real hole, and prose in the middle of a docs page is the weakest place to record it — the component's JSDoc, the defaultValue prop description and the API page all stay silent.

Failure scenario: A consumer builds <form><NumberField name="qty" defaultValue={1} /><button type="reset">Reset</button></form>, the reset leaves the typed value in place, and they file it as a bug because neither the defaultValue nor the form prop docs mention it.

Fix: Link a tracking issue from the docs sentence, and repeat the caveat on the defaultValue prop description so it reaches the API page and IntelliSense.

3. 🟡 The theme overrides section omits two themeable slots

Location: docs/data/material/components/number-field/number-field.md:181

Use MuiNumberField in the theme to set default props or override the root, controls, incrementButton, and decrementButton styles.

NumberFieldScrubArea and NumberFieldScrubAreaCursor are also declared with name: 'MuiNumberField' (NumberFieldInputSlot.tsx:113 and :142) and both have utility classes in numberFieldClasses.ts, so scrubArea and scrubAreaCursor are valid styleOverrides keys. Readers of this sentence will conclude the scrub handle can only be styled per-instance via slotProps.

Fix: Add scrubArea and scrubAreaCursor to the list.

4. ℹ️ MuiNumberField is inserted out of alphabetical order in three registries

Location: packages/mui-material/src/styles/overrides.ts:223

ComponentNameToClassKey places MuiNumberField after MuiPaper; styles/props.ts:213 places it after MuiSnackbarContent; and src/index.js:235 exports it before NoSsr while src/index.d.ts:241 correctly places it after. These files are otherwise strictly alphabetical, so the odd placements will read as accidental to the next person editing them.

Verdict

Request changes — the useButtonBase change alters keyboard activation for every Material button based on an undocumented Base UI event flag and ships with no test, and resolveInputProps silently drops the callback form of a documented slotProps path.


🤖 Review generated with Claude Code · Opus 5 (High) · xhigh review depth · 49 turns · 10m1s · $14.60 · run

@silviuaavram

Copy link
Copy Markdown
Member Author

Addressed each Claude comment apart from #2 and #5 (the slots merging). The rest should be addressed.

@silviuaavram

Copy link
Copy Markdown
Member Author

@claude review xhigh

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: out-of-date The pull request has merge conflicts and can't be merged. scope: number field Changes related to the number field. type: new feature Expand the scope of the product to solve a new problem. v10.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NumberField] Create Material-UI component from the Docs example

6 participants