AbsaOSS / cps-shared-ui

Angular shared components library
https://absaoss.github.io/cps-shared-ui/
Apache License 2.0
2 stars 2 forks source link

Not possible to use a nested property for optionLabel/optionValue/optionInfo in CpsSelect #387

Open lukasmatta opened 2 months ago

lukasmatta commented 2 months ago

Currently, if one wants to use nested property for optionLabel/optionValue/optionInfo it's not possible. Let me illustrate on an example:

We have an array of options of the following type:

interface Option {
  name: string;
  address: {
    city: string;
  };
}

And we want to use it in a CpsSelect:

<cps-select
  [options]="options"
  optionLabel="address.city" <!-- currently not possible -->
>
</cps-select>

I'd suggest supporting not only string type but also a Function type for those inputs, so that a user can define custom function that will take option object and would return value to be used for optionLabel/Value/Info, e.g.:

const getCity = (option: Option): string => option.address.city;
<cps-select
  [options]="options"
  optionLabel="getCity"
>
</cps-select>

Components that might also support this: CpsSelect/CpsTreeSelect CpsAutocomplete/CpsTreeAutocomplete