-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Disabled Button focus within Portal #23493
Comments
Why is this not an issue with React? |
@oliviertassinari Because it is Material UI problem, see updated demo with regular buttons: When parent has focus and you click on normal disabled button, nothing happens. When MUI |
Wrong analysis. Will keep you posted. |
I think that we can close, it's an edge case (i.e. negative ROI). It has to do with the nested |
Is there a workaround then? Because that way we can't use any MUI Button-based component at all. |
That's definitely odd behavior but since click-focus is not specified and up to the user-agent not very surprising. The inner span is on the chopping block for v5 anyway but we'll need to investigate it first. Alternatively we can work around it with pointerdown events. |
const Button = React.forwardRef(function Button(props, ref) {
const { onPointerDown = () => {}, disabled, ...other } = props;
function handlePointerDown(event) {
if (disabled) {
event.preventDefault();
}
onPointerDown(event);
}
return (
<MuiButton
ref={ref}
disabled={disabled}
onPointerDown={handlePointerDown}
{...other}
/>
);
}); -- https://codesandbox.io/s/material-ui-issue-forked-ybvw2?file=/src/Demo.js:141-535 |
@eps1lon Thanks, but this is solution just for |
Ok, just for reference, when any parent element of https://codesandbox.io/s/material-ui-issue-forked-mzj74?file=/src/Demo.js For time being we will use this workaround, it is probably most universal, even though still not entirely optimal. |
When is disabled
Button
placed within Portal, parent outside Portal does not receivefocus
properly.Current Behavior 😯
When you click on normally placed
Button
, parent receives focus correctly even when thatButton
is disabled. When you place thatButton
in portal, only enabledButton
do that.Expected Behavior 🤔
Events should work exactly the same in both cases, no matter if
Portal
is used.Steps to Reproduce 🕹
https://codesandbox.io/s/material-ui-issue-forked-eu17z?file=/src/Demo.js
Steps:
Button
inPortal
. Parent receives focus as well.Button
inPortal
. Parent does not receive or lose focus depending on previous state.Context 🔦
Focused state of parent affects display of some controls within its tree. When user clicks disabled
Button
, these controls are hidden even though they should be displayed.Your Environment 🌎
The text was updated successfully, but these errors were encountered: