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

优化对 value 为空的判断 #135

Closed
wants to merge 2 commits into from
Closed

优化对 value 为空的判断 #135

wants to merge 2 commits into from

Conversation

ystarlongzi
Copy link

当组件传入value的值默认为null或空字符串时,是否也可以认定为value并没有设置值,即为undefined

在项目中有碰到这样的场景,组件包含allowClear属性,然后value的初始值为null,而不是undefined,此时鼠标滑过时,会显示清除按钮(当然将value初始值设置为undefined完全可以避免这种情况)。

http://codepen.io/ystarlongzi/pen/xRVNVe

当组件传入`value`的值默认为`null`或空字符串时,是否也可以认定为`value`并没有设置值,即为`undefined`?

在项目中有碰到这样的场景,组件包含`allowClear`属性,然后`value`的初始值为`null`,而不是`undefined`,此时鼠标滑过时,会显示清除按钮(当然将`value`初始值设置为`undefined`完全可以避免这种情况)。

http://codepen.io/ystarlongzi/pen/xRVNVe
@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.718% when pulling 00032aa on ystarlongzi:patch-1 into 3ada48a on react-component:master.

将双等号判断修改为全等好判断
@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.718% when pulling b214f89 on ystarlongzi:patch-1 into 3ada48a on react-component:master.

@yiminghe
Copy link
Member

除了 undefined,其他都是有效值

@yiminghe yiminghe closed this Nov 25, 2016
@benjycui benjycui mentioned this pull request Nov 26, 2016
@ystarlongzi
Copy link
Author

@yiminghe

今天又想了下,认为空字符串是有效值,是可以理解的,因为确实有存在选项为空的场景,如下:

<Select value={""}>
    <Option value="">全选</Option>
    <Option value="1">未付款</Option>
    <Option value="2">已付款</Option>
    <Option value="3">待发货</Option>
</Select>

但是,认为null是有效值,感觉还是不大合理。不知你是如何理解值为null这种场景的?

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