-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Display custom label in place of selected options #1036
Conversation
@sagalbot could this be reviewed please? 🙏 We're really looking forward to getting back to using the new versions of |
Is there a way to fix and merge this? Sorry for being pushy, I just hope this marvelops feature isn't forgotten. Also thank you for your time and effort on this lib @andreasvirkus @sagalbot |
ping @sagalbot |
I'm afraid that it will not be possible to deselect the selected options when the tags will not be rendered? (clicking on an option in the list does not deselect it now). Correct me if I'm wrong |
@adamdyderski I think the functionality you're looking for is in a different PR - #1033 This just adds the functionality to show a custom label, so it's only a visual change in that sense. It would greatly benefit from #1033 of course, but I've decoupled the features into 2 separate PRs |
@andreasvirkus this one will be next up after #1033 goes in. |
|
||
```js | ||
customFieldLabel: { | ||
type: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm torn on whether this should be a string or a function (or both). If it was a function, it could be called from a computed property, passing along the currently selected values. Something like this:
props: {
shouldTruncate: {
type: Boolean,
default: false
},
truncatedLabel: {
type: [String, Function],
}
},
computed: {
truncatedLabelResult() {
if( typeof this.truncatedLabel === 'function') {
return this.truncatedLabel(this.value)
}
return this.truncatedLabel;
}
}
You can easily make the string a computed property from the parent component, but people always seem to struggle with this. In my experience, I almost always wrap VueSelect
in a parent component to handle that sort of thing. In a perfect world, the component wouldn't manage any state - only firing events, it'd be up to the developer to track it themselves.
Either way, I think we do need some sort of shouldTruncate
flag that can be referenced from the template. That way you can truncate if more than X values are selected. Maybe it could be a slot? With a slot, we wouldn't need shouldTruncate
, we can just check if the slot has any content, and if it does, we use that content instead of iterating the options.
Let me know if you've got any thoughts on the above! Thanks for all your work on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like string gives us more control, since it's more strict & a function could return anything (e.g. what would we do with an array or an object?)
I don't have the statistics on what people struggle with though, so if it's a pain point that gets brought up often, having handling for both could be an option. 🤷
new Limit property added: |
This PR resolves #1003 with an additional prop, whose textual value would override the
vs__selected-options
contents.Maybe
collapseTags
would be a better name, seems that Element UI uses that as mentioned in #1003 (comment)An example use case for this new prop would be: