nuxt / nuxt/ui

SelectMenu: Compound label

Open
#4,581 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
6.9k
Forks
1.1k
Avg merge
1d 7h
Merged PRs (30d)
57

Description

Description

For SelectMenu seems to be no option to customize the label of the selected item, e.g. use multiple values to compose the label. Currently only one item value can be selected by prop labelKey, but it is not possible to use multiple values OR to even add custom html-code.

Example:

const items = [
    {
        id: 1,
        firstName: 'Max',
        lastName: 'Mustermann',
    },
    ...
]

The items to select can be fully customized, even with custom html code:

<template #item-label="{ item }">
   {{ item.firstName }} <span class="text-highlighted">{{ item.lastName}}</span>
   <div class="text-xs text-muted">#{{ item.customerId }}</div>
</template>

But when an item is selected, the selected item can only be one value:

<USelectMenu label-key="lastName" />

Possible solutions:

  1. Make a new label prop that accepts a function, so values can be compound:
<USelectMenu :label="(item) => item.firstName + ' ' + item.lastName"
  1. Optionally make a slot to customize the labels:
<USelectMenu>
   <template #label="{ item }">
      {{ item.firstName }} <span class="text-highlighted">{{ item.lastName}}</span>
      <span class="text-xs text-muted">#{{ item.customerId }}</span>
   </template>
</USelectMenu>

P.S. the prop labelKey is not documented https://ui.nuxt.com/components/select-menu#props

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SelectMenu component and its documentation at ui.nuxt.com/components/select-menu, focusing on how labelKey and the item-label slot are currently exposed. Define and implement a way to compose or customize the selected item label, then update the props documentation so labelKey is documented and the completed behavior is shown with the provided item shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.