siemens / ix

Siemens Industrial Experience is a design system for designers and developers, to consistently create the perfect digital experience for industrial software products.
https://ix.siemens.io/
MIT License
197 stars 65 forks source link

Select component datakey for comparisons #821

Closed JulianEvi closed 1 month ago

JulianEvi commented 11 months ago

What happened?

The select component seems to compare objects by reference, which is a problem if the value in the form control does not come from the collection that supplies the select. Other frameworks like Prime NG offer a "dataKey" property in order to prevent a deep compare, which enables the user to define the key used in such comparisons.

Due to this, the select field does not show an initial value if the form value came from a different backend call. Performing a mapping for every form control value that is used in a select is an overhead and can require additional refactoring in large existing applications. I solved it by wrapping the select component in another ControlValueAccessor, which handles the mapping.

What type of frontend frameware are you seeing the problem on?

Angular

Which version of iX do you use?

2.0.1

Code to produce this issue.

// product contains an object which is deep compared equal to one of the marketProducts, but has a different reference

<ix-select formControlName="product">
 <ix-select-item *ngFor="let item of marketProducts" label="{{ item.name }}" [value]="item">
 </ix-select-item>
</ix-select>
danielleroux commented 8 months ago

Sounds valid can you please provide a link to the mantioned prime ng component which has this dataKey? Or your value accessor ?

JulianEvi commented 7 months ago

https://primeng.org/dropdown https://primeng.org/table

Those two components have the dataKey property.

matthiashader commented 7 months ago

Internal ref [IX-891]

matthiashader commented 1 month ago

See answer, regarding on value comparison here: https://github.com/siemens/ix/issues/1270#issuecomment-2151696893