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.

Click doesn't toggle switch, only dragging works

See original GitHub issue

I’m attaching a gif showing the behavior. When I click on the switch it doesn’t do anything at all. It can only be toggled by dragging it and even then the animation makes a jump. https://gfycat.com/VagueNeglectedBonobo

I’m using React 16.8.1 and react-switch 4.0.1 in a create-react-app project where I manually updated React. Here’s how I’m using the switch:

<Switch
          onChange={checked => console.log(checked)}
          width={112}
          height={45}
          onColor={colorPalette.primary}
          offColor={colorPalette.gray}
          offHandleColor={colorPalette.dark}
          handleDiameter={30}
          uncheckedIcon={false}
          checkedIcon={false}
          checked={isRunning}
          onColor="#2e91e9"
          id="normal-switch"
  />

What could be causing the behavior?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
oquirozmcommented, Feb 16, 2019

@markusenglund got it, solved it. I think we can close the issue.

@superzadeh I have no idea how you could work around this, sorry.

0reactions
superzadehcommented, Feb 20, 2019

Yeah, I ended up rolling my own component; slightly more limited in functionality but at least it works in the iframe.

A nice update for this project would be to allow passing a custom window/callback to get the window object;

import ReactDOM from "react-dom";
import React, { Component } from "react";
import Switch from "react-switch";
import Frame, { FrameContextConsumer } from "react-frame-component";

class SwitchExample extends Component {
  constructor() {
    super();
    this.state = { checked: false };
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(checked) {
    this.setState({ checked });
  }

  render() {
    return (
      <Frame>
        <FrameContextConsumer>
          {// Callback is invoked with iframe's window and document instances
          (frameContext) => {
            // Render Children
            return (
              <div>
                <p>Switch with default style</p>
                <Switch
                  window={frameContext.window}
                  onChange={this.handleChange}
                  checked={this.state.checked}
                />
              </div>
            );
          }}
        </FrameContextConsumer>
      </Frame>
    );
  }
}

ReactDOM.render(<SwitchExample />, document.getElementById("root"));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Paper-toggle-button not allowing drag · Issue #125 - GitHub
Click and drag the paper-toggle-button to its opposite state · Release the mouse · Click and drag the paper-toggle-button its opposite state ...
Read more >
Android Switch Button Drag off Click/Drag On - Stack Overflow
I extended off of the switch control and created an interface for objects that want to act upon certain drag events. Please see...
Read more >
How to Fix Mouse Right-click Button Not Working in Windows ...
How to fix the mouse right- click button not working on Windows 10 PC? Is your mouse right- click button not working ?...
Read more >
Turn On/Off Mouse Click Lock in Windows 10/8/7 [Tutorial]
Turn On/Off Mouse Click Lock in Windows 10/8/7 [Tutorial]Clicklock is the feature in Windows that allows you to use single- clicks to act...
Read more >
Right Click not holding in games - Steam Community
The answer: Logitech Mice do this as well. There's a trick to try and fix it: The toggle switch that operates the 'button'...
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