Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions packages/calcite-components/src/components/block/block.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ describe("calcite-block", () => {
const actionAssignedSlot = await page.$eval("calcite-action", (action) => action.assignedSlot.name);
expect(actionAssignedSlot).toBe(SLOTS.headerMenuActions);
});

it("applies correct header spacing when heading or description properties are present", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fine for now until we add extra checks to ensure styles use reflected props. After that, we should rely on screenshot tests. From the assertion perspective, it is not guaranteed that changes in the CSS class will be detected by this test, meaning its implementation could change without causing a test failure. cc @driskull

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed.

This is a sufficient test for now but ideally a screenshot test should be the real test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jcfranco Should I create a follow up issue to add a screenshot test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jcfranco I created this follow up issue to remove this E2E test once the reflected prop checks are in place.

const page = await newE2EPage();

await page.setContent(`<calcite-block></calcite-block>`);

const block = await page.find("calcite-block");
const header = await page.find(`calcite-block >>> .${CSS.header}`);
block.setAttribute("heading", "test-heading");
await page.waitForChanges();

expect(header).toHaveClass(CSS.headerHasText);

block.removeAttribute("heading");
await page.waitForChanges();

expect(header).not.toHaveClass(CSS.headerHasText);

block.setAttribute("description", "test-description");
await page.waitForChanges();

expect(header).toHaveClass(CSS.headerHasText);
});
});

it("should allow the CSS custom property to be overridden when applied to :root", async () => {
Expand Down
11 changes: 4 additions & 7 deletions packages/calcite-components/src/components/block/block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
@apply justify-start;
}

.header--has-text {
padding: var(--calcite-spacing-md);
}

.header,
.toggle {
grid-area: header;
Expand Down Expand Up @@ -194,11 +198,4 @@ calcite-action-menu {
}
}

:host([heading]),
:host([description]) {
.header {
padding: var(--calcite-spacing-md);
}
}

@include base-component();
7 changes: 5 additions & 2 deletions packages/calcite-components/src/components/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,15 @@ export class Block
}

render(): VNode {
const { collapsible, el, loading, open, heading, messages } = this;
const { collapsible, el, loading, open, heading, messages, description } = this;

const toggleLabel = open ? messages.collapse : messages.expand;

const headerContent = (
<header class={CSS.header} id={IDS.header}>
<header
class={{ [CSS.header]: true, [CSS.headerHasText]: !!(heading || description) }}
id={IDS.header}
>
{this.renderIcon("start")}
{this.renderContentStart()}
{this.renderLoaderStatusIcon()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const CSS = {
description: "description",
header: "header",
headerContainer: "header-container",
headerHasText: "header--has-text",
heading: "heading",
icon: "icon",
iconStart: "icon--start",
Expand Down