skip to Main Content

I am using the from Material UI. Everything works fine but when I add onChange event handler to control the value of the switch the sliding animation does not work anymore.

The switch ref: https://mui.com/material-ui/react-switch/#customization.

I couldn’t figure out how a change handler is preventing an animation. This is just normal sliding animation. I have tried to add transition to its parent element but nothing worked.

I have used @material-ui/core.

2

Answers


  1. Can you show us your code ?

    const MaterialUISwitch = styled(Switch)(({ theme }) => ({
    

    dis you change the props switch ?

    Login or Signup to reply.
  2. In order to control Switch state you need both checked and onChange props.

    Here is sandbox example of controlled IOS Switch.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search