Skip to content

Commit 60a88a2

Browse files
committed
feat(custom-element): support passing custom-element-specific options via 2nd argument of defineCustomElement
1 parent 56c76a8 commit 60a88a2

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

packages/runtime-dom/__tests__/customElement.spec.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -898,16 +898,20 @@ describe('defineCustomElement', () => {
898898
})
899899

900900
const toggle = ref(true)
901-
const ES = defineCustomElement({
902-
shadowRoot: false,
903-
render() {
904-
return [
905-
renderSlot(this.$slots, 'default'),
906-
toggle.value ? renderSlot(this.$slots, 'named') : null,
907-
renderSlot(this.$slots, 'omitted', {}, () => [h('div', 'fallback')]),
908-
]
901+
const ES = defineCustomElement(
902+
{
903+
render() {
904+
return [
905+
renderSlot(this.$slots, 'default'),
906+
toggle.value ? renderSlot(this.$slots, 'named') : null,
907+
renderSlot(this.$slots, 'omitted', {}, () => [
908+
h('div', 'fallback'),
909+
]),
910+
]
911+
},
909912
},
910-
})
913+
{ shadowRoot: false },
914+
)
911915
customElements.define('my-el-shadowroot-false-slots', ES)
912916

913917
test('should render slots', async () => {

packages/runtime-dom/src/apiCustomElement.ts

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export function defineCustomElement<
141141
Exposed
142142
>
143143
>,
144+
extraOptions?: CustomElementOptions,
144145
): VueElementConstructor<ResolvedProps>
145146

146147
// overload 3: defining a custom element from the returned value of
@@ -149,6 +150,7 @@ export function defineCustomElement<
149150
T extends DefineComponent<any, any, any, any>,
150151
>(
151152
options: T,
153+
extraOptions?: CustomElementOptions,
152154
): VueElementConstructor<
153155
T extends DefineComponent<infer P, any, any, any>
154156
? ExtractPropTypes<P>
@@ -165,6 +167,7 @@ export function defineCustomElement(
165167
hydrate?: RootHydrateFunction,
166168
): VueElementConstructor {
167169
const Comp = defineComponent(options, extraOptions) as any
170+
if (isPlainObject(Comp)) extend(Comp, extraOptions)
168171
class VueCustomElement extends VueElement {
169172
static def = Comp
170173
constructor(initialProps?: Record<string, any>) {

packages/runtime-dom/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export {
245245
useShadowRoot,
246246
VueElement,
247247
type VueElementConstructor,
248+
type CustomElementOptions,
248249
} from './apiCustomElement'
249250

250251
// SFC CSS utilities

0 commit comments

Comments
 (0)