Dropdown: option keys fallback to values incorrectly
See original GitHub issueSteps
if we define our Dropdown
component like this:
const opts = [
{
key: 0,
value: 1,
text: 'Foo',
},
{
key: 1,
value: 2,
text: 'Bar',
},
]
const MyDropdown = () => <Dropdown selection options={opts} />
Note: this only happens with selection
prop true
, because only in that case, select
is rendered behind the scenes
Expected Result
This should render <select>
with two <option>
s with keys 0
and 1
Actual Result
This tries to render <select>
with two <option>
s with keys 1
and 1
because of { option.key || option.value }
(see this line of the code https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/Dropdown.js#L1074)
I think this line should be rewritten to only fallback to option.value
when option.key
is either undefined
or empty string. All other falsy values are valid keys, react converts them to strings.
Version
last
Testcase
https://codepen.io/notgiorgi/pen/ZKgBob?editors=0010 (you cannot use devtools on codepen)
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to implement a better fallback when a selected option in ...
I have a dropdown list called Reward. All the options in the dropdown list are populated from the info submitted by users elsewhere, ......
Read more >Dropdown: items missing "key" prop, React warning displayed
Keys in Dropdown options are still required and still work. If you do not pass a key we will use the value as...
Read more >Striking a Balance Between Native and Custom Select Elements
We're going to build a styled select element. Not just the outside, ... Clicking an option in the listbox updates the selected value....
Read more >Update enables SSL 3.0 fallback warnings in Internet Explorer ...
On the Edit menu, point to New, and then click DWORD Value. Type EnableSSL3Fallback, and then press the Enter key. In the Details...
Read more >Essentials - i18next documentation
Calling the t function with an array of keys enables you to translate dynamic keys providing a non specific fallback value. As a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One approach can be to write a helper function:
and then
Or we could do
and then
I can send a PR
Released in
semantic-ui-react@0.68.5
.