Repository navigation
[all components] Type render callback props to the rendered element - #5104
Conversation
Specialize the render callback's props (the third generic of BaseUIComponentProps) to ComponentPropsWithRef<'tag'> for parts locked to a single element: Avatar.Image, Form, Fieldset.Root, NumberField.Input, OTPField.Input, and the anchor links (PreviewCard.Trigger, Menu.LinkItem, NavigationMenu.Link, Toolbar.Link). Keep the loose HTMLProps default for polymorphic parts (Field.Control, Toolbar.Input, Combobox/Autocomplete Input, Field.Label, Slider.Value, *.Button parts) so they can still be rendered as a different element. Also drop the injected type='text' from Combobox/Autocomplete Input (native default already; was invalid when rendered as a <textarea>).
commit: |
Bundle size
PerformanceTotal duration: 1,297.28 ms -96.59 ms(-6.9%) | Renders: 78 (+0) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The render prop type column now resolves to the element-specific props for the parts whose render callback was specialized (Avatar.Image, Form, Fieldset.Root, NumberField.Input, OTPField.Input, and the anchor links incl. Menu/ContextMenu LinkItem).
Pins two things for rendering Combobox/Autocomplete Input as a <textarea> via the render prop: it no longer receives an invalid `type` attribute (guards the removed injected type='text'), and the combobox ARIA attributes (role, aria-expanded, aria-controls) are applied only while the popup is open — a non-input control omits them when closed, unlike a native <input> which always exposes them.
7e508eb to
50ceaee
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves Base UI’s type safety for render callback props by specializing the third generic of BaseUIComponentProps to the actual rendered intrinsic element for selected components (e.g. <a>, <img>, <input>, <form>, <fieldset>), while keeping looser typing where polymorphism is intended. It also removes an injected type="text" from Combobox.Input to support rendering as <textarea> without invalid attributes, and updates type-level checks and generated docs accordingly.
Changes:
- Specialized
BaseUIComponentProps<..., ..., RenderFunctionProps>for several parts sorender={(props) => ...}exposes the correct intrinsic props (e.g.href,src,disabled). - Removed injected
type: 'text'fromCombobox.Inputand added runtime tests ensuring<textarea>rendering stays valid and editable. - Added/expanded type-level
*.spec.tsxchecks and updated generated docs to reflect the new callback prop types.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/toolbar/link/ToolbarLink.tsx | Specializes render callback props to native <a> props. |
| packages/react/src/toolbar/link/ToolbarLink.spec.tsx | Adds type-level check that render props include href. |
| packages/react/src/preview-card/trigger/PreviewCardTrigger.tsx | Specializes render callback props to native <a> props. |
| packages/react/src/preview-card/trigger/PreviewCardTrigger.spec.tsx | Adds type-level check that render props include href. |
| packages/react/src/otp-field/input/OTPFieldInput.tsx | Specializes render callback props to native <input> props. |
| packages/react/src/otp-field/input/OTPFieldInput.spec.tsx | Adds type-level checks for <input>-specific props in render. |
| packages/react/src/number-field/input/NumberFieldInput.tsx | Specializes render callback props to native <input> props. |
| packages/react/src/number-field/input/NumberFieldInput.spec.tsx | Adds type-level checks for <input>-specific props in render. |
| packages/react/src/navigation-menu/link/NavigationMenuLink.tsx | Specializes render callback props to native <a> props. |
| packages/react/src/navigation-menu/link/NavigationMenuLink.spec.tsx | Adds type-level check that render props include href. |
| packages/react/src/menu/link-item/MenuLinkItem.tsx | Specializes render callback props to native <a> props. |
| packages/react/src/menu/link-item/MenuLinkItem.spec.tsx | Adds type-level check that render props include href. |
| packages/react/src/form/Form.tsx | Specializes render callback props to native <form> props. |
| packages/react/src/form/Form.spec.tsx | Adds type-level check that render props include noValidate. |
| packages/react/src/fieldset/root/FieldsetRoot.tsx | Specializes render callback props to native <fieldset> props. |
| packages/react/src/fieldset/root/FieldsetRoot.spec.tsx | Adds type-level check that render props include disabled. |
| packages/react/src/combobox/input/ComboboxInput.tsx | Removes injected type="text" to allow <textarea> rendering without invalid attributes. |
| packages/react/src/combobox/input/ComboboxInput.test.tsx | Adds runtime coverage for rendering Combobox.Input as <textarea>. |
| packages/react/src/avatar/image/AvatarImage.tsx | Specializes render callback props to native <img> props. |
| packages/react/src/avatar/Avatar.spec.tsx | Adds type-level checks that Avatar.Image render props include src/alt. |
| docs/src/app/(docs)/react/components/toolbar/types.md | Updates generated API docs for specialized <a> render prop typing. |
| docs/src/app/(docs)/react/components/preview-card/types.md | Updates generated API docs for specialized <a> render prop typing. |
| docs/src/app/(docs)/react/components/otp-field/types.md | Updates generated API docs for specialized <input> render prop typing. |
| docs/src/app/(docs)/react/components/number-field/types.md | Updates generated API docs for specialized <input> render prop typing. |
| docs/src/app/(docs)/react/components/navigation-menu/types.md | Updates generated API docs for specialized <a> render prop typing. |
| docs/src/app/(docs)/react/components/menu/types.md | Updates generated API docs for specialized <a> render prop typing. |
| docs/src/app/(docs)/react/components/form/types.md | Updates generated API docs for specialized <form> render prop typing. |
| docs/src/app/(docs)/react/components/fieldset/types.md | Updates generated API docs for specialized <fieldset> render prop typing. |
| docs/src/app/(docs)/react/components/context-menu/types.md | Updates generated API docs impacted by specialized <a> render prop typing. |
| docs/src/app/(docs)/react/components/avatar/types.md | Updates generated API docs for specialized <img> render prop typing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
flaviendelangle
left a comment
There was a problem hiding this comment.
PR review
This PR is type-only except for one safe runtime change (dropping the injected type="text" on Combobox.Input/Autocomplete.Input). The native-input-vs-other-element ARIA branch keys off tagName === 'INPUT' (AriaCombobox.tsx:992), not the type attribute, so the removal doesn't disturb it, and the new tests pin both the editability and the open-only ARIA behavior. The render-callback specialization only propagates each component's already-declared element type ('img', 'form', 'input', 'a') to the callback param, so it can't tighten anything beyond what the component's own props already required. Nothing is merge-blocking.
Bugs (0)
No findings.
Tests (0)
No findings.
Simplifications (0)
No findings.
Docs (2)
1. ℹ️ Auto-generated render type is now noisy in public API tables
Location: docs/src/app/(docs)/react/components/form/types.md:11 (and the avatar/number-field/otp-field/preview-card/menu/navigation-menu/toolbar tables)
| render | `ReactElement \| ((props: React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, state: Form.State) => ReactElement)` | ... |The specialized third generic causes pnpm docs:api to emit the fully-expanded React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement> in place of the prior clean HTMLProps. It's accurate but considerably harder to read in the published prop table.
Failure scenario: A user scanning the Form/Avatar/Input prop tables sees a long leaky type for render instead of a concise one; purely a readability regression in the generated docs.
Fix: Optional — if the docs generator supports a type alias/display override, map these back to a short name; otherwise accept it as the cost of the more precise type.
2. ℹ️ Combobox.Input no longer emits a type="text" attribute
Location: packages/react/src/combobox/input/ComboboxInput.tsx:205
// removed:
type: 'text',Behaviorally inert for a native <input> (text is the default), and the PR documents it as intentional. The only observable effect is that the rendered DOM element no longer carries type="text", so an app styling the input via an input[type="text"] selector would stop matching. The in-repo demos that rely on type="text" pass it explicitly (autocomplete/demos/grid/...), so they're unaffected.
Failure scenario: A consumer with CSS like .MyCombobox input[type="text"] { ... } loses those styles after upgrading.
Fix: None needed; consider a one-line changelog/migration note since it's a visible DOM-attribute change.
Verdict
Approve — type-only specialization plus a safe, well-tested type="text" removal; no correctness or test gaps, only minor cosmetic notes on generated docs.
🤖 Review generated with Claude Code
<!-- CURSOR_AGENT_PR_BODY_BEGIN --> ## Summary Upgrades `@base-ui/react` from `^1.6.0` → `^1.7.0` (latest as of Aug 4, 2026). No Frosted UI source changes were required. Validated locally: - `tsc` (CJS + ESM) ✅ - `eslint` + `stylelint` ✅ - `vitest` — 312/312 tests passing ✅ Sources: [Base UI v1.7.0 release notes](https://base-ui.com/react/overview/releases/v1-7-0), [GitHub release](https://github.com/mui/base-ui/releases/tag/v1.7.0), [CHANGELOG](https://github.com/mui/base-ui/blob/master/CHANGELOG.md). --- ## Breaking changes **Official changelog marks no 🚨 breaking changes in v1.7.0.** However, there are behavioral, API, and type changes consumers (and Frosted UI wrappers) should be aware of: ### Behavioral / DOM changes (potentially breaking in practice) 1. **`Accordion.Root` no longer sets an implicit `dir` attribute** ([#5117](mui/base-ui#5117)) - Previously `Accordion.Root` wrote `dir` onto the root. Direction now comes from the document / ancestor only. - Impact: CSS/JS that depended on `Accordion.Root[dir]` may stop matching. Pass `dir` explicitly if needed. 2. **`Combobox.Input` / `Autocomplete.Input` no longer inject `type="text"`** ([#5104](mui/base-ui#5104)) - Native `<input>` still defaults to text, but the attribute is no longer present in the DOM. - Impact: selectors like `input[type="text"]` will no longer match unless `type="text"` is passed explicitly. 3. **Listbox separators use `role="presentation"`** ([#5399](mui/base-ui#5399)) - `Select.Separator`, `Combobox.Separator`, and `Autocomplete.Separator` no longer expose `role="separator"` (axe/ARC compliance). - `Select.Separator` switched from a re-export of the generic `Separator` to a dedicated listbox separator component. - Public props (`orientation`, etc.) are preserved. 4. **Checkbox Group / Radio Group form values aligned with native submission** ([#5218](mui/base-ui#5218), [#5238](mui/base-ui#5238)) - Form payload shape may change vs prior Base UI behavior. Verify any custom form serialization that assumed the old values. 5. **Popup / overlay remount + handle reuse** - Dialog, Alert Dialog, Drawer, Menu, Popover, Preview Card, Tooltip no longer reopen after remounting with a reused handle ([#5109](mui/base-ui#5109), [#5149](mui/base-ui#5149)). 6. **Disabled state inheritance** - `Combobox.Item` / `Select.Item` inherit disabled from Root ([#5365](mui/base-ui#5365)). - `Menu` propagates disabled state to items ([#5363](mui/base-ui#5363)). 7. **`Field` keeps invalid state when disabled** ([#5116](mui/base-ui#5116)). 8. **`Select` no longer force-mounts the popup on programmatic value changes** ([#5119](mui/base-ui#5119)). ### API additions / changes | Area | Change | |---|---| | Autocomplete / Combobox | New `ChangeEventReason` values: `"input-press"`, `"cancel-open"` ([#5356](mui/base-ui#5356), [#5376](mui/base-ui#5376)) | | Autocomplete | New `form?: string` prop on Root (associates the internal input with an external form) | | Combobox | Exposes `aria-expanded` / expanded behavior for inline comboboxes ([#5332](mui/base-ui#5332)) | | Combobox / Autocomplete | New `.Separator` part | | Select | Dedicated `.Separator` part (listbox-safe semantics) | | Toast | `render` prop content now works on `Toast.Title`, `Toast.Description`, `Toast.Action` ([#5210](mui/base-ui#5210)) | | Modal docs | Touch-device modal scroll behavior clarified for Combobox / Select | ### Type changes 1. **`render` callback props specialized to the rendered element** ([#5104](mui/base-ui#5104)) - Third generic of `BaseUIComponentProps` now types callback props as the intrinsic element for: - `Avatar.Image` → `'img'` - `Form` → `'form'` - `NumberField.Input` / `OTPField.Input` → `'input'` - `PreviewCard.Trigger` / `Menu.LinkItem` / `NavigationMenu.Link` / `Toolbar.Link` → `'a'` - Polymorphic parts (e.g. `Combobox.Input`, `Field.Control`, button parts via `nativeButton`) remain loosely typed as `HTMLProps`. - May surface new TS errors if a `render` callback assumed looser props (or the reverse: more precise props like `src`/`href` are now available). 2. **Implementation-only types stripped from published `.d.ts`** ([#5165](mui/base-ui#5165)) - `@internal` declarations are no longer emitted. - Deep imports of internals (e.g. previously published helpers like `FloatingFocusManager`, `useAnchorPositioning`, numeral utils, store helpers) will fail typechecking if used. - Frosted UI does not depend on these internals. 3. **`AutocompleteRootChangeEventReason` / `ComboboxRootChangeEventReason` union widened** - Adds `"input-press"` and `"cancel-open"`. Exhaustive `switch`/`if` chains over reasons may need updates. 4. **Internal path moves** (only relevant for deep imports) - e.g. `useAnchorPositioning` moved under `internals/`; several utils relocated/removed from the public declaration graph. ### Frosted UI impact assessment | Concern | Status | |---|---| | Compile / typecheck against 1.7.0 | Passes with no source edits | | Existing `DialogRootActions` / `AlertDialogRootActions` imports | Still exported | | `useRender` / `mergeProps` | Unchanged public surface | | Autocomplete `keepHighlight` stories | Still valid (Autocomplete retains the prop; Combobox had removed it earlier in 1.6) | | Select.Separator wrapper | Compatible; benefits from a11y role fix automatically | --- ## What's new in `@base-ui/[email protected]` ### Features / enhancements - Typed `render` callback props based on the rendered element - Autocomplete locale-aware filtering - Autocomplete `form` prop for associating an external form - New Combobox / Autocomplete / Select listbox `Separator` parts (presentation role) - Combobox inline `aria-expanded` exposure - New open-change reasons: `input-press`, `cancel-open` - Scroll Area WebKit overscroll feedback on Thumb - Avatar Fallback shows immediately when `delay={0}` - Toast `render` prop support on Title / Description / Action ### Fixes (high level) - Popup positioning: collision padding off-by-one, unwanted flip with capped scrollable content, left-anchored auto-resize origin, unpositioned popups at viewport origin, canceled-exit unmount completion - Focus restoration after keyboard close in Safari/Firefox - Dialog touch outside-press without backdrop; scroll-lock handoff with external overlays - Drawer swipe/open reliability, iOS cross-axis scroll, Shadow DOM gestures, virtual keyboard scroll - Menu/submenu: duplicate `onOpenChange`, VoiceOver, TalkBack, pinch-zoom, Chrome mouseleave - Combobox/Select highlight/filter/scroll fixes (Safari hover highlight, grouped limit, query clear, disabled inheritance) - Field `data-dirty` for null-valued controls; Form focuses first invalid field in document order - Number Field multi-character format symbol editing - Progress custom `min`/`max` semantics - Slider assorted fixes; Tabs Suspense pre-hydration indicator - Toast timer / swipe / re-add / provider effect ordering - Navigation Menu frozen state when open trigger unmounts - Radio unnecessary ARIA attributes removed; internal input clicks no longer bubble (Checkbox/Switch/Radio) ### Performance / bundle size Across many components Base UI reduced parsed bundle size and avoided redundant work: - Shared popup / store / dialog / popover / field / form / meter / progress / scroll-area / slider / switch / tabs / toast / toolbar / toggle-group size reductions - Avoid redundant re-renders during lazy flipping - Remove redundant lifecycle synchronization - Exclude prehydration scripts from client bundles (Slider, Tabs) - Deduplicate Combobox/Select/Autocomplete handlers and swipe math --- ## Full v1.7.0 changelog (from upstream) ### General - Restore visible focus after keyboard close in Safari and Firefox (#5093) - Type `render` callback props based on the rendered element (#5104) - Reduce popup / store / shared popup bundle size (#5233, #5250, #5192) - Keep unpositioned popups at the viewport origin (#5299) - Correct layout and passive effect timing (#5337) - Remove redundant lifecycle synchronization (#5341) - Prevent stale cleanup from clearing registered part IDs (#5340) - Complete popup unmounting after a canceled exit transition (#5401) - Fix rendered trigger ID ownership (#5110) - Prevent unwanted flip with capped scrollable content (#5120) - Fix `collisionPadding` off-by-one on the biased side (#5143) - Mount popup subtrees synchronously when opening in React 17 (#5309) - Fix auto-resize origin for left-anchored popups (#5370) - Avoid redundant re-renders during lazy flipping (#5372) - Strip implementation-only types from published `.d.ts` files (#5165) - Fix `usePreviousValue` equality comparison (#5264) ### Components - **Accordion:** Remove implicit `dir` on Root (#5117) - **Alert Dialog / Dialog / Drawer / Menu / Popover / Preview Card / Tooltip:** Prevent reopen after remount with reused handle (#5109, #5149) - **Autocomplete:** Locale filtering; `input-press` / `cancel-open` reasons; reset scroll on filter; separator semantics - **Avatar:** Fallback immediate at `delay={0}` - **Button:** Keyboard click for custom elements - **Checkbox / Checkbox Group / Switch / Radio Group:** Click bubbling, validation, native form values, bundle size - **Combobox:** Filtering/highlight fixes; `expanded` for inline; disabled inheritance; separator; portalled content; bundle cleanup - **Composite:** Nested reorder, disabled nav skip, RTL scroll alignment - **Drawer:** Swipe/open, iOS scroll, Shadow DOM, snap points, bundle - **Field / Fieldset / Form:** Invalid-when-disabled, `data-dirty`, focus first invalid, bundle - **Menu:** Pinch-zoom, submenu hover/VO/TalkBack, disabled propagation, exit animation - **Meter / Progress / Toggle Group:** Formatting / min-max / bundle - **Navigation Menu:** Frozen menu on trigger unmount; pinch-zoom - **Number Field / OTP Field:** Format symbols; invalid autofocus when autoSubmit blocked - **Scroll Area:** Thumb drag, iOS visibility, overscroll feedback, snap while dragging - **Select:** Highlight/disabled/mount/separator fixes - **Slider / Tabs:** Assorted fixes; Suspense indicator; exclude prehydration from client bundles - **Toast:** Timer, swipe locking, re-add closing toast, `render` prop content, provider effect order --- ## Test plan - [x] Bump `@base-ui/react` to `^1.7.0` and refresh lockfile - [x] `pnpm --filter=frosted-ui exec tsc --project tsconfig-esm.json --noEmit` - [x] `pnpm --filter=frosted-ui build:js` (CJS + ESM) - [x] `pnpm --filter=frosted-ui lint` - [x] `pnpm --filter=frosted-ui test` (312 tests) - [ ] CI green on this PR - [ ] Spot-check Storybook surfaces that wrap Base UI heavily (Combobox, Select, Dialog, Menu, Toast, Accordion) if desired before merge <!-- CURSOR_AGENT_PR_BODY_END --> <div><a href="https://cursor.com/agents/bc-b799cb20-62b5-4aad-9033-e9e7a838d771?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/background-agent?bcId=bc-b799cb20-62b5-4aad-9033-e9e7a838d771&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div> Co-authored-by: Cursor Agent <[email protected]>
Fixes #5102
The third generic of
BaseUIComponentPropstypes therendercallback's props. It defaults toHTMLPropsso the callback can spread onto any element. Specializing it toComponentPropsWithRef<'tag'>exposes element-specific props (src,href,disabled, …) but blocks rendering as a different element. So we specialize only parts locked to one element, and keepHTMLPropsfor parts that can legitimately render as something else.Specialized
Avatar.Image<img>Form<form>NumberField.Input<input>OTPField.Input<input>PreviewCard.Trigger<a>Menu.LinkItem<a>NavigationMenu.Link<a>Toolbar.Link<a>Kept loose (
HTMLProps)Combobox.Input/Autocomplete.Input<textarea>Field.Control,Toolbar.Input<textarea>Field.LabelnativeLabel={false}supports<div>Fieldset.RootRadioGroup,CheckboxGroup, orSlider.RootSlider.Value<span>/<div>; shouldn't forcehtmlForNavigationMenu.List<ul>has no element-specific props*.ButtonpartsnativeButtonAlso
Combobox.Input/Autocomplete.Input: dropped the injectedtype="text"(native default already; was invalid when rendered as a<textarea>).*.spec.tsxchecks for the specialized callbacks.