|
|
@@ -21,8 +21,6 @@ et sélectionner des éléments organisés en catégories et sous-catégories.
|
|
|
item-title="label"
|
|
|
item-value="value"
|
|
|
multiple
|
|
|
- chips
|
|
|
- closable-chips
|
|
|
:menu-props="{ maxHeight: 400 }"
|
|
|
@update:menu="onMenuUpdate"
|
|
|
@update:model-value="$emit('update:modelValue', $event)"
|
|
|
@@ -57,8 +55,7 @@ et sélectionner des éléments organisés en catégories et sous-catégories.
|
|
|
>
|
|
|
<!-- Always prioritize the mapping for consistent labels, fall back to item label if available -->
|
|
|
{{
|
|
|
- selectedItemsMap[item.raw.value] ||
|
|
|
- (item.raw.label && item.raw.label !== item.raw.value ? item.raw.label : item.raw.value)
|
|
|
+ selectedItemsMap[item.raw] || selectedItemsMap[item.raw.value]
|
|
|
}}
|
|
|
</v-chip>
|
|
|
<span
|
|
|
@@ -160,7 +157,7 @@ interface SelectItem {
|
|
|
id: string
|
|
|
label: string
|
|
|
normalizedLabel?: string
|
|
|
- value?: string
|
|
|
+ value?: number
|
|
|
type: 'category' | 'subcategory' | 'item'
|
|
|
parentId?: string
|
|
|
level: number
|
|
|
@@ -247,12 +244,42 @@ const expandedCategories: Ref<Set<string>> = ref(new Set())
|
|
|
const expandedSubcategories: Ref<Set<string>> = ref(new Set())
|
|
|
const searchText: Ref<string> = ref('')
|
|
|
|
|
|
+/**
|
|
|
+ * Expands all parent categories and subcategories of selected items.
|
|
|
+ */
|
|
|
+const expandParentsOfSelectedItems = () => {
|
|
|
+ expandedCategories.value.clear()
|
|
|
+ expandedSubcategories.value.clear()
|
|
|
+
|
|
|
+ for (const selectedId of props.modelValue) {
|
|
|
+ const item = normalizedItems.value.find(i => i.value === selectedId)
|
|
|
+ if (!item) continue
|
|
|
+
|
|
|
+ // Trouver la sous-catégorie
|
|
|
+ const subcategory = normalizedItems.value.find(i => i.id === item.parentId)
|
|
|
+ if (subcategory) {
|
|
|
+ expandedSubcategories.value.add(subcategory.id)
|
|
|
+
|
|
|
+ // Trouver la catégorie
|
|
|
+ if (subcategory.parentId) {
|
|
|
+ const category = normalizedItems.value.find(i => i.id === subcategory.parentId)
|
|
|
+ if (category) {
|
|
|
+ expandedCategories.value.add(category.id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* A callback function that is triggered when the menu's open state is updated.
|
|
|
*/
|
|
|
const onMenuUpdate = (isOpen: boolean) => {
|
|
|
+ if (isOpen) {
|
|
|
+ expandParentsOfSelectedItems()
|
|
|
+ }
|
|
|
// Réinitialiser la recherche quand le menu se ferme
|
|
|
- if (!isOpen && searchText.value) {
|
|
|
+ else if (!isOpen && searchText.value) {
|
|
|
searchText.value = ''
|
|
|
onSearchInput()
|
|
|
}
|