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

feat(NcSelectTags): Disable internal v-model and options handling #3968

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/components/NcSelectTags/NcSelectTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ export default {
<NcSelect v-bind="propsToForward"
:options="availableOptions"
:close-on-select="!multiple"
:value="localValue"
:value="passthru ? value : localValue"
@search="searchString => search = searchString"
@input="handleInput"
v-on="{ ...$listeners, input: () => {} }">
<!-- Do not forward input event listener to NcSelect as we emit custom input events programmatically -->
v-on="{
...$listeners,
input: passthru ? $listeners.input : handleInput,
}">
<template #option="option">
<NcEllipsisedOption :name="getOptionLabel(option)"
:search="search" />
Expand Down Expand Up @@ -173,6 +174,16 @@ export default {
// Add NcSelect prop defaults and populate $props
...NcSelect.props,

/**
* Enable automatic fetching of tags
*
* If `false`, available tags must be passed using the `options` prop
*/
fetchTags: {
type: Boolean,
default: true,
},

/**
* Callback to generate the label text
*
Expand Down Expand Up @@ -224,6 +235,17 @@ export default {
default: null,
},

/**
* Enable passing of `value` prop and emitted `input` events as-is
* i.e. for usage with `v-model`
*
* If `true`, custom internal `value` and `input` handling is disabled
*/
passthru: {
type: Boolean,
default: false,
},

/**
* Placeholder text
*
Expand Down Expand Up @@ -264,7 +286,7 @@ export default {
data() {
return {
search: '',
tags: [],
availableTags: [],
}
},

Expand Down Expand Up @@ -292,19 +314,31 @@ export default {
propsToForward() {
const {
// Props handled by this component
fetchTags,
optionsFilter,
passthru,
// Props to forward
...propsToForward
} = this.$props

return propsToForward
},

tags() {
if (!this.fetchTags) {
return this.options
}
return this.availableTags
},
},

async beforeCreate() {
async created() {
if (!this.fetchTags) {
return
}
try {
const result = await searchTags()
this.tags = result
this.availableTags = result
} catch (error) {
console.error('Loading systemtags failed', error)
}
Expand Down