-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Select element update #7054
Select element update #7054
Changes from 3 commits
021a6ca
cc7b610
87587e2
dc09140
0a6cf21
d092c52
dbd4851
bf9fe29
01c63d5
4c932a0
06aafde
f129956
1fd6935
c172e1c
03dc300
36524f3
0f38d16
1445899
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,28 @@ function warnIfValueIsNull(props) { | |
} | ||
} | ||
|
||
function warnIfDuplicateValues(inst) { | ||
const options = inst._currentElement.props.children; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is legal for this to be a composite component, so the children might not be simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They can also be nested inside arrays/maps/sets etc, so this does not work reliably. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also not to forget that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, |
||
|
||
if (options === undefined) { | ||
return; | ||
} | ||
|
||
// Displays a warning for all duplicate values in select element. Does not exit after first duplicate is found. | ||
for (var i = 0; i < options.length-1; i++) { | ||
if (options[i].props.value !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Children are not required to be only elements. This needs to check the type (also related to composite components as mentioned by @jimfb, shouldn't check the value of those). |
||
for (var j = i + 1; j < options.length; j++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (options[i].props.value === options[j].props.value) { | ||
warning( | ||
false, | ||
`Select element contains duplicate option value ${options[i].props.value} in options #${i} & #${j}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We try to include a stack trace for new warnings. Again, #7040 is a good example. |
||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var valuePropNames = ['value', 'defaultValue']; | ||
|
||
/** | ||
|
@@ -169,6 +191,7 @@ var ReactDOMSelect = { | |
if (__DEV__) { | ||
checkSelectPropTypes(inst, props); | ||
warnIfValueIsNull(props); | ||
warnIfDuplicateValues(inst); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate values is valid for uncontrolled components, so we probably shouldn't warn in that case? |
||
} | ||
|
||
var value = LinkedValueUtils.getValue(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.
We're trying to put new warnings within devtools. For an example that you can mimic, see: #7040
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.
Should I move it to ReactDOMNullInputValuePropDevtool.js or create a new file? If a new file, what should I name it? Thanks.
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.
You would create a new file for this warning. #7040 is just a reference for what it might look like. You can maybe name it something like
ReactDOMDuplicateSelectValuesDevtool.js
to be consistent with the current naming scheme.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.
I noticed
ReactDOMNullInputValuePropDevtool.js
exportsReactDOMUnknownPropertyDevtool
. Is that correct or a copy/paste error?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.
@git-richard looks like a copy/paste error to me, but @jimfb can verify.
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.
Yeah, just copy-paste.