question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[docs] Improve iOS style switch demo

See original GitHub issue
  • 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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Apr 26, 2021

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,
+    }),
   },
 }));
0reactions
aayushjain7commented, Apr 27, 2021

Great! 💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

UISwitch | Apple Developer Documentation
Present a switch control as a Mac-style checkbox when your app runs in the Mac user interface idiom ... The title displayed next...
Read more >
Flutter for iOS developers
Learn how to apply iOS developer knowledge when building Flutter apps. ... How is react-style, or declarative, programming different from the traditional ...
Read more >
Switch - NativeScript Docs
The Switch component represents control, which can have two states('true', 'false'). The user can toggle the components value. The modules allow setting and ......
Read more >
switch - JavaScript - MDN Web Docs - Mozilla
The default clause of a switch statement will be jumped to if no case matches the ... JavaScript Demo: Statement - Switch ......
Read more >
Cloud-based maps styling | Maps Customization Guide
Android; iOS; JavaScript; Try Sample; Maps Static API ... Google Maps Platform offers Cloud-based maps styling features that make it easy to style, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found