markusenglund / react-switch

A draggable toggle-switch component for React. Check out the demo at:
https://react-switch.netlify.com/
MIT License
1.33k stars 101 forks source link

Pass the attribute 'name' to the nested checkbox #37

Closed xiao-hu closed 5 years ago

xiao-hu commented 5 years ago

This allows the switch to be used more like a tradition checkbox (issue #36 ).

markusenglund commented 5 years ago

How exactly would you use the name attribute? In an uncontrolled form like this?

        <form>
          <Switch
            name="asdfqwer"
            checked={this.state.checked}
            onChange={this.handleChange}
          />
          <input type="submit" />
        </form>
xiao-hu commented 5 years ago

The idea is that I can submit the form in various ways, even something very old fashion like below. There is no need to restrict how it should be use.

        <form action='/submit'>
          <Switch
            name="asdfqwer"
            checked={this.state.checked}
            onChange={this.handleChange}
          />
          <input type="submit" />
        </form>

In my use case, I have a general form processor that does some thing to the form using the names of the inputs in the form, i.e., <form onSubmit=(generalFormProcessor)>. It would be very useful to me if <Switch/> should be viewed as some sort of <input/>.

markusenglund commented 5 years ago

Ok, seems reasonable. I'll try to release it soon.

markusenglund commented 5 years ago

Released in 4.1.0!