Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[Switch] preventDefault is ignored #23709
Comments
|
Below the [Switch API props table] you'll find
which means that you're not preventing the default behavior of the click event on However, it doesn't seem like you can do this at the moment. Passing |
|
Should we solve the issue like this? diff --git a/packages/material-ui/src/internal/SwitchBase.js b/packages/material-ui/src/internal/SwitchBase.js
index 3db2a57393..009679bf56 100644
--- a/packages/material-ui/src/internal/SwitchBase.js
+++ b/packages/material-ui/src/internal/SwitchBase.js
@@ -84,6 +84,10 @@ const SwitchBase = React.forwardRef(function SwitchBase(props, ref) {
};
const handleInputChange = (event) => {
+ if (event.nativeEvent.defaultPrevented) {
+ return;
+ }
+
const newChecked = event.target.checked;
setCheckedState(newChecked); |
|
Looks like a small change. If no one is working on it, then I can do it. This will be my first contribution. |
|
@satyadeeproat this sounds accurate. The objective is to reproduce the behavior of a native input checkbox. We will need to add a test case for it. |
|
Ok. let me do it. Will add a test case too. |
|
Now that I look at this issue without Material-UI: This looks like a React bug to me. We should still get this fix in but I'm also opening a React issue to get some clarification. Edit: Already reported: facebook/react#9023 |
Current Behavior😯
Using
preventDefaultdoes not prevent the Switch UI from updating.Expected Behavior🤔
Using
preventDefaultin theonClickhandler should stop the element from updating.Steps to Reproduce🕹
Steps:
preventDefaultinsideonClickContext🔦
Your Environment🌎