Skip to content

Commit

Permalink
fix(combobox, dropdown, input-date-picker, popover, tooltip): fix ini…
Browse files Browse the repository at this point in the history
…tialization logic in components output target (#9470)

**Related Issue:** #9468

## Summary

#9443 introduced a
regression caused by using the `componentOnLoad` util to consolidate
initialization logic shared between `connectedCallback` and
`componentDidLoad`. The util appears to resolve at a different time in
the `components` output target, which messed up with initialization of
certain components.

**Note**: there are no accompanying tests as this is not reproducible in
the test environment, which uses the lazy-loaded output.
  • Loading branch information
jcfranco authored and benelan committed Jun 25, 2024
1 parent 39e6d6f commit 5dcc3f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export class Combobox
//
// --------------------------------------------------------------------------

async connectedCallback(): Promise<void> {
connectedCallback(): void {
connectInteractive(this);
connectLocalized(this);
connectMessages(this);
Expand All @@ -483,9 +483,7 @@ export class Combobox
onToggleOpenCloseComponent(this);
}

await componentOnReady(this.el);
connectFloatingUI(this, this.referenceEl, this.floatingEl);
afterConnectDefaultValueSet(this, this.getValue());
}

async componentWillLoad(): Promise<void> {
Expand All @@ -496,6 +494,8 @@ export class Combobox
}

componentDidLoad(): void {
afterConnectDefaultValueSet(this, this.getValue());
connectFloatingUI(this, this.referenceEl, this.floatingEl);
setComponentLoaded(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { createObserver } from "../../utils/observers";
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
import { RequestedItem } from "../dropdown-group/interfaces";
import { Scale } from "../interfaces";
import { componentOnReady } from "../../utils/component";
import { ItemKeyboardEvent } from "./interfaces";
import { SLOTS } from "./resources";

Expand Down Expand Up @@ -198,7 +197,7 @@ export class Dropdown
//
//--------------------------------------------------------------------------

async connectedCallback(): Promise<void> {
connectedCallback(): void {
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
this.setFilteredPlacements();
if (this.open) {
Expand All @@ -207,8 +206,6 @@ export class Dropdown
}
connectInteractive(this);
this.updateItems();

await componentOnReady(this.el);
connectFloatingUI(this, this.referenceEl, this.floatingEl);
}

Expand All @@ -218,6 +215,7 @@ export class Dropdown

componentDidLoad(): void {
setComponentLoaded(this);
connectFloatingUI(this, this.referenceEl, this.floatingEl);
}

componentDidRender(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import {
FocusTrapComponent,
} from "../../utils/focusTrapComponent";
import { guid } from "../../utils/guid";
import { componentOnReady, getIconScale } from "../../utils/component";
import { getIconScale } from "../../utils/component";
import { Status } from "../interfaces";
import { Validation } from "../functional/Validation";
import { syncHiddenFormInput } from "../input/common/input";
Expand Down Expand Up @@ -462,7 +462,7 @@ export class InputDatePicker
//
// --------------------------------------------------------------------------

async connectedCallback(): Promise<void> {
connectedCallback(): void {
connectInteractive(this);
connectLocalized(this);

Expand Down Expand Up @@ -509,9 +509,7 @@ export class InputDatePicker
onToggleOpenCloseComponent(this);
}

await componentOnReady(this.el);
connectFloatingUI(this, this.referenceEl, this.floatingEl);
this.localizeInputValues();
}

async componentWillLoad(): Promise<void> {
Expand All @@ -523,6 +521,8 @@ export class InputDatePicker

componentDidLoad(): void {
setComponentLoaded(this);
this.localizeInputValues();
connectFloatingUI(this, this.referenceEl, this.floatingEl);
}

disconnectedCallback(): void {
Expand Down
14 changes: 9 additions & 5 deletions packages/calcite-components/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
} from "../../utils/loadable";
import { createObserver } from "../../utils/observers";
import { FloatingArrow } from "../functional/FloatingArrow";
import { componentOnReady, getIconScale } from "../../utils/component";
import { getIconScale } from "../../utils/component";
import PopoverManager from "./PopoverManager";
import { PopoverMessages } from "./assets/popover/t9n";
import { ARIA_CONTROLS, ARIA_EXPANDED, CSS, defaultPopoverPlacement } from "./resources";
Expand Down Expand Up @@ -278,6 +278,8 @@ export class Popover

transitionEl: HTMLDivElement;

hasLoaded = false;

focusTrap: FocusTrap;

// --------------------------------------------------------------------------
Expand All @@ -286,13 +288,11 @@ export class Popover
//
// --------------------------------------------------------------------------

async connectedCallback(): Promise<void> {
connectedCallback(): void {
this.setFilteredPlacements();
connectLocalized(this);
connectMessages(this);

await componentOnReady(this.el);
this.setUpReferenceElement();
this.setUpReferenceElement(this.hasLoaded);
connectFocusTrap(this);

if (this.open) {
Expand All @@ -307,6 +307,10 @@ export class Popover

componentDidLoad(): void {
setComponentLoaded(this);
if (this.referenceElement && !this.effectiveReferenceElement) {
this.setUpReferenceElement();
}
this.hasLoaded = true;
}

disconnectedCallback(): void {
Expand Down
14 changes: 10 additions & 4 deletions packages/calcite-components/src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
import { guid } from "../../utils/guid";
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
import { FloatingArrow } from "../functional/FloatingArrow";
import { componentOnReady } from "../../utils/component";
import { ARIA_DESCRIBED_BY, CSS } from "./resources";
import TooltipManager from "./TooltipManager";
import { getEffectiveReferenceElement } from "./utils";
Expand Down Expand Up @@ -147,6 +146,8 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {

guid = `calcite-tooltip-${guid()}`;

hasLoaded = false;

openTransitionProp = "opacity";

transitionEl: HTMLDivElement;
Expand All @@ -157,10 +158,8 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {
//
// --------------------------------------------------------------------------

async connectedCallback(): Promise<void> {
await componentOnReady(this.el);
connectedCallback(): void {
this.setUpReferenceElement(true);

if (this.open) {
onToggleOpenCloseComponent(this);
}
Expand All @@ -172,6 +171,13 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {
}
}

componentDidLoad(): void {
if (this.referenceElement && !this.effectiveReferenceElement) {
this.setUpReferenceElement();
}
this.hasLoaded = true;
}

disconnectedCallback(): void {
this.removeReferences();
disconnectFloatingUI(this, this.effectiveReferenceElement, this.el);
Expand Down

0 comments on commit 5dcc3f5

Please sign in to comment.