Repository navigation
feat(vue-vuetify): add MultiEnumSelectRenderer for multi-select dropdowns #2637
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
Merged
lucas-koehler
merged 30 commits into
eclipsesource:master
from
darius-lesch:feat/multi-enum-select-renderer
Oct 9, 2026
Merged
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9099496
feat(vue-vuetify): add MultiEnumSelectRenderer for multiselect rendering
darius-lesch b305067
Merge pull request #4 from darius-lesch/feature/multienum-select-rend…
darius-lesch 2f82463
feat: add multi-select example to the dev playground
darius-lesch 42b1b16
Resolved linting and harmonized imports
darius-lesch 7cecfd9
Merge pull request #5 from darius-lesch/feat-add-multi-select-example…
darius-lesch b36f863
Merge branch 'eclipsesource:master' into feat/multi-enum-select-renderer
darius-lesch f457e12
fix: resolved namespace error
darius-lesch 7ef53a0
feat(core, vue-vuetify): support atomic array updates for multi-enum …
darius-lesch c9ae9d2
refactor(vue-vuetify): extract shared predicate for multi-enum testers
darius-lesch 5ff28df
Merge pull request #11 from darius-lesch/refactor-extract-multi-enum-…
darius-lesch 0c76e8a
chore(examples): consolidate multi-select into enum-multi and clean s…
darius-lesch 5727bb4
Merge pull request #12 from darius-lesch/jules-113073129629200865-d6d…
darius-lesch e7a0171
fix: prettier formatting fix applied
darius-lesch 515e556
Merge pull request #10 from darius-lesch/feat-atomic-array-updates-mu…
darius-lesch ce95497
fix: removed leftover blank line
darius-lesch 3631b4f
refactor(vue-vuetify): utilize `adaptValue` in `MultiEnumSelectRenderer`
darius-lesch 1bf9f57
refactor(vue-vuetify): standardize `isMultiEnumControl` API
darius-lesch 3b13513
chore(core): DRY up mapDispatchToMultiEnumProps handleChange implemen…
darius-lesch 06c2b40
Merge pull request #14 from darius-lesch/standardize-is-multi-enum-co…
darius-lesch 77042c4
Merge pull request #13 from darius-lesch/refactor/vue-vuetify-multi-e…
darius-lesch 2fefc81
test(vue-vuetify): cover partial deselect for multiselect component
darius-lesch 84bd290
Merge pull request #15 from darius-lesch/fix-core-mapper-dry-up-94112…
darius-lesch 0b19ce7
Merge pull request #16 from darius-lesch/fix/vuetify-multi-select-des…
darius-lesch e3e1d5c
test(vue-vuetify): add interaction tests for oneOf schema in MultiEnu…
darius-lesch 26bf3ff
Merge pull request #18 from darius-lesch/test/vue-vuetify-multi-enum-…
darius-lesch 544047d
Merge pull request #17 from darius-lesch/fix/pr-2637-comments-v2
darius-lesch 7b26505
fix(vue-vuetify): update isMultiEnumControl tester to strictly requir…
darius-lesch b3f9f6d
fix: prettier fixes
darius-lesch 410cd79
Merge pull request #19 from darius-lesch/fix-multi-enum-tester-const-…
darius-lesch 5c9466b
remove unnecessary any cast
lucas-koehler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { registerExamples } from '../register'; | ||
|
|
||
| export const schema = { | ||
| type: 'object', | ||
| properties: { | ||
| fruits: { | ||
| type: 'array', | ||
| title: 'Select Fruits (Dropdown)', | ||
|
lucas-koehler marked this conversation as resolved.
Outdated
|
||
| uniqueItems: true, | ||
| items: { | ||
| type: 'string', | ||
| enum: ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'], | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const uischema = { | ||
| type: 'VerticalLayout', | ||
| elements: [ | ||
| { | ||
| type: 'Control', | ||
| scope: '#/properties/fruits', | ||
| options: { | ||
| format: 'multiselect', | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export const data = { | ||
| fruits: ['Banana', 'Cherry'], | ||
| }; | ||
|
|
||
| registerExamples([ | ||
| { | ||
| name: 'multi-select', | ||
| label: 'multi-select', | ||
| data, | ||
| schema, | ||
| uischema, | ||
| }, | ||
| ]); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/vue-vuetify/src/complex/MultiEnumSelectRenderer.entry.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { | ||
| and, | ||
| hasType, | ||
| optionIs, | ||
| rankWith, | ||
| schemaMatches, | ||
| schemaSubPathMatches, | ||
| uiTypeIs, | ||
| type JsonFormsRendererRegistryEntry, | ||
| type JsonSchema, | ||
| } from '@jsonforms/core'; | ||
| import controlRenderer from './MultiEnumSelectRenderer.vue'; | ||
|
|
||
| const hasOneOfItems = (schema: JsonSchema): boolean => | ||
| schema.oneOf !== undefined && | ||
| schema.oneOf.length > 0 && | ||
| (schema.oneOf as JsonSchema[]).every((entry: JsonSchema) => { | ||
| return entry.const !== undefined; | ||
| }); | ||
|
|
||
| const hasEnumItems = (schema: JsonSchema): boolean => | ||
| schema.type === 'string' && schema.enum !== undefined; | ||
|
|
||
| export const entry: JsonFormsRendererRegistryEntry = { | ||
| renderer: controlRenderer, | ||
| tester: rankWith( | ||
| 10, | ||
| and( | ||
| uiTypeIs('Control'), | ||
| optionIs('format', 'multiselect'), | ||
| and( | ||
| schemaMatches( | ||
| (schema) => | ||
| hasType(schema, 'array') && | ||
| !Array.isArray(schema.items) && | ||
| schema.uniqueItems === true, | ||
| ), | ||
| schemaSubPathMatches('items', (schema) => { | ||
| return hasOneOfItems(schema) || hasEnumItems(schema); | ||
| }), | ||
| ), | ||
| ), | ||
| ), | ||
|
lucas-koehler marked this conversation as resolved.
Outdated
|
||
| }; | ||
96 changes: 96 additions & 0 deletions
96
packages/vue-vuetify/src/complex/MultiEnumSelectRenderer.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <template> | ||
| <control-wrapper | ||
| v-bind="controlWrapper" | ||
| :styles="styles" | ||
| :isFocused="isFocused" | ||
| :appliedOptions="appliedOptions" | ||
| > | ||
| <v-select | ||
| v-disabled-icon-focus | ||
| :id="control.id + '-input'" | ||
| :class="styles.control.input" | ||
| :disabled="!control.enabled" | ||
| :readonly="control.readonly" | ||
| :autofocus="appliedOptions.focus" | ||
| :placeholder="appliedOptions.placeholder" | ||
| :label="computedLabel" | ||
| :hint="control.description" | ||
| :persistent-hint="persistentHint()" | ||
| :required="control.required" | ||
| :error-messages="control.errors" | ||
| :clearable="clearable" | ||
| :model-value="control.data" | ||
| :items="selectOptions" | ||
| item-title="label" | ||
| item-value="value" | ||
| multiple | ||
| chips | ||
| closable-chips | ||
| v-bind="vuetifyProps('v-select')" | ||
| @update:model-value="onChange" | ||
| @focus="handleFocus" | ||
| @blur="handleBlur" | ||
| > | ||
| <template v-slot:prepend v-if="$slots.prepend"> | ||
| <slot name="prepend" /> | ||
| </template> | ||
| <template v-slot:append v-if="$slots.append"> | ||
| <slot name="append" /> | ||
| </template> | ||
| </v-select> | ||
| </control-wrapper> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { type ControlElement } from '@jsonforms/core'; | ||
| import { | ||
| rendererProps, | ||
| useJsonFormsControl, | ||
| type RendererProps, | ||
| } from '@jsonforms/vue'; | ||
| import { defineComponent } from 'vue'; | ||
| import { VSelect } from 'vuetify/components'; | ||
| import { determineClearValue, useVuetifyControl } from '../util'; | ||
| import { default as ControlWrapper } from '../controls/ControlWrapper.vue'; | ||
| import { DisabledIconFocus } from '../controls/directives'; | ||
|
|
||
| const controlRenderer = defineComponent({ | ||
| name: 'multi-enum-select-renderer', | ||
| components: { | ||
| ControlWrapper, | ||
| VSelect, | ||
| }, | ||
| directives: { | ||
| DisabledIconFocus, | ||
| }, | ||
| props: { | ||
| ...rendererProps<ControlElement>(), | ||
| }, | ||
| setup(props: RendererProps<ControlElement>) { | ||
| const clearValue = determineClearValue([]); | ||
| return useVuetifyControl(useJsonFormsControl(props), (value) => | ||
| value === null ? clearValue : value || [], | ||
| ); | ||
| }, | ||
| computed: { | ||
| selectOptions() { | ||
| const itemsSchema = this.control.schema.items as any; | ||
| if (itemsSchema.oneOf) { | ||
| return itemsSchema.oneOf.map((item: any) => ({ | ||
| label: item.title || item.const, | ||
| value: item.const, | ||
| })); | ||
| } | ||
| if (itemsSchema.enum) { | ||
| return itemsSchema.enum.map((val: any) => ({ | ||
| label: val, | ||
| value: val, | ||
| })); | ||
| } | ||
| return []; | ||
| } | ||
|
lucas-koehler marked this conversation as resolved.
Outdated
|
||
| } | ||
|
lucas-koehler marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| export default controlRenderer; | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
packages/vue-vuetify/tests/unit/complex/MultiEnumSelectRenderer.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { describe, it, expect, beforeEach } from 'vitest'; | ||
| import { clearAllIds } from '@jsonforms/core'; | ||
| import MultiEnumSelectRenderer from '../../../src/complex/MultiEnumSelectRenderer.vue'; | ||
| import { entry as multiEnumSelectRendererEntry } from '../../../src/complex/MultiEnumSelectRenderer.entry'; | ||
| import { mountJsonForms } from '../util'; | ||
|
|
||
| describe('MultiEnumSelectRenderer.vue', () => { | ||
| const renderers = [multiEnumSelectRendererEntry]; | ||
|
|
||
| describe('with enum schema', () => { | ||
| const schema = { | ||
| type: 'array', | ||
| title: 'My Multi Select', | ||
| uniqueItems: true, | ||
| items: { | ||
| type: 'string', | ||
| enum: ['a', 'b', 'c'], | ||
| }, | ||
| }; | ||
| const uischema = { | ||
| type: 'Control', | ||
| scope: '#', | ||
| options: { | ||
| format: 'multiselect', | ||
| }, | ||
| }; | ||
|
|
||
| let wrapper: ReturnType<typeof mountJsonForms>; | ||
|
|
||
| beforeEach(() => { | ||
| clearAllIds(); | ||
| wrapper = mountJsonForms(['a'], schema, renderers, uischema); | ||
| }); | ||
|
|
||
| it('check if child MultiEnumSelectRenderer exists', () => { | ||
| expect(wrapper.getComponent(MultiEnumSelectRenderer)).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders a select input', () => { | ||
| expect(wrapper.find('input[type="text"]').exists()).toBe(true); | ||
| }); | ||
|
|
||
| it('renders title as label', () => { | ||
| expect(wrapper.find('label').text()).toEqual('My Multi Select'); | ||
| }); | ||
|
|
||
| it('emits change when an item is selected', async () => { | ||
| const select = wrapper.findComponent({ name: 'VSelect' }); | ||
| await select.vm.$emit('update:modelValue', ['a', 'b']); | ||
|
|
||
| const component = wrapper.getComponent(MultiEnumSelectRenderer); | ||
| expect(component.vm.control.data).toEqual(['a', 'b']); | ||
| }); | ||
|
|
||
| it('emits change when an item is deselected', async () => { | ||
|
lucas-koehler marked this conversation as resolved.
|
||
| const select = wrapper.findComponent({ name: 'VSelect' }); | ||
| await select.vm.$emit('update:modelValue', []); | ||
|
|
||
| const component = wrapper.getComponent(MultiEnumSelectRenderer); | ||
| expect(component.vm.control.data).toEqual([]); | ||
| }); | ||
|
|
||
| it('emits change when cleared', async () => { | ||
| const select = wrapper.findComponent({ name: 'VSelect' }); | ||
| await select.vm.$emit('update:modelValue', null); | ||
|
|
||
| const component = wrapper.getComponent(MultiEnumSelectRenderer); | ||
| // Because `determineClearValue([])` is used by jsonforms natively | ||
| // clearing sets the value to undefined to remove it from the data object cleanly | ||
|
lucas-koehler marked this conversation as resolved.
Outdated
|
||
| expect(component.vm.control.data).toEqual(undefined); | ||
| }); | ||
|
|
||
| it('should render component and match snapshot', () => { | ||
| expect(wrapper.html()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with oneOf schema', () => { | ||
| const schema = { | ||
| type: 'array', | ||
| title: 'My OneOf Multi Select', | ||
| uniqueItems: true, | ||
| items: { | ||
| oneOf: [ | ||
| { const: 'a', title: 'Option A' }, | ||
| { const: 'b', title: 'Option B' }, | ||
| { const: 'c', title: 'Option C' }, | ||
| ], | ||
| }, | ||
| }; | ||
| const uischema = { | ||
| type: 'Control', | ||
| scope: '#', | ||
| options: { | ||
| format: 'multiselect', | ||
| }, | ||
| }; | ||
|
|
||
| let wrapper: ReturnType<typeof mountJsonForms>; | ||
|
|
||
| beforeEach(() => { | ||
| clearAllIds(); | ||
| wrapper = mountJsonForms(['b'], schema, renderers, uischema); | ||
| }); | ||
|
|
||
| it('check if child MultiEnumSelectRenderer exists', () => { | ||
| expect(wrapper.getComponent(MultiEnumSelectRenderer)).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should render component and match snapshot', () => { | ||
| expect(wrapper.html()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.