mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
fix(): overlays now present correctly when using custom elements build (#23039)
resolves #23029
This commit is contained in:
@ -5,11 +5,23 @@ import { Side } from '../interface';
|
||||
declare const __zone_symbol__requestAnimationFrame: any;
|
||||
declare const requestAnimationFrame: any;
|
||||
|
||||
/**
|
||||
* Waits for a component to be ready for
|
||||
* both custom element and non-custom element builds.
|
||||
* If non-custom element build, el.componentOnReady
|
||||
* will be used.
|
||||
* For custom element builds, we wait a frame
|
||||
* so that the inner contents of the component
|
||||
* have a chance to render.
|
||||
*
|
||||
* Use this utility rather than calling
|
||||
* el.componentOnReady yourself.
|
||||
*/
|
||||
export const componentOnReady = (el: any, callback: any) => {
|
||||
if (el.componentOnReady) {
|
||||
el.componentOnReady().then(callback);
|
||||
el.componentOnReady().then((resolvedEl: any) => callback(resolvedEl));
|
||||
} else {
|
||||
callback();
|
||||
raf(() => callback(el));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
42
core/src/utils/test/ready.spec.ts
Normal file
42
core/src/utils/test/ready.spec.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { componentOnReady } from '../helpers';
|
||||
|
||||
describe('componentOnReady()', () => {
|
||||
it('should correctly call callback for a custom element', (done) => {
|
||||
customElements.define('hello-world', class extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
});
|
||||
|
||||
const component = document.createElement('hello-world');
|
||||
componentOnReady(component, (el) => {
|
||||
expect(el).toBe(component);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it('should correctly call callback for a lazy loaded component', (done) => {
|
||||
const cb = jest.fn((el) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => resolve(el), 250);
|
||||
});
|
||||
});
|
||||
|
||||
customElements.define('hello-world', class extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
componentOnReady() {
|
||||
return cb(this);
|
||||
}
|
||||
});
|
||||
|
||||
const component = document.createElement('hello-world');
|
||||
componentOnReady(component, (el) => {
|
||||
expect(el).toBe(component);
|
||||
expect(cb).toHaveBeenCalledTimes(1);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user