diff --git a/core/src/utils/overlays.ts b/core/src/utils/overlays.ts index 925fa8bf1b8..13b83b913e7 100644 --- a/core/src/utils/overlays.ts +++ b/core/src/utils/overlays.ts @@ -2,6 +2,7 @@ import { ActionSheet } from '../components/action-sheet/action-sheet'; import { Alert } from '../components/alert/alert'; import { Loading } from '../components/loading/loading'; import { Modal } from '../components/modal/modal'; +import { PickerColumnCmp } from '../components/picker-column/picker-column'; import { Picker } from '../components/picker/picker'; import { Popover } from '../components/popover/popover'; import { Toast } from '../components/toast/toast'; @@ -16,10 +17,15 @@ let lastId = 0; export const activeAnimations = new WeakMap(); -const createController = (tagName: string, customElement?: any) => { +type ChildCustomElementDefinition = { + tagName: string; + customElement: any; +} + +const createController = (tagName: string, customElement?: any, childrenCustomElements?: ChildCustomElementDefinition[]) => { return { create(options: Opts): Promise { - return createOverlay(tagName, options, customElement) as any; + return createOverlay(tagName, options, customElement, childrenCustomElements) as any; }, dismiss(data?: any, role?: string, id?: string) { return dismissOverlay(document, data, role, tagName, id); @@ -34,7 +40,7 @@ export const alertController = /*@__PURE__*/createController('ion-action-sheet', ActionSheet); export const loadingController = /*@__PURE__*/createController('ion-loading', Loading); export const modalController = /*@__PURE__*/createController('ion-modal', Modal); -export const pickerController = /*@__PURE__*/createController('ion-picker', Picker); +export const pickerController = /*@__PURE__*/createController('ion-picker', Picker, [{ tagName: 'ion-picker-column', customElement: PickerColumnCmp }]); export const popoverController = /*@__PURE__*/createController('ion-popover', Popover); export const toastController = /*@__PURE__*/createController('ion-toast', Toast); @@ -50,15 +56,24 @@ export const prepareOverlay = (el: T) => { } }; -export const createOverlay = (tagName: string, opts: object | undefined, customElement?: any): Promise => { +export const createOverlay = (tagName: string, opts: object | undefined, customElement?: any, childrenCustomElements?: ChildCustomElementDefinition[]): Promise => { /* tslint:disable-next-line */ if (typeof window.customElements !== 'undefined') { - if ( - typeof (window as any) !== 'undefined' && - window.customElements && - !window.customElements.get(tagName) - ) { - window.customElements.define(tagName, customElement); + if (typeof (window as any) !== 'undefined' && window.customElements) { + if (!window.customElements.get(tagName)) { + window.customElements.define(tagName, customElement); + } + /** + * If the parent element has nested usage of custom elements, + * we need to manually define those custom elements. + */ + if (childrenCustomElements) { + for (const customElementDefinition of childrenCustomElements) { + if (!window.customElements.get(customElementDefinition.tagName)) { + window.customElements.define(customElementDefinition.tagName, customElementDefinition.customElement); + } + } + } } return window.customElements.whenDefined(tagName).then(() => {