Skip to content
20 changes: 20 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,26 @@ describe('defineCustomElement', () => {
container.appendChild(e)
expect(e.shadowRoot!.innerHTML).toBe('<div></div>')
})

// https://github.com/vuejs/core/issues/12964
// Disabled because of missing support for `delegatesFocus` in jsdom
// https://github.com/jsdom/jsdom/issues/3418
// eslint-disable-next-line vitest/no-disabled-tests
test.skip('shadowRoot should be initialized with delegatesFocus', () => {
const E = defineCustomElement(
{
render() {
return [h('input', { tabindex: 1 })]
},
},
{ shadowRootOptions: { delegatesFocus: true } },
)
customElements.define('my-el-with-delegate-focus', E)

const e = new E()
container.appendChild(e)
expect(e.shadowRoot!.delegatesFocus).toBe(true)
})
})

describe('emits', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type VueElementConstructor<P = {}> = {
export interface CustomElementOptions {
styles?: string[]
shadowRoot?: boolean
shadowRootOptions?: Omit<ShadowRootInit, 'mode'>
nonce?: string
configureApp?: (app: App) => void
}
Expand Down Expand Up @@ -263,7 +264,11 @@ export class VueElement
)
}
if (_def.shadowRoot !== false) {
this.attachShadow({ mode: 'open' })
this.attachShadow(
extend({}, _def.shadowRootOptions, {
mode: 'open',
}) as ShadowRootInit,
)
this._root = this.shadowRoot!
} else {
this._root = this
Expand Down
Loading