Skip to content

Commit

Permalink
fix(shell-center-row): fix rendering tied to named-slot content (#10451)
Browse files Browse the repository at this point in the history
**Related Issue:** #6059

- remove use of `getSlotted` utility
- replace with `slotchange` event and `@State` variables to update the
display of elements.
- existing tests should suffice
  • Loading branch information
driskull authored and benelan committed Feb 8, 2025
1 parent 50ede48 commit ba0b99a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("calcite-shell-center-row", () => {

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 +59,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,16 +1,9 @@
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 { logger } from "../../utils/logger";
import { slotChangeGetAssignedElements } from "../../utils/dom";
import { CSS, SLOTS } from "./resources";

/**
* @deprecated Use the `calcite-shell-panel` component instead.
* @slot - A slot for adding content to the `calcite-shell-panel`.
* @slot action-bar - A slot for adding a `calcite-action-bar` to the `calcite-shell-panel`.
*/
Expand All @@ -19,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 @@ -49,33 +42,7 @@ export class ShellCenterRow implements ConditionalSlotComponent {

@Element() el: HTMLCalciteShellCenterRowElement;

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

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

disconnectedCallback(): void {
disconnectConditionalSlotComponent(this);
}

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

componentWillLoad(): void {
logger.deprecated("component", {
name: "shell-center-row",
removalVersion: 4,
suggested: "shell-panel",
});
}
@State() actionBar: HTMLCalciteActionBarElement;

// --------------------------------------------------------------------------
//
Expand All @@ -84,21 +51,19 @@ 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];

Expand All @@ -108,4 +73,10 @@ export class ShellCenterRow implements ConditionalSlotComponent {

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

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

0 comments on commit ba0b99a

Please sign in to comment.