-
Notifications
You must be signed in to change notification settings - Fork 416
vue-vuetify: Enable overriding control-wrapper with custom component #2482
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 14 commits into
eclipsesource:master
from
kchobantonov:injectable-control-wrapper
Nov 10, 2025
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d7cb44d
allow control-wrapper to be overridden by provided component
kchobantonov 3c9cf53
fix list-with-detail example, the v-number-input doesn't handle incor…
kchobantonov 0e85ab1
use computed field to make sure that the selectedIndex is in range
kchobantonov ab9e82c
make props optional
kchobantonov a9d8096
enhance the custom wrapper for examples.
kchobantonov b67adf0
Update packages/vue-vuetify/src/controls/IntegerControlRenderer.vue
kchobantonov ba9beba
Update packages/vue-vuetify/src/controls/NumberControlRenderer.vue
kchobantonov 08e4dad
revert back the name of the control
kchobantonov 8fab8ae
Merge branch 'master' into injectable-control-wrapper
kchobantonov b216569
remove not needed method
kchobantonov e7c5485
organize imports
kchobantonov bf7af15
update type definition
kchobantonov 3dfbcd7
Merge branch 'master' into injectable-control-wrapper
kchobantonov 98a5210
Merge branch 'master' into injectable-control-wrapper
kchobantonov 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
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
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,68 @@ | ||
| <template> | ||
| <div | ||
| class="control-wrapper" | ||
| v-if="appStore.overrideControlTemplate && visible" | ||
| :class="[styles?.control.root, { 'focused-wrapper': isFocused }]" | ||
| :id="id" | ||
| > | ||
| <label :for="id">{{ label }} {{ required ? '(required)' : '' }}</label> | ||
| <template v-for="vnode in processedSlot"> | ||
| <component :is="vnode" /> | ||
| </template> | ||
| </div> | ||
|
|
||
| <default-control-wrapper v-else v-bind="props"> | ||
| <slot></slot> | ||
| </default-control-wrapper> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import DefaultControlWrapper from '@/controls/components/DefaultControlWrapper.vue'; | ||
| import type { ControlWrapperProps } from '@/util'; | ||
| import { cloneVNode, computed, defineProps, useSlots } from 'vue'; | ||
| import { useAppStore } from '../store'; | ||
| const appStore = useAppStore(); | ||
|
|
||
| const props = defineProps<ControlWrapperProps>(); | ||
| const slots = useSlots(); | ||
|
|
||
| /** | ||
| * Recursively clones a VNode and removes 'label' prop from Vuetify input components. | ||
| */ | ||
| function stripLabel(vnode: any) { | ||
| if (!vnode) return vnode; | ||
|
|
||
| const hasLabel = vnode.props && 'label' in vnode.props; | ||
| if (hasLabel) { | ||
| vnode = cloneVNode(vnode, { label: undefined }); | ||
| } | ||
|
|
||
| if (vnode.children && Array.isArray(vnode.children)) { | ||
| vnode.children = vnode.children.map(stripLabel); | ||
| } | ||
|
|
||
| return vnode; | ||
| } | ||
|
|
||
| const processedSlot = computed(() => { | ||
| if (!slots.default) return []; | ||
| return slots.default().map(stripLabel); | ||
| }); | ||
| </script> | ||
|
|
||
| <style scoped> | ||
| .control-wrapper { | ||
| position: relative; | ||
| padding: 8px; | ||
| transition: | ||
| background-color 0.2s ease, | ||
| box-shadow 0.2s ease; | ||
| border-radius: 6px; | ||
| } | ||
|
|
||
| /* Subtle focus effect */ | ||
| .focused-wrapper { | ||
| background-color: rgba(25, 118, 210, 0.05); /* soft glow */ | ||
| box-shadow: 0 0 8px rgba(25, 118, 210, 0.3); | ||
| } | ||
| </style> |
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
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
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
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 |
|---|---|---|
| @@ -1,29 +1,46 @@ | ||
| <template> | ||
| <div v-if="visible" :class="styles.control.root" :id="id"> | ||
| <slot></slot> | ||
| </div> | ||
| <component :is="WrapperComponent" v-bind="props"> | ||
| <slot /> | ||
| </component> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { defineComponent, type PropType } from 'vue'; | ||
| import type { Styles } from '../styles'; | ||
| import type { Styles } from '@/styles'; | ||
| import type { | ||
| AppliedOptions, | ||
| ControlWrapperProps, | ||
| ControlWrapperType, | ||
| } from '@/util'; | ||
| import { ControlWrapperSymbol } from '@/util'; | ||
| import { defineComponent, inject, type PropType } from 'vue'; | ||
| import DefaultControlWrapper from './components/DefaultControlWrapper.vue'; | ||
| export default defineComponent({ | ||
| name: 'control-wrapper', | ||
| name: 'ControlWrapper', | ||
| props: { | ||
| id: { | ||
| required: true as const, | ||
| type: String, | ||
| }, | ||
| visible: { | ||
| required: false as const, | ||
| type: Boolean, | ||
| default: true, | ||
| }, | ||
| styles: { | ||
| required: true, | ||
| type: Object as PropType<Styles>, | ||
| id: { type: String }, | ||
| description: { type: String }, | ||
| errors: { type: String }, | ||
| label: { type: String }, | ||
| visible: { type: Boolean }, | ||
| required: { type: Boolean }, | ||
| isFocused: { type: Boolean }, | ||
| styles: { type: Object as PropType<Styles> }, | ||
| appliedOptions: { | ||
| type: Object as PropType<AppliedOptions>, | ||
| }, | ||
| }, | ||
| setup(props: ControlWrapperProps) { | ||
| // Inject a custom wrapper if provided | ||
| const WrapperComponent = inject<ControlWrapperType>( | ||
| ControlWrapperSymbol, | ||
| DefaultControlWrapper, | ||
| ) as ControlWrapperType; | ||
| return { | ||
| WrapperComponent, | ||
| props, | ||
| }; | ||
| }, | ||
| }); | ||
| </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
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
28 changes: 28 additions & 0 deletions
28
packages/vue-vuetify/src/controls/components/DefaultControlWrapper.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,28 @@ | ||
| <template> | ||
| <div v-if="visible" :class="styles?.control.root" :id="id"> | ||
| <slot></slot> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import type { Styles } from '@/styles'; | ||
| import type { AppliedOptions, ControlWrapperProps } from '@/util'; | ||
| import { defineComponent, type DefineComponent, type PropType } from 'vue'; | ||
|
|
||
| export default defineComponent({ | ||
| name: 'default-control-wrapper', | ||
| props: { | ||
| id: { type: String }, | ||
| description: { type: String }, | ||
| errors: { type: String }, | ||
| label: { type: String }, | ||
| visible: { type: Boolean }, | ||
| required: { type: Boolean }, | ||
| isFocused: { type: Boolean }, | ||
| styles: { type: Object as PropType<Styles> }, | ||
| appliedOptions: { | ||
| type: Object as PropType<AppliedOptions>, | ||
| }, | ||
| }, | ||
| }) as DefineComponent<ControlWrapperProps>; | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { default as DefaultControlWrapper } from './DefaultControlWrapper.vue'; | ||
| export { default as ValidationBadge } from './ValidationBadge.vue'; | ||
| export { default as ValidationIcon } from './ValidationIcon.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 |
|---|---|---|
| @@ -1,5 +1,25 @@ | ||
| import type { InjectionKey } from 'vue'; | ||
| import type { DefineComponent, InjectionKey } from 'vue'; | ||
| import type { Styles } from '../styles'; | ||
| import type { useControlAppliedOptions } from './composition'; | ||
|
|
||
| export const IsDynamicPropertyContext: InjectionKey<boolean> = Symbol.for( | ||
| 'jsonforms-vue-vuetify:IsDynamicPropertyContext', | ||
| ); | ||
|
|
||
| export type AppliedOptions = ReturnType<typeof useControlAppliedOptions>; | ||
| export interface ControlWrapperProps { | ||
| id?: string; | ||
| description?: string; | ||
| errors?: string; | ||
| label?: string; | ||
| visible?: boolean; | ||
| required?: boolean; | ||
| isFocused?: boolean; | ||
| styles?: Styles; | ||
| appliedOptions?: AppliedOptions; | ||
| } | ||
|
|
||
| export type ControlWrapperType = DefineComponent<ControlWrapperProps>; | ||
|
|
||
| export const ControlWrapperSymbol: InjectionKey<ControlWrapperType> = | ||
| Symbol.for('jsonforms-vue-vuetify:ControlWrapper'); |
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
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.