Skip to content
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

Merged
merged 6 commits into from
May 12, 2017
Merged

fix #1290 switch support onClick #1293

merged 6 commits into from
May 12, 2017

Conversation

pingan1927
Copy link
Contributor

@pingan1927 pingan1927 commented May 10, 2017

First of all, thanks for your contribution! :-)

Please makes sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow antd's code convention.
  • Run npm run lint and fix those errors before submitting in order to keep consistent code style.
  • Rebase before creating a PR to keep commit history clear.
  • Add some descriptions and refer relative issues for you PR.

This change is Reviewable

@codecov
Copy link

codecov bot commented May 10, 2017

Codecov Report

Merging #1293 into master will decrease coverage by 0.07%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#rn 63.12% <ø> (ø) ⬆️
#web 60.35% <77.77%> (-0.15%) ⬇️
Impacted Files Coverage Δ
components/switch/index.web.tsx 62.06% <77.77%> (-16.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d369ecb...e38baa8. Read the comment docs.

@pingan1927 pingan1927 changed the title fix #1290 fix #1290 switch support onClick May 10, 2017
<div className="checkbox" />
<div
className={fackInputCls}
onClick={this.onChange}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没测试?这里写错了吧

Copy link
Contributor Author

@pingan1927 pingan1927 May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我再改改

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

肯定写错了啊... 应该是 onClick={this.onClick}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了

onClick = () => {
const { checked } = this.props;
if (this.props.onClick) {
this.props.onClick(checked);
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改 z-index 感觉很奇怪。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对应的写法

Copy link
Contributor Author

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 后一个元素不能被点击到

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input 的 z-index 也应该去掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那改动就大了去了,大的写法问题可以起个issue做一次重构

@@ -8,6 +8,7 @@ interface SwitchProps {
className?: string;
name?: string;
platform?: string;
onClick?: Function;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该补充参数。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClick的触发是在onChange之前,取的参数是change前的值,把参数去掉了,如果要加参数,就业务自己取比较好。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参数先都不要了,onClick先于onChange触发。参数自取

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pingan1927 没任何参数不行。至少把 event 对象给出来,不然看起来就是纯粹为了你眼前的需求去加这么一个 onClick,这不太好。

Copy link
Contributor Author

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

Copy link
Contributor

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一样描述一下出入参,作用

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果disabled,取的是switch组件传入的默认的checked。API已更新。

Copy link
Contributor Author

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

/>
<div
className={fackInputCls}
onClick={this.onChange}
{...(disabled ? { onClick: this.onClick } : {})}
Copy link
Member

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 关系不大。

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label加上onClick我试试看

Copy link
Contributor Author

@pingan1927 pingan1927 May 10, 2017

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影响,不可行

@@ -49,10 +48,11 @@ export default class Switch extends React.Component<SwitchProps, any> {
{...(disabled ? { disabled: 'disabled' } : {})}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个之前的代码也看的怪怪的,disabled={disabled} 不就行了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个晚点review下是否会有影响,这次先不改了。

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我知道你的意思 ,disabled的值可以传boolean,改了

@pingan1927 pingan1927 merged commit b3a75ff into master May 12, 2017
@paranoidjk paranoidjk deleted the enhance-switch branch May 15, 2017 07:59
lixiaoyang1992 pushed a commit to lixiaoyang1992/ant-design-mobile that referenced this pull request Apr 26, 2018
* fix ant-design#1290

* update

* fix bug

* fix

* update API doc

* update switch PropsType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants