Skip to content

Commit 14a6673

Browse files
bdfranckchrisolsen
authored andcommitted
fix(#2948): fix Modal spacing for heading and actions
1 parent 9d32cdd commit 14a6673

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

libs/react-components/src/lib/modal/modal.spec.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { render } from "@testing-library/react";
22
import GoabButton from "../../lib/button/button";
33
import { GoabModal, GoabModalProps } from "./modal";
44

5-
describe("Modal Tests", () => {
5+
describe("Modal", () => {
66
it("should render", async () => {
77
const { baseElement } = render(<GoabModal>Modal Content</GoabModal>);
88

@@ -12,7 +12,7 @@ describe("Modal Tests", () => {
1212
expect(modal?.getAttribute("closable")).toBe("false");
1313
});
1414

15-
it("Modal - should render with close capability via icon and background", async () => {
15+
it("should render with close capability via icon and background", async () => {
1616
const props = {
1717
heading: "Modal Heading",
1818
open: true,
@@ -35,15 +35,29 @@ describe("Modal Tests", () => {
3535
const { baseElement } = render(<GoabModal {...props}>Modal Content</GoabModal>);
3636
const modal = baseElement.querySelector("goa-modal");
3737
const actionContent = modal?.querySelector("[slot='actions']");
38-
const heading = modal?.querySelector("[slot='heading']");
3938
// Role attribute is no longer passed to the web component (deprecated)
4039
expect(modal?.getAttribute("role")).toBeNull();
4140

42-
expect(heading?.textContent).toContain("Modal Heading");
41+
expect(modal?.getAttribute("heading")).toBe("Modal Heading");
4342
expect(modal?.getAttribute("open")).toBe("true");
4443
expect(modal?.getAttribute("maxwidth")).toBe("500px");
4544
expect(modal?.getAttribute("closable")).toBe("true");
4645
expect(modal?.textContent).toContain("Modal Content");
4746
expect(actionContent?.textContent).toContain("Close");
4847
});
48+
49+
it("should render with React node heading", async () => {
50+
const headingNode = <div>Custom Heading</div>;
51+
const { baseElement } = render(
52+
<GoabModal open heading={headingNode}>
53+
Modal Content
54+
</GoabModal>,
55+
);
56+
57+
const modal = baseElement.querySelector("goa-modal");
58+
const headingContent = modal?.querySelector("[slot='heading']");
59+
60+
expect(modal?.getAttribute("open")).toBe("true");
61+
expect(headingContent?.textContent).toBe("Custom Heading");
62+
});
4963
});

libs/react-components/src/lib/modal/modal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ export function GoabModal({
8080
ref={el}
8181
open={open ? "true" : undefined}
8282
closable={onClose ? "true" : "false"}
83+
heading={typeof heading === "string" ? heading : undefined}
8384
maxwidth={maxWidth}
8485
transition={transition}
8586
calloutvariant={calloutVariant}
8687
testid={testId}
8788
>
88-
{heading && <div slot="heading">{heading}</div>}
89+
{heading && typeof heading !== "string" && <div slot="heading">{heading}</div>}
8990
{actions && <div slot="actions">{actions}</div>}
9091
{children}
9192
</goa-modal>

libs/web-components/src/components/modal/Modal.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,20 @@
138138
const el = _rootEl?.querySelector(selector);
139139
const children = el && getSlottedChildren(el);
140140
141+
// If no children at all, it's empty
142+
if (!children || children.length === 0) {
143+
return true;
144+
}
145+
146+
// If the only child is an iframe, it's empty
147+
if (children?.length === 1 && children[0].tagName === "IFRAME") {
148+
return true;
149+
}
150+
141151
return children?.length === 1 // there should only be one child element
142152
&& children[0].tagName === "DIV" // angular renders a <div>
143153
&& children[0].getAttribute("slot") === slotName // the div is a slot
154+
&& children[0]?.textContent?.trim() === "" // the div is empty
144155
}
145156
146157
function close(e: Event) {

0 commit comments

Comments
 (0)