ant-design: Switch: cannot get event object while fire click/change event

Version

3.0.0-alpha0

Environment

Chrome 59.0.3071.115

Reproduction link

https://ant.design/components/switch-cn/

Steps to reproduce

【Background】 Use Switch in a clickable component; prevent parent component’s click event while fire Switch’s click event.

【Codes】

<Switch onChange={(checked) => {
      //TODO
     return false
}} onClick={(e) => {
    console.log(e)      //e输出为Boolean值:true/false,  value of checked
    e.preventDefault();   // Error
    e.stopPropagation();
}} />

【Problem】 Cannot get the event object when trigger click event in Switch Component

What is expected?

get click event object when fire click event

What is actually happening?

null

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

OK… I think it is an abused example of Transfer. But you can try this as workaround:

<Checkbox>
  Checkbox
  <span onClick={e => { e.preventDefault(); e.stopPropagation(); }}>
    <Switch size="small" />
  </span>
</Checkbox>