diff --git a/docs/components/checkbox.md b/docs/components/checkbox.md index 572294a..0f96eb1 100644 --- a/docs/components/checkbox.md +++ b/docs/components/checkbox.md @@ -213,7 +213,7 @@ const treeValue = ref() @@ -244,6 +244,15 @@ const treeValue = ref() + + + diff --git a/src/checkbox/utils.ts b/src/checkbox/utils.ts index 01f65b8..a4cbf9f 100644 --- a/src/checkbox/utils.ts +++ b/src/checkbox/utils.ts @@ -4,3 +4,4 @@ export type CheckboxValue = string | number export const multipleInjection: InjectionKey> = Symbol('RCheckboxGroup#multiple') export const modelInjection: InjectionKey> = Symbol('RCheckboxGroup#model') +export const labelsInjection: InjectionKey> = Symbol('RCheckbox#labels') diff --git a/src/select/index.vue b/src/select/index.vue index 2a2c1a0..f4ed339 100644 --- a/src/select/index.vue +++ b/src/select/index.vue @@ -2,9 +2,10 @@ import '../common/style.scss' import { vOnClickOutside } from '@vueuse/components' import type { RoughSVG } from 'roughjs/bin/svg' -import { toRef, watch, watchEffect } from 'vue' +import { provide, reactive, toRef, watch, watchEffect } from 'vue' import RCheckboxGroup from '../checkbox/checkbox-group.vue' import type { CheckboxValue } from '../checkbox/utils' +import { labelsInjection } from '../checkbox/utils' import { useReactionState } from '../common/utils' import RGraphics from '../graphics/index.vue' import type { GraphicsProps } from '../graphics/utils' @@ -57,8 +58,13 @@ watch($$(internalModelValue), currentValue => { emit('update:modelValue', currentValue) }) +const labels = reactive(new Map()) + const displayText = $computed(() => { - return Array.isArray(internalModelValue) ? internalModelValue.join(', ') : internalModelValue + const text = Array.isArray(internalModelValue) + ? internalModelValue.map(value => labels.get(value) ?? value) + : (internalModelValue !== undefined ? labels.get(internalModelValue) ?? internalModelValue : internalModelValue) + return Array.isArray(text) ? text.join(', ') : text }) let input = $ref() @@ -126,6 +132,8 @@ function drawDropdown(rc: RoughSVG, svg: SVGSVGElement) { }) svg.appendChild(rectangle) } + +provide(labelsInjection, labels)