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(shell-center-row): fix rendering tied to named-slot content #10451

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ describe("calcite-shell-center-row", () => {
const page = await newE2EPage();

await page.setContent("<calcite-shell-center-row></calcite-shell-center-row>");
await page.waitForChanges();
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? page.waitForChanges shouldn't be necessary after setting the test content. 🤔


const actionBarContainer = await page.find(`calcite-shell-center-row >>> .${CSS.actionBarContainer}`);

expect(actionBarContainer).toBeNull();
expect(await actionBarContainer.isVisible()).toBe(false);
});

it("should render action bar container first when action bar has start position", async () => {
Expand All @@ -59,6 +60,10 @@ describe("calcite-shell-center-row", () => {

await page.waitForChanges();
expect(element).toHaveClass(CSS.actionBarContainer);

const actionBarContainer = await page.find(`calcite-shell-center-row >>> .${CSS.actionBarContainer}`);

expect(await actionBarContainer.isVisible()).toBe(true);
});

it("should render action bar container last when action bar has end position", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Component, Element, Fragment, h, Prop, VNode } from "@stencil/core";
import {
ConditionalSlotComponent,
connectConditionalSlotComponent,
disconnectConditionalSlotComponent,
} from "../../utils/conditionalSlot";
import { getSlotted } from "../../utils/dom";
import { Component, Element, Fragment, h, Prop, State, VNode } from "@stencil/core";
import { Position, Scale } from "../interfaces";
import { slotChangeGetAssignedElements } from "../../utils/dom";
import { CSS, SLOTS } from "./resources";

/**
Expand All @@ -17,7 +12,7 @@ import { CSS, SLOTS } from "./resources";
styleUrl: "shell-center-row.scss",
shadow: true,
})
export class ShellCenterRow implements ConditionalSlotComponent {
export class ShellCenterRow {
// --------------------------------------------------------------------------
//
// Properties
Expand Down Expand Up @@ -47,19 +42,7 @@ export class ShellCenterRow implements ConditionalSlotComponent {

@Element() el: HTMLCalciteShellCenterRowElement;

// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------

connectedCallback(): void {
connectConditionalSlotComponent(this);
}

disconnectedCallback(): void {
disconnectConditionalSlotComponent(this);
}
@State() actionBar: HTMLCalciteActionBarElement;

// --------------------------------------------------------------------------
//
Expand All @@ -68,28 +51,33 @@ export class ShellCenterRow implements ConditionalSlotComponent {
// --------------------------------------------------------------------------

render(): VNode {
const { el } = this;
const { actionBar } = this;

const contentNode = (
<div class={CSS.content}>
<slot />
</div>
);

const actionBar = getSlotted<HTMLCalciteActionBarElement>(el, SLOTS.actionBar);

const actionBarNode = actionBar ? (
<div class={CSS.actionBarContainer} key="action-bar">
<slot name={SLOTS.actionBar} />
const actionBarNode = (
<div class={CSS.actionBarContainer} hidden={!this.actionBar} key="action-bar">
<slot name={SLOTS.actionBar} onSlotchange={this.handleActionBarSlotChange} />
</div>
) : null;
);

const children: VNode[] = [actionBarNode, contentNode];

// todo: if actionBar position changes, this will not update.
if (actionBar?.position === "end") {
Copy link
Member

Choose a reason for hiding this comment

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

Can you create a separate issue for this and remove this comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I can create one. Didn't we decide to deprecate shell-center-row at some point?

children.reverse();
Copy link
Member Author

Choose a reason for hiding this comment

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

if actionBar position changes, this will not update. Since this component is deprecated I guess it doesn't matter too much.

Copy link
Member Author

Choose a reason for hiding this comment

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

}

return <Fragment>{children}</Fragment>;
}

private handleActionBarSlotChange = (event: Event): void => {
this.actionBar = slotChangeGetAssignedElements(event).filter(
(el): el is HTMLCalciteActionBarElement => el.matches("calcite-action-bar"),
)[0];
};
}
Loading