question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selected item slot for Select component

See original GitHub issue

This function solves the problem

It would be great to have selected-item(or any other name) slot to improve customization of selected value.

Expected API

Also instead of render-label property, it would be great to have scoped slot as I think it is more suitable for Vue. Having prop to customize render is kind of React thing.

<template>
<n-select :options="options" >
  <template #selected-item="{ item }">
    {{item.label}} - {{item.value}} 
  </template>
  <template #option="{ item }">
    This is {{item.label}}
  </template>
</n-select>
</template>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
07akionicommented, Jun 21, 2021

I don’t think the API is gonna change as vue is in stable release now, though it was discussed a lot in RFCs. As a consumer it would be great to have more slot oriented customization. Please consider using slots more.

Anyway, thank you for your work naive-ui is really great framework, I liked it a lot so far.

Thanks! I know many people perfer slot API (if it is typed, I would too). However now the typed slot rfc is still pending (the same for generic types), I think it’s risky to implement it before the rfc is merged. If there’re some changes, it will cost a lot to change all the related codes.

https://github.com/vuejs/rfcs/pull/192

1reaction
07akionicommented, Jun 21, 2021

and my usage example is also for display-only purposes. slots itself are meant to be display only purposes.

I mean it doesn’t mix too much logic (with complex slot props) in it. Since Vue doesn’t has good typescript support for slots. I think it is dangerous to rely too much on slots now (nor API and implementation may break a lot if vue change its API).

However the feature will be provided (not by slot api). It’s necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selected-item slot - Quasar Playground - CodePen
https://quasar.dev/vue-components/select#Example--Selected-item-slot. 4. -->. 5. <div id="q-app">. 6. <div class="q-pa-md" style="max-width: 300px">.
Read more >
Get value of clicked item in Vuetify multiple select component
So essentially all the items are selected when the component is mounted. Once the user clicks on an item from the list, I...
Read more >
Select component — Vuetify
The selection slot can be used to customize the way selected values are shown in the input. This is great when you want...
Read more >
Selected Item Slot help - Redstone Discussion and Mechanisms
I wanted to testfor if the player has the selected item slot 1-9, and if the player is holding a map with a...
Read more >
[docs] q-select with v-slot:selected-item #4739 - GitHub
In that case, you have to add option-value="id" or something similar to your q-select , so that internal :key="opt.value" binding works ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found