Skip to content

Commit

Permalink
fix(block): display correct header spacing when heading or descriptio…
Browse files Browse the repository at this point in the history
…n are present (#9924)

**Related Issue:**
[#9920](#9920)

## Summary
Update `block` component to display correct header spacing when
`heading` or `description` properties are present.

---------

Co-authored-by: Matt Driscoll <[email protected]>
  • Loading branch information
2 people authored and benelan committed Aug 2, 2024
1 parent 90e9368 commit d8f1077
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
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 () => {
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

0 comments on commit d8f1077

Please sign in to comment.