Closed Weffe closed 6 years ago
On a second look, it seems that the instances are different. Here is the modified working example: https://codesandbox.io/s/zl19j92pwm
I took a look at the change you made and I'm wondering why does the value
of the DropDownList
need to come from the same array of data you are passing to the DropDownList
?. Why can't it just have the same shape of data?
I made a change to get the DropDownList
to render the text and have the correct value using the defaultItem
prop that can be used on DropDownList
. However, it ends up double rendering Animals
inside the list. The major changes are on ln 110
and ln 47
Also, @Xizario I recreated your working fix by using the provided filterBy
function from the data-query package and I'm still getting the same results as in the original codesandbox.
Here's the filterBy sandbox: https://codesandbox.io/s/vmko587135
@Weffe - We are currently working on improving this behavior and hopefully for the next version of Kendo UI for React
this workaround will not be needed.
About the defaultItem
, its purpose is to indicate that nothing is selected in the DropDownList.
I have checked the example using filterBy
and it looks like setting a function in the state twice does not work. Probably the second function overrides the first. Here is a modified example: https://codesandbox.io/s/506xmjy4q4
Thanks, @nstoychev for the workaround. In my own app, I was using filterBy
and would like to keep using it so I'll go with your solution to this issue. Hopefully, this does get fixed for the next version and will keep a lookout on it.
@Weffe , my first example could have been a bit confusing in the whole context. Changing this:
<DropDownList
data={categoryDropdownData}
value={selectedCategoryDropdownValue}
to:
<DropDownList
data={categoryDropdownData}
value={categoryDropdownData.find(c => c.id === selectedCategoryDropdownValue.id)}
Is a bit more generic for use. This is not a workaround, it is the official way.
In future there will be a property that you can set to determinate field by which the item will be compared. But the solution above will still work. So for example it would be possible to do something like:
<DropDownList
data={categoryDropdownData}
value={selectedCategoryDropdownValue}
someFutureProperty="id"
That pretty much saves a few characters, nothing more.
In general we don't have plans to do deep equality check of the objects, since could cause lot of performance problems when your store and data become more complex. Shallow comparison on the other hand is not an option, because it could lead to false positive selects. Selecting by exact object reference is both safe and easy for customization.
We have published version 2.0.0 and the new property dataItemKey can also be used to resolve the issue.
Release notes can be found here: https://www.telerik.com/kendo-react-ui/components/changelogs/ui-for-react/.
I'm submitting a...
Current behavior
Currently, the
DropDownList
fails to render thetextField
correctly when initially setting thevalue
of saidDropDownList
fromcomponentDidMount
. It does however correctly reflect the change ofvalue
from thecomponentDidMount
.Side note: The
data
is an array of objects that look likeExpected behavior
The
DropDownList
should render thetextField
properly when setting an initial value outside of theonChange
function. This would be a controlled DropDownList.Minimal reproduction of the problem with instructions
I have created a codesandbox demo perfectly recreating this bug. You can take a look at the console to see the current state. I have created the initial value to be the same as the first option in the dropdown list which is
Animals
.Codesandbox: https://codesandbox.io/s/5wm4rp6orp Codesandbox Standalone: https://5wm4rp6orp.codesandbox.io/
Steps to take:
componentDidMount
Animals
textField
correctly renders only after selecting the same valueWhat is the motivation or use case for changing the behavior?
The states between mounting and selecting the same option are exactly the same. However, what is not the same is the failure to render the
textField
even though the "different" states are exactly the same.Environment
Package versions:
Browser:
System: