Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item Label Generator for Combo Box #8333

Open
Artur- opened this issue Dec 12, 2024 · 1 comment
Open

Item Label Generator for Combo Box #8333

Artur- opened this issue Dec 12, 2024 · 1 comment
Labels
enhancement New feature or request vaadin-combo-box workaround There is a workaround in the comments.

Comments

@Artur-
Copy link
Member

Artur- commented Dec 12, 2024

Describe your motivation

It is quite common that you want to show something else in the combobox than exactly what is in the data object, aka format the label.

ComboBox has ${comboBoxRenderer(this.renderer, [])} you can use to render something else in the popup but that is for another use case - rendering something more complex in the dropdown.

The use case here is e.g. that the data object contains a Java class name and you want to render the simple name (name without package) in the combobox. Both in the dropdown and in the field. You want it to act like there would be a property in the data object containing the simple class name, but without actually creating that property

Describe the solution you'd like

Add an itemLabelGenerator which is reponsible for rendering the item label in all places and make the default implementation use itemLabelPath, i.e.

let label = item && this.itemLabelPath ? get(this.itemLabelPath, item) : undefined;
if (label === undefined || label === null) {
label = item ? item.toString() : '';
}
return label;

Describe alternatives you've considered

No response

Additional context

No response

@web-padawan web-padawan added enhancement New feature or request vaadin-combo-box labels Dec 12, 2024
@tomivirkki
Copy link
Member

Workaround:

<vaadin-combo-box
  .items=${items.map((item) => ({ ...item, shortName: createShortName(item) }))}
  item-label-path="shortName"
></vaadin-combo-box>

@yuriy-fix yuriy-fix added the workaround There is a workaround in the comments. label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vaadin-combo-box workaround There is a workaround in the comments.
Projects
None yet
Development

No branches or pull requests

4 participants