Skip to content

Commit be80e79

Browse files
committed
feat(runtime-dom): allow specifying additional options for attachShadow
close 12964
1 parent 8bd9cdb commit be80e79

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,23 @@ describe('defineCustomElement', () => {
471471
container.appendChild(e)
472472
expect(e.shadowRoot!.innerHTML).toBe('<div></div>')
473473
})
474+
475+
// https://github.com/vuejs/core/issues/12964
476+
// Disabled because of missing support for `delegatesFocus` in jsdom
477+
// https://github.com/jsdom/jsdom/issues/3418
478+
// eslint-disable-next-line vitest/no-disabled-tests
479+
test.skip('shadowRoot should be initialized with delegatesFocus', () => {
480+
const E = defineCustomElement({
481+
render() {
482+
return [h('input', { tabindex: 1 })]
483+
},
484+
}, { shadowRootOptions: { delegatesFocus: true } })
485+
customElements.define('my-el-with-delegate-focus', E)
486+
487+
const e = new E()
488+
container.appendChild(e)
489+
expect(e.shadowRoot!.delegatesFocus).toBe(true)
490+
})
474491
})
475492

476493
describe('emits', () => {

packages/runtime-dom/src/apiCustomElement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export type VueElementConstructor<P = {}> = {
5353
export interface CustomElementOptions {
5454
styles?: string[]
5555
shadowRoot?: boolean
56+
shadowRootOptions?: ShadowRootInit
5657
nonce?: string
5758
configureApp?: (app: App) => void
5859
}
@@ -263,7 +264,7 @@ export class VueElement
263264
)
264265
}
265266
if (_def.shadowRoot !== false) {
266-
this.attachShadow({ mode: 'open' })
267+
this.attachShadow(extend({ mode: 'open' }, _def.shadowRootOptions))
267268
this._root = this.shadowRoot!
268269
} else {
269270
this._root = this

0 commit comments

Comments
 (0)