|
13 | 13 | import Tagify from '@yaireo/tagify' |
14 | 14 | import '@yaireo/tagify/dist/tagify.css' |
15 | 15 |
|
16 | | -const props = withDefaults(defineProps<{ |
17 | | - type?: string |
18 | | - settings?: Tagify.TagifySettings |
19 | | - value?: Tagify.TagData[] |
20 | | - delimiters?: string |
21 | | - whitelist?: Tagify.TagData[] |
22 | | - tagClass?: string |
23 | | -}>(), { |
24 | | - type: 'input', |
25 | | - settings: () => ({}), |
26 | | - value: () => [], |
27 | | - delimiters: ',', |
28 | | - whitelist: () => [], |
29 | | - tagClass: '', |
30 | | -}) |
| 16 | +const props = withDefaults( |
| 17 | + defineProps<{ |
| 18 | + type?: string |
| 19 | + settings?: Tagify.TagifySettings |
| 20 | + value?: Tagify.TagData[] |
| 21 | + delimiters?: string |
| 22 | + whitelist?: Tagify.TagData[] |
| 23 | + tagClass?: string |
| 24 | + }>(), |
| 25 | + { |
| 26 | + type: 'input', |
| 27 | + settings: () => ({}), |
| 28 | + value: () => [], |
| 29 | + delimiters: ',', |
| 30 | + whitelist: () => [], |
| 31 | + tagClass: '', |
| 32 | + }, |
| 33 | +) |
31 | 34 |
|
32 | 35 | const emit = defineEmits<{ |
33 | 36 | input: [value: string | Tagify.TagData[]] |
34 | 37 | }>() |
35 | 38 |
|
36 | 39 | const tagify = ref<Tagify | null>(null) |
37 | 40 |
|
38 | | -watch(() => props.value, (newVal) => { |
39 | | - // Value modified externally, update tagify |
40 | | - if (newVal) { |
41 | | - tagify.value?.loadOriginalValues(newVal as unknown as string | string[]) |
42 | | - } |
43 | | -}) |
| 41 | +watch( |
| 42 | + () => props.value, |
| 43 | + (newVal) => { |
| 44 | + // Value modified externally, update tagify |
| 45 | + if (newVal) { |
| 46 | + // @ts-expect-error: problem in tagify types |
| 47 | + tagify.value?.loadOriginalValues(newVal) |
| 48 | + } |
| 49 | + }, |
| 50 | +) |
44 | 51 |
|
45 | 52 | onMounted(() => { |
46 | 53 | // Install tagify |
@@ -73,10 +80,7 @@ onUnmounted(() => { |
73 | 80 |
|
74 | 81 | function onChange(event: { target: EventTarget | null }) { |
75 | 82 | // Update value prop |
76 | | - emit( |
77 | | - 'input', |
78 | | - (event.target as HTMLInputElement | null)?.value ?? [], |
79 | | - ) |
| 83 | + emit('input', (event.target as HTMLInputElement | null)?.value ?? []) |
80 | 84 | } |
81 | 85 | </script> |
82 | 86 |
|
|
0 commit comments