-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SelectInput relying on synthetic events, is there a workaround? #18006
Comments
Yes but as you already said we're inside react which has its own synthetic event system. Could you explain why we shouldn't rely on reacts event system or what the specific issue is with the current approach? |
Using a different virutal dom library that doesn't use synthetic events (IE I 100% understand that it is not the goal of this library to consider those other use cases. I'm not suggesting that relying on the synthetic events is a problem at all -- that's probably the right way to work with react. I'm suggesting that this current way of solving "have the events of the dropdown div be sourced from the select" by swapping out the If this is a non-starter, that's fine we can close it up. In our project we just switched over to using react. It just strikes me as strange that the select seems to be the only component to handle the source redirect in this manor. |
I didn't know that, thanks 👍 . We try to be compatible with Could you add a repro that we can test against? A codesandbox would be ideal. |
👍 for considering |
Wow was not expecting the positive considerations! Thanks for the traction. Here's a codesandbox demoing it failing: I couldn't get JSX going with everything so I just wrote the small demo using preact's hyperscript method. I also added an input field to demo that other events work. You can see in the browser's console the errors with setting the event target:
Here's the issue I made over @ prect: preactjs/preact#2031 |
Before we explore a potential solution, I would like to raise that using preact and the non-native select implementation seems misaligned. Material-UI provides a NativeSelect component that has a significantly smaller bundle size footprint and is free from this problem. I expect the audience that resonates with Preact to prefer the NativeSelect component. That being said, if you still have a good reason for using the Select component, we would first need to avoid the read-only exception. Then, we need to think of a different API. I can think of two options. 1. In addition to target, we could use a new key, like @eps1lon I'm curious to hear your point of view as you often raise great original solutions. |
I think forms are very important and having a great integration story is more important than being able to support other targets. In general I'd like to make it more visible that I'd have to look at the current form library landscape and how integration works to make an educated guess. But then again if we do want to support preact seriously we might as well run the tests with it. |
I'm fairly certain it'd be possible to consume the event from the generated div dropdown and then emit the correct event from the select field. What are your thoughts on this? Inside most of React's codebase, it seems they go down the route of creating new events when they need to perform this kind of indirection. |
While you decide on a strategic solution how about you just force writing on the target field of the event using something like:
I know it's (kind of) a hack but it would give us using preact a quick workaround while leaving the semantic as it is... |
This specific issue was fixed in #18027. |
Unsure if this is considered a bug or what, and I'm not convinced it should be up to y'all to address it, but the select component is relying on react's synthetic events to do the event.target replacement for option blur:
#10534
#12467
Specifically:
https://github.com/mui-org/material-ui/blame/master/packages/material-ui/src/Select/SelectInput.js#L156-L160
https://github.com/mui-org/material-ui/blame/master/packages/material-ui/src/Select/SelectInput.js#L128-L130
Event.target is a read only property on the DOM's event model. Some possible alternatives to this would be:
I can also accept that none of that will happen and things like
preact
are just SOL with this particular widget.The text was updated successfully, but these errors were encountered: