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

[Feature Request] Using VSelect v-slot:selection-display to override the entire selection output #20769

Open
3dyuval opened this issue Dec 8, 2024 · 1 comment
Labels
C: VSelect VSelect T: feature A new feature

Comments

@3dyuval
Copy link

3dyuval commented Dec 8, 2024

Problem to solve

The v-slot:selection slot in VSelect is currently limited to customizing individual selected items. If we need to change how to display selection for the entire state, it's currently possible only using a workaround.
For instance: showing a single label when all items are selected. If we were to implement this feature in our current v-select:selection slot, we'd have to resort to:

<script setup>
import { ref, computed } from 'vue';

    const allItems = ['one', 'two'];
    const itemsSelected = ref(['one', 'two']);
    const allItemsSelected = computed(() => itemsSelected.value.length === allItems.length);

</script>
<template>
  <VSelect v-model="itemsSelected">
    <template #selection="{ item, index }">
      {{ 
        index > 1 && allItemsSelected 
          ? ''
          : index === 0 
          ? allItemsSelected 
            ? 'All items selected' 
            : item 
          : '' 
      }}
    </template>
  </VSelect>
</template>

Proposed solution

Enhance VSelect with a slot or prop for overriding the entire selection template. This would allow to easily define a custom template using v-slot:selection-display and use this to override the entire selection display, providing access to the full itemsSelected array.
Example:

<VSelect v-model="itemsSelected">
  <template #selection-display="{ itemsSelected }">
    {{ itemsSelected.length === allItems.length ? 'All items selected' : itemsSelected.join(', ') }}
  </template>
</VSelect>
@3dyuval 3dyuval changed the title [Feature Request] Using VSelect v-slot:selection to override the entire selection output instead of a single selection property [Feature Request] Using VSelect v-slot:selection-display to override the entire selection output instead of a single selection property Dec 8, 2024
@3dyuval 3dyuval changed the title [Feature Request] Using VSelect v-slot:selection-display to override the entire selection output instead of a single selection property [Feature Request] Using VSelect v-slot:selection-display to override the entire selection output Dec 8, 2024
@KaelWD
Copy link
Member

KaelWD commented Dec 17, 2024

Similar to #15014

@KaelWD KaelWD added T: feature A new feature C: VSelect VSelect labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VSelect VSelect T: feature A new feature
Projects
None yet
Development

No branches or pull requests

2 participants