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

Selected item slot for Select component #223

Closed
ayZagen opened this issue Jun 21, 2021 · 7 comments
Closed

Selected item slot for Select component #223

ayZagen opened this issue Jun 21, 2021 · 7 comments
Labels
feature request New feature or request

Comments

@ayZagen
Copy link

ayZagen commented Jun 21, 2021

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>
@07akioni
Copy link
Collaborator

render-label actually passes selected as 2nd argument (not documented and will be documented).

Adding too much specify slot api is not a good pattern. Naive UI prefers slots for display-only slot such as header or something like that, but won't add too many render slots.

@ayZagen
Copy link
Author

ayZagen commented Jun 21, 2021

Excuse me but I could not understand how to customize selected item with render-label?
For ref:
image

@07akioni
Copy link
Collaborator

Excuse me but I could not understand how to customize selected item with render-label?
For ref:
image

You mean you want to customize tags (in select input)?

@07akioni 07akioni reopened this Jun 21, 2021
@07akioni 07akioni added the feature request New feature or request label Jun 21, 2021
@ayZagen
Copy link
Author

ayZagen commented Jun 21, 2021

I've digged into code all I need is to customize NInternalSelection.

Also you said Naive UI prefers slots for display-only slot and my usage example is also for display-only purposes. slots itself are meant to be display only purposes.

@07akioni
Copy link
Collaborator

07akioni commented 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.

@ayZagen
Copy link
Author

ayZagen commented 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.

@07akioni
Copy link
Collaborator

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.

vuejs/rfcs#192

@07akioni 07akioni closed this as completed Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants