-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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(factories): handle falsy key
values
#1729
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ import DropdownMenu from './DropdownMenu' | |
|
||
const debug = makeDebugger('dropdown') | ||
|
||
const getKeyOrValue = (key, value) => _.isNil(key) ? value : key | ||
|
||
/** | ||
* A dropdown allows a user to select a value from a series of options. | ||
* @see Form | ||
|
@@ -1072,7 +1074,7 @@ export default class Dropdown extends Component { | |
<select type='hidden' aria-hidden='true' name={name} value={value} multiple={multiple}> | ||
<option value='' /> | ||
{_.map(options, (option, i) => ( | ||
<option key={option.key || option.value} value={option.value}>{option.text}</option> | ||
<option key={getKeyOrValue(option.key, option.value)} value={option.value}>{option.text}</option> | ||
))} | ||
</select> | ||
) | ||
|
@@ -1137,7 +1139,7 @@ export default class Dropdown extends Component { | |
const defaultProps = { | ||
active: item.value === selectedLabel, | ||
as: 'a', | ||
key: item.key || item.value, | ||
key: getKeyOrValue(item.key, item.value), | ||
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. ^ |
||
onClick: this.handleLabelClick, | ||
onRemove: this.handleLabelRemove, | ||
value: item.value, | ||
|
@@ -1168,6 +1170,7 @@ export default class Dropdown extends Component { | |
onClick: this.handleItemClick, | ||
selected: selectedIndex === i, | ||
...opt, | ||
key: getKeyOrValue(opt.key, opt.value), | ||
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. ProblemBefore #1639, But, it's breaking change that I think should be reverted, because our users rely on 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. You are correct, however, this is a semver fail on my part. I should have incremented the minor (since we're pre 1.0). I do not think we should ship this feature moving forward. In If we feel very strongly about fixing this regression, I am willing to ship this as a patch right now to take care of current users as long as we immediately follow it up with a 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. Yes, I completely agree 👍 Let's ship this fix as |
||
// Needed for handling click events on disabled items | ||
style: { ...opt.style, pointerEvents: 'all' }, | ||
})) | ||
|
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.
As described in #1720,
0
will break the previous condition while it's a valid key.