MCPcopy Create free account
hub / github.com/ionic-team/ionic-framework / componentWillLoad

Method componentWillLoad

core/src/components/modal/modal.tsx:463–522  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

461 }
462
463 componentWillLoad() {
464 const { breakpoints, initialBreakpoint, el, htmlAttributes } = this;
465 const isSheetModal = (this.isSheetModal = breakpoints !== undefined && initialBreakpoint !== undefined);
466
467 const attributesToInherit = ['aria-label', 'role'];
468 this.inheritedAttributes = inheritAttributes(el, attributesToInherit);
469
470 // Cache original parent before modal gets moved to body during presentation
471 if (el.parentNode) {
472 this.cachedOriginalParent = el.parentNode as HTMLElement;
473 }
474
475 /**
476 * When using a controller modal you can set attributes
477 * using the htmlAttributes property. Since the above attributes
478 * need to be inherited inside of the modal, we need to look
479 * and see if these attributes are being set via htmlAttributes.
480 *
481 * We could alternatively move this to componentDidLoad to simplify the work
482 * here, but we'd then need to make inheritedAttributes a State variable,
483 * thus causing another render to always happen after the first render.
484 */
485 if (htmlAttributes !== undefined) {
486 attributesToInherit.forEach((attribute) => {
487 const attributeValue = htmlAttributes[attribute];
488 if (attributeValue) {
489 /**
490 * If an attribute we need to inherit was
491 * set using htmlAttributes then add it to
492 * inheritedAttributes and remove it from htmlAttributes.
493 * This ensures the attribute is inherited and not
494 * set on the host.
495 *
496 * In this case, if an inherited attribute is set
497 * on the host element and using htmlAttributes then
498 * htmlAttributes wins, but that's not a pattern that we recommend.
499 * The only time you'd need htmlAttributes is when using modalController.
500 */
501 this.inheritedAttributes = {
502 ...this.inheritedAttributes,
503 [attribute]: htmlAttributes[attribute],
504 };
505
506 delete htmlAttributes[attribute];
507 }
508 });
509 }
510
511 if (isSheetModal) {
512 this.currentBreakpoint = this.initialBreakpoint;
513 }
514
515 if (breakpoints !== undefined && initialBreakpoint !== undefined && !breakpoints.includes(initialBreakpoint)) {
516 printIonWarning('[ion-modal] - Your breakpoints array must include the initialBreakpoint value.');
517 }
518
519 if (!this.htmlAttributes?.id) {
520 setOverlayId(this.el);

Callers

nothing calls this directly

Calls 3

inheritAttributesFunction · 0.90
printIonWarningFunction · 0.90
setOverlayIdFunction · 0.90

Tested by

no test coverage detected