-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathshadow-root.ts
More file actions
39 lines (30 loc) · 1.22 KB
/
shadow-root.ts
File metadata and controls
39 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type ApplicationInstance from '@ember/application/instance';
import config from 'test-app/config/environment';
// @ts-expect-error Public property 'isFastBoot' of exported class
const isFastBoot = typeof FastBoot !== 'undefined';
export function initialize(appInstance: ApplicationInstance) {
if (config.environment !== 'test' || isFastBoot || !config.APP['shadowDom']) {
return;
}
let appRootElement = appInstance.rootElement as HTMLElement | null;
if (typeof appRootElement === 'string') {
appRootElement = document.querySelector(
appRootElement,
) as HTMLElement | null;
}
const targetElement =
appRootElement || document.getElementsByTagName('body')[0];
const hostElement = document.createElement('div');
hostElement.attachShadow({ mode: 'open' });
const rootElement = document.createElement('div');
const wormhole = document.createElement('div');
wormhole.id = 'ember-basic-dropdown-wormhole';
hostElement.shadowRoot?.appendChild(wormhole);
hostElement.shadowRoot?.appendChild(rootElement);
targetElement?.appendChild(hostElement);
config.APP['rootElement'] = '#ember-basic-dropdown-wormhole';
appInstance.set('rootElement', rootElement);
}
export default {
initialize,
};