Skip to content

Comments

[all components] Only define preventBaseUIHandler on event handlers typing that actually contain it#4089

Draft
flaviendelangle wants to merge 2 commits intomui:masterfrom
flaviendelangle:event-preventable
Draft

[all components] Only define preventBaseUIHandler on event handlers typing that actually contain it#4089
flaviendelangle wants to merge 2 commits intomui:masterfrom
flaviendelangle:event-preventable

Conversation

@flaviendelangle
Copy link
Member

Fixes #4088

I added support for event.preventBaseUIHandler() but we could also consider removing it from the types when it was not supported 👍

@flaviendelangle flaviendelangle self-assigned this Feb 13, 2026
@flaviendelangle flaviendelangle added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. component: accordion Changes related to the accordion component. labels Feb 13, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

commit: 073e8a0

@mui-bot
Copy link

mui-bot commented Feb 13, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 0B(0.00%)

Details of bundle changes


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

@aarongarciah
Copy link
Member

we could also consider removing it from the types when it was not supported

I think this would make more sense. It'd signals wether an event handler can be prevented (i.e. does something on the Base UI side) or not.

@netlify
Copy link

netlify bot commented Feb 13, 2026

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0314ef2
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698f573a9b168c00082cfc3c
😎 Deploy Preview https://deploy-preview-4089--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.

@flaviendelangle
Copy link
Member Author

flaviendelangle commented Feb 13, 2026

The tricky thing is that we have a single interface BaseUIComponentProps that applys the BaseUIEvent (which contains the faulty method) on ALL event handlers.

We could update the typing to reflect the truth but it would make the types a lot harder to maintain 😬

With that being said, it's broken on event handlers we do not define at all (like Accordion.Trigger onMouseDown) and we can't just define every single event handler...

For example:

image

Another solution is to make the callback nullable on all event handlers, but it's not pretty 😬

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 13, 2026
@flaviendelangle flaviendelangle force-pushed the event-preventable branch 3 times, most recently from edac27f to 490e263 Compare February 13, 2026 16:28
@flaviendelangle flaviendelangle changed the title [menu][accordion] Make all event handlers preventable [menu][accordion] Only define preventBaseUIHandler on event handlers typing that actually contain it Feb 13, 2026
@flaviendelangle flaviendelangle changed the title [menu][accordion] Only define preventBaseUIHandler on event handlers typing that actually contain it [all components] Only define preventBaseUIHandler on event handlers typing that actually contain it Feb 13, 2026
@flaviendelangle
Copy link
Member Author

I'm exploring hardcoding the preventable events on a few components to see what it would mean in practice.

@flaviendelangle flaviendelangle force-pushed the event-preventable branch 2 times, most recently from 92aff11 to 3737c79 Compare February 13, 2026 16:48
@flaviendelangle
Copy link
Member Author

I migrated a few components, but this feels super fragile.
TS can't catch anything if we forget to mark an event as preventable or if we mark an eventable as preventable by mistake.

@atomiks
Copy link
Contributor

atomiks commented Feb 14, 2026

Seems like this issue exists because only our internal props are marked with event.preventBaseUIHandler = () => {...}, instead of their props too (as in, the props unique to the JSX callsite)

It seems like if both sets of props are marked, then this issue would be fixed without needing to split types or define every handler upfront

It probably does have a non insignificant runtime cost in some cases though, in which case the type-level fix is better

@flaviendelangle
Copy link
Member Author

It seems like if both sets of props are marked, then this issue would be fixed without needing to split types or define every handler upfront

That's another approach indeed, way better than marking all the event handlers that could potentially exist 😆

I think we can discuss it on today's meeting 👍

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

Labels

component: accordion Changes related to the accordion component. component: menu Changes related to the menu component. PR: out-of-date The pull request has merge conflicts and can't be merged. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

event.preventBaseUIHandler is not a function

4 participants