-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
onChange callback will also pass option
param
#157
Conversation
RaoHai
commented
Jan 17, 2017
•
edited
Loading
edited
- close 建议 Select 选择器的 onChange 函数增加 option 参数方便回调 ant-design/ant-design#4597
- onChange(value, option: Option | Array)
* cherry-pick * remove useless files * remove useless files * Group ts * update interface * ReactElement
Changes Unknown when pulling 17a3bd3 on RaoHai:onChangeOption into ** on react-component:master**. |
c6953a1
to
c2fcfbb
Compare
Changes Unknown when pulling c2fcfbb on RaoHai:onChangeOption into ** on react-component:master**. |
Changes Unknown when pulling c2fcfbb on RaoHai:onChangeOption into ** on react-component:master**. |
@@ -89,7 +89,7 @@ React.render(c, container); | |||
|defaultValue | initial selected option(s) | String/Array<String> | - | | |||
|value | current selected option(s) | String/Array<String>/{key:String, label:React.Node}/Array<{key, label}> | - | | |||
|labelInValue| whether to embed label in value, see above value type | Bool | false | | |||
|onChange | called when select an option or input value change(combobox) | function(value) | - | | |||
|onChange | called when select an option or input value change(combobox) | function(value, option: Option | Array<Option>) | - | |
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.
这个 Option 是指 <Option />
还是 { key: '1', label: '1' }
?
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.
{ key: '1', label: '1' }
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 里说的应该是 <Option />
吧, 他需要获取 props。
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.
我看一下 onSelect。。。
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.
确实应该是 <Option />
Changes Unknown when pulling e76df9f on RaoHai:onChangeOption into ** on react-component:master**. |
改好了。
|
tests/Select.multiple.spec.js
Outdated
@@ -40,7 +40,7 @@ describe('Select.multiple', () => { | |||
value: 'One,Two,Three', | |||
} }); | |||
|
|||
expect(handleChange).toBeCalledWith(['1', '2']); | |||
expect(handleChange).toBeCalledWith(['1', '2'], [null, null]); |
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.
这里不能匹配到 Option 吗?
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.
这个例子有点怪。你自己试试,真实输入 One 是不会出来选项的,要输入 1 才行。但是 test 是通过的,
src/util.js
Outdated
@@ -135,3 +135,13 @@ export function splitBySeparators(string, separators) { | |||
} | |||
return array; | |||
} | |||
|
|||
export function findChildByKey(children, key) { |
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.
要考虑 OptGroup 的情况。
Changes Unknown when pulling b195636 on RaoHai:onChangeOption into ** on react-component:master**. |
b195636
to
9239519
Compare
ci failed...
|
CI 的 node 要换成 6+
…On Fri, 17 Feb 2017 at 18:21 陆离 ***@***.***> wrote:
ci failed...
rc-tools run guard
/home/travis/build/react-component/select/node_modules/rc-tools/lib/gulpfile.js:31
const { tsCompiledDir } = require('./constants');
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#157 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAcY5RYTeVlaJrMrX9C84HAxi0NuuD95ks5rdXSPgaJpZM4LlPfm>
.
|
rebase 下。 |
9239519
to
5bdc17c
Compare
为什么出现了两个我。。 |
@ @ 还能这样。。。。 |
你一定用了两个不同的 git user 设置。 |
只是换了一台电脑而已。。 |
两台电脑上的 |
哈哈,是 |
看东西重影。 |
export function findChildBy(optionLabelProp, children, key) { | ||
let child = null; | ||
React.Children.forEach(children, child_ => { | ||
if (child_.type === OptGroup) { |
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.
用 child_.type.isSelectOptGroup
判断。
React.Children.forEach(children, child_ => { | ||
if (child_.type === OptGroup) { | ||
child = child || findChildBy(optionLabelProp, child_.props.children, key); | ||
} else if (child_.type === Option && (child_.key === key || child_.props.value === key)) { |
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.
用 child_.type.isSelectOption
判断
@@ -38,7 +38,7 @@ describe('Select.combobox', () => { | |||
|
|||
wrapper.find('input').simulate('change', { target: { value: '1' } }); | |||
|
|||
expect(handleChange).toBeCalledWith('1'); | |||
expect(handleChange).toBeCalledWith('1', null); |
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.
没有 <Option />
的时候,第二个参数是 null
还是 undefined
?我看下面是 undefined
。
support in #264 |