Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flow): process items on loaded #11364

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/calcite-components/src/components/flow/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export class Flow extends LitElement implements LoadableComponent {
private frameEl: HTMLDivElement;

private itemMutationObserver: MutationObserver = createObserver("mutation", () =>
this.handleMutationObserverChange(),
this.updateItemsAndProps(),
);

private items: FlowItemLikeElement[] = [];

private selectedIndex = -1;

// #endregion
Expand All @@ -44,8 +46,6 @@ export class Flow extends LitElement implements LoadableComponent {

@state() flowDirection: FlowDirection = "standby";

@state() items: FlowItemLikeElement[] = [];

// #endregion

// #region Public Properties
Expand Down Expand Up @@ -120,7 +120,6 @@ export class Flow extends LitElement implements LoadableComponent {

override connectedCallback(): void {
this.itemMutationObserver?.observe(this.el, { childList: true, subtree: true });
this.handleMutationObserverChange();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be fine since connecting a flow doesn't need to update items. The mutation observer should suffice when items are added. If we find an issue we can call on connectedCallback and loaded.

}

load(): void {
Expand All @@ -139,6 +138,7 @@ export class Flow extends LitElement implements LoadableComponent {

loaded(): void {
setComponentLoaded(this);
this.updateItemsAndProps();
}

override disconnectedCallback(): void {
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Flow extends LitElement implements LoadableComponent {
return newSelectedIndex < oldSelectedIndex ? "retreating" : "advancing";
}

private handleMutationObserverChange(): void {
private updateItemsAndProps(): void {
const { customItemSelectors, el } = this;

const newItems = Array.from<FlowItemLikeElement>(
Expand All @@ -206,7 +206,6 @@ export class Flow extends LitElement implements LoadableComponent {
this.items = newItems;

this.ensureSelectedFlowItemExists();

this.updateFlowProps();
}

Expand Down
Loading