Skip to content

feat: add function support for optionLabel and optionInfo#625

Open
lukasmatta wants to merge 5 commits into
masterfrom
387-not-possible-to-use-a-nested-property-for-optionlabeloptionvalueoptioninfo-in-cpsselect
Open

feat: add function support for optionLabel and optionInfo#625
lukasmatta wants to merge 5 commits into
masterfrom
387-not-possible-to-use-a-nested-property-for-optionlabeloptionvalueoptioninfo-in-cpsselect

Conversation

@lukasmatta
Copy link
Copy Markdown
Collaborator

@lukasmatta lukasmatta commented May 18, 2026

This pull request adds support for function-based option keys (optionLabel, optionValue, and optionInfo) to the cps-autocomplete, cps-select, cps-tree-autocomplete, and cps-tree-select components. This allows developers to specify a function to compute the display label, value, or info text for options, enabling more flexible and powerful customization (such as accessing nested properties or generating computed labels). The change is demonstrated through new examples and is thoroughly tested.

The most important changes are:

Core component enhancements:

  • Updated CpsAutocompleteComponent to accept a function or string for optionLabel, optionValue, and optionInfo, and to use a new utility function getOptionProp for property access throughout the component. This enables function-based option keys for labels, values, and info fields. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Updated templates for cps-autocomplete and cps-select to use getProp for rendering option labels and info, ensuring that function-based option keys are supported in the UI. [1] [2] [3] [4] [5] [6]

Documentation and examples:

  • Added new code examples to the demo pages (autocomplete-page, select-page, tree-autocomplete-page, tree-select-page) to showcase function-based option keys, including examples using nested properties and computed labels. [1] [2] [3] [4] [5] [6] [7] [8]

Testing:

  • Added comprehensive unit tests to CpsAutocompleteComponent to ensure correct behavior with function-based option keys, including rendering, filtering, selection, and chip display.

These changes make the UI components more flexible and developer-friendly, allowing for advanced use cases such as dynamic labels and values derived from complex or nested option data.

Release notes:

  • Add function support for optionLabel and optionInfo

…for-optionlabeloptionvalueoptioninfo-in-cpsselect
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

Coverage report for library

St.
Category Percentage Covered / Total
🔴 Statements 39.89% 2774/6954
🔴 Branches 32.95% 1118/3393
🔴 Functions 38.84% 527/1357
🔴 Lines 40.59% 2603/6413

Test suite run success

761 tests passing in 29 suites.

Report generated by 🧪jest coverage report action from 601b9c2

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

Playwright test results

passed  70 passed

Details

stats  70 tests across 4 suites
duration  2 minutes, 9 seconds
commit  601b9c2
info  For details, download the Playwright report

@lukasmatta lukasmatta changed the title Add support for functions for optionLabel and optionInfo with tests feat: add function support for optionLabel and optionInfo May 18, 2026
…for-optionlabeloptionvalueoptioninfo-in-cpsselect
@lukasmatta lukasmatta marked this pull request as ready for review May 19, 2026 20:35
Copilot AI review requested due to automatic review settings May 19, 2026 20:35
@lukasmatta lukasmatta requested a review from fateeand as a code owner May 19, 2026 20:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds function-based option key support to select, autocomplete, and tree dropdown components so labels, values, and info text can be derived from option objects.

Changes:

  • Introduces a shared OptionKey utility and uses it in internal pipes/components.
  • Updates select/autocomplete/tree dropdown rendering and selection logic to resolve string or function option keys.
  • Adds autocomplete tests and composition examples demonstrating function-based option labels.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
projects/cps-ui-kit/src/public-api.ts Exports the new option key type.
projects/cps-ui-kit/src/lib/utils/internal/option-utils.ts Adds shared option key resolution helper.
projects/cps-ui-kit/src/lib/pipes/internal/label-by-value.pipe.ts Supports function-based value/label keys.
projects/cps-ui-kit/src/lib/pipes/internal/combine-labels.pipe.ts Supports function-based keys for combined labels.
projects/cps-ui-kit/src/lib/pipes/internal/check-option-selected.pipe.ts Supports function-based option values.
projects/cps-ui-kit/src/lib/components/internal/cps-base-tree-dropdown/cps-base-tree-dropdown.component.ts Supports function-based tree labels/info.
projects/cps-ui-kit/src/lib/components/cps-select/cps-select.component.ts Resolves option values via string or function keys.
projects/cps-ui-kit/src/lib/components/cps-select/cps-select.component.html Renders select labels/info via the new helper.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.ts Resolves labels, values, filtering, and selection with function keys.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.spec.ts Adds tests for function-based autocomplete keys.
projects/cps-ui-kit/src/lib/components/cps-autocomplete/cps-autocomplete.component.html Renders autocomplete labels/info via the new helper.
projects/composition/src/app/pages/tree-select-page/tree-select-page.component.ts Adds demo label function.
projects/composition/src/app/pages/tree-select-page/tree-select-page.component.html Adds tree select example using function labels.
projects/composition/src/app/pages/tree-autocomplete-page/tree-autocomplete-page.component.ts Adds demo label function.
projects/composition/src/app/pages/tree-autocomplete-page/tree-autocomplete-page.component.html Adds tree autocomplete example using function labels.
projects/composition/src/app/pages/select-page/select-page.component.ts Adds demo nested code resolver.
projects/composition/src/app/pages/select-page/select-page.component.html Adds select example using function labels.
projects/composition/src/app/pages/autocomplete-page/autocomplete-page.examples.ts Adds code sample for function-based autocomplete labels.
projects/composition/src/app/pages/autocomplete-page/autocomplete-page.component.ts Adds demo nested code resolver.
projects/composition/src/app/pages/autocomplete-page/autocomplete-page.component.html Adds autocomplete example using function labels.

Comment on lines +1 to +3
export type OptionKey = string | ((option: any) => any);

export function getOptionProp(option: any, key: OptionKey): any {
Comment on lines +198 to +201
* Name of the label field of an option, or a function that receives the option and returns the label.
* @group Props
*/
@Input() optionLabel = 'label';
@Input() optionLabel: OptionKey = 'label';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants