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(notice): fix rendering tied to named-slot content #10453

Merged
merged 2 commits into from
Oct 1, 2024
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
34 changes: 12 additions & 22 deletions packages/calcite-components/src/components/notice/notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import {
VNode,
Watch,
} from "@stencil/core";
import {
ConditionalSlotComponent,
connectConditionalSlotComponent,
disconnectConditionalSlotComponent,
} from "../../utils/conditionalSlot";
import { getSlotted, setRequestedIcon } from "../../utils/dom";
import { setRequestedIcon, slotChangeHasAssignedElement } from "../../utils/dom";
import {
componentFocusable,
LoadableComponent,
Expand Down Expand Up @@ -59,12 +54,7 @@ import { CSS, SLOTS } from "./resources";
assetsDirs: ["assets"],
})
export class Notice
implements
ConditionalSlotComponent,
LoadableComponent,
T9nComponent,
LocalizedComponent,
OpenCloseComponent
implements LoadableComponent, T9nComponent, LocalizedComponent, OpenCloseComponent
{
//--------------------------------------------------------------------------
//
Expand Down Expand Up @@ -135,13 +125,11 @@ export class Notice
//--------------------------------------------------------------------------

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

disconnectedCallback(): void {
disconnectConditionalSlotComponent(this);
disconnectLocalized(this);
disconnectMessages(this);
}
Expand All @@ -160,7 +148,6 @@ export class Notice
}

render(): VNode {
const { el } = this;
const closeButton = (
<button
aria-label={this.messages.close}
Expand All @@ -172,8 +159,6 @@ export class Notice
</button>
);

const hasActionEnd = getSlotted(el, SLOTS.actionsEnd);

return (
<div class={CSS.container} ref={this.setTransitionEl}>
{this.requestedIcon ? (
Expand All @@ -190,11 +175,9 @@ export class Notice
<slot name={SLOTS.message} />
<slot name={SLOTS.link} />
</div>
{hasActionEnd ? (
<div class={CSS.actionsEnd}>
<slot name={SLOTS.actionsEnd} />
</div>
) : null}
<div class={CSS.actionsEnd} hidden={!this.hasActionEnd}>
<slot name={SLOTS.actionsEnd} onSlotchange={this.handleActionsEndSlotChange} />
</div>
{this.closable ? closeButton : null}
</div>
);
Expand Down Expand Up @@ -266,10 +249,15 @@ export class Notice
// Private Methods
//
//--------------------------------------------------------------------------

private close = (): void => {
this.open = false;
};

private handleActionsEndSlotChange = (event: Event): void => {
this.hasActionEnd = slotChangeHasAssignedElement(event);
};

//--------------------------------------------------------------------------
//
// Private State/Props
Expand All @@ -296,4 +284,6 @@ export class Notice
openTransitionProp = "opacity";

transitionEl: HTMLElement;

@State() hasActionEnd = false;
}
Loading