This commit is contained in:
Matthias Hryniszak 2025-06-26 06:57:33 -04:00 committed by GitHub
commit 5402aae5a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -501,6 +501,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', () => {

View File

@ -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
}
@ -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