Skip to content
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

[docs] Improve iOS style switch demo #25985

Closed
2 tasks done
aayushjainx opened this issue Apr 26, 2021 · 5 comments · Fixed by #26096
Closed
2 tasks done

[docs] Improve iOS style switch demo #25985

aayushjainx opened this issue Apr 26, 2021 · 5 comments · Fixed by #26096
Labels
docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. support: question Community support but can be turned into an improvement

Comments

@aayushjainx
Copy link

aayushjainx commented Apr 26, 2021

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When the iOS styled switch is set to disable and the switch is turned on, it still displays the green colour and does not look like it is disabled. But works fine when the switch is set to false.

Expected Behavior 🤔

It is expected to turn its colour to grey when it is disabled and the state is set to true like the rest of the switches and should look like a disabled switch.

Steps to Reproduce 🕹

Steps:

  1. Open the codesandbox
  2. Go to line number 141 and in the iOS switch add another attribute i.e. disabled.
  3. Save it and you could see that the iOS switch is still green coloured rather than turning into grey on disabled.

Context 🔦

iOS switch is used in many projects and is also used in disabled mode and do not provide a user-friendly experience when it still looks like enabled when it is disabled.

Your Environment 🌎

`npx @material-ui/envinfo`
 It was used in Google Chrome and Microsoft Edge.
  Output from `npx @material-ui/envinfo` goes here.
@aayushjainx aayushjainx added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 26, 2021
@mnajdova
Copy link
Member

The styles you are adding on line 45 have higher specificity, that is why they are winning. I'd suggest adding the ':not(.Mui-disabled)' selector there too, maybe something like https://codesandbox.io/s/material-demo-forked-khxl6?file=/demo.tsx

@mnajdova mnajdova added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 26, 2021
@aayushjainx
Copy link
Author

That's great but this was actually from the Material UI documentation. The bug is there.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 26, 2021

@aayushjain7 This demo is only meant for illustration purposes, it doesn't cover all the state subtleties.

@oliviertassinari oliviertassinari changed the title [Bug] iOS style switch - No color change on disabled. [docs] Improve iOS style switch demo Apr 26, 2021
@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Apr 26, 2021
@oliviertassinari
Copy link
Member

However, there is a bug in the nominal use case:

switch

I would propose this diff to match the iOS spec:

fixed

diff --git a/docs/src/pages/components/switches/CustomizedSwitches.tsx b/docs/src/pages/components/switches/CustomizedSwitches.tsx
index 9dd13b3265..e7becca025 100644
--- a/docs/src/pages/components/switches/CustomizedSwitches.tsx
+++ b/docs/src/pages/components/switches/CustomizedSwitches.tsx
@@ -14,31 +14,34 @@ const IOSSwitch = styled((props: SwitchProps) => (
   padding: 0,
   margin: theme.spacing(1),
   '& .MuiSwitch-switchBase': {
-    padding: 1,
+    padding: 0,
+    margin: 2,
+    transitionDuration: '300ms',
     '&.Mui-checked': {
       transform: 'translateX(16px)',
       color: theme.palette.common.white,
       '& + .MuiSwitch-track': {
-        backgroundColor: '#52d869',
+        backgroundColor: '#33cf4d',
         opacity: 1,
         border: 0,
       },
     },
     '&.Mui-focusVisible .MuiSwitch-thumb': {
-      color: '#52d869',
+      color: '#33cf4d',
       border: '6px solid #fff',
     },
   },
   '& .MuiSwitch-thumb': {
-    width: 24,
-    height: 24,
+    width: 22,
+    height: 22,
   },
   '& .MuiSwitch-track': {
     borderRadius: 26 / 2,
-    border: `1px solid ${theme.palette.grey[400]}`,
-    backgroundColor: theme.palette.grey[50],
+    backgroundColor: '#e4e3e6',
     opacity: 1,
-    transition: theme.transitions.create(['background-color', 'border-color']),
+    transition: theme.transitions.create(['background-color'], {
+      duration: 300,
+    }),
   },
 }));

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Apr 26, 2021
@aayushjainx
Copy link
Author

Great! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. support: question Community support but can be turned into an improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants