diff --git a/packages/calcite-components/src/components/block-section/block-section.e2e.ts b/packages/calcite-components/src/components/block-section/block-section.e2e.ts index 3ec0ad96f16..5f533869ec4 100644 --- a/packages/calcite-components/src/components/block-section/block-section.e2e.ts +++ b/packages/calcite-components/src/components/block-section/block-section.e2e.ts @@ -1,4 +1,4 @@ -import { CSS, TEXT } from "./resources"; +import { CSS } from "./resources"; import { accessible, defaults, focusable, hidden, reflects, renders, t9n } from "../../tests/commonTests"; import { E2EPage, newE2EPage } from "@stencil/core/testing"; import { html } from "../../../support/formatting"; @@ -87,9 +87,8 @@ describe("calcite-block-section", () => { }); it("can be toggled", async () => { - const page = await newE2EPage({ - html: ``, - }); + const page = await newE2EPage(); + await page.setContent(html``); await assertToggleBehavior(page); }); @@ -119,7 +118,8 @@ describe("calcite-block-section", () => { }); it("can be toggled", async () => { - const page = await newE2EPage({ html: "" }); + const page = await newE2EPage(); + await page.setContent(html``); await assertToggleBehavior(page); }); }); @@ -173,19 +173,19 @@ describe("calcite-block-section", () => { const toggleSpy = await element.spyOnEvent("calciteBlockSectionToggle"); const toggle = await page.find(`calcite-block-section >>> .${CSS.toggle}`); - expect(toggle.getAttribute("aria-label")).toBe(TEXT.expand); + expect(toggle.getAttribute("aria-expanded")).toBe("false"); await toggle.click(); expect(toggleSpy).toHaveReceivedEventTimes(1); expect(await element.getProperty("open")).toBe(true); - expect(toggle.getAttribute("aria-label")).toBe(TEXT.collapse); + expect(toggle.getAttribute("aria-expanded")).toBe("true"); await toggle.click(); expect(toggleSpy).toHaveReceivedEventTimes(2); expect(await element.getProperty("open")).toBe(false); - expect(toggle.getAttribute("aria-label")).toBe(TEXT.expand); + expect(toggle.getAttribute("aria-expanded")).toBe("false"); const keyboardToggleEmitter = toggle.tagName === "CALCITE-ACTION" @@ -206,13 +206,13 @@ describe("calcite-block-section", () => { expect(toggleSpy).toHaveReceivedEventTimes(3); expect(await element.getProperty("open")).toBe(true); - expect(toggle.getAttribute("aria-label")).toBe(TEXT.collapse); + expect(toggle.getAttribute("aria-expanded")).toBe("true"); await keyboardToggleEmitter.press("Enter"); await page.waitForChanges(); expect(toggleSpy).toHaveReceivedEventTimes(4); expect(await element.getProperty("open")).toBe(false); - expect(toggle.getAttribute("aria-label")).toBe(TEXT.expand); + expect(toggle.getAttribute("aria-expanded")).toBe("false"); } }); diff --git a/packages/calcite-components/src/components/block-section/block-section.scss b/packages/calcite-components/src/components/block-section/block-section.scss index 051fde69d8c..3d90065ae6d 100644 --- a/packages/calcite-components/src/components/block-section/block-section.scss +++ b/packages/calcite-components/src/components/block-section/block-section.scss @@ -60,11 +60,18 @@ word-wrap: anywhere; } -.toggle--switch { - calcite-switch { - @apply pointer-events-none; +.toggle--switch-container { + @apply flex items-center relative bg-transparent w-full; + + .focus-guard { + --calcite-label-margin-bottom: 0; + @apply absolute pointer-events-none; + inset-inline-end: 0; margin-inline-start: theme("margin.1"); } +} + +.toggle--switch { .status-icon { margin-inline-start: theme("margin.2"); } diff --git a/packages/calcite-components/src/components/block-section/block-section.tsx b/packages/calcite-components/src/components/block-section/block-section.tsx index a84b1bd2a11..ac76d37b85b 100644 --- a/packages/calcite-components/src/components/block-section/block-section.tsx +++ b/packages/calcite-components/src/components/block-section/block-section.tsx @@ -13,7 +13,6 @@ import { } from "@stencil/core"; import { focusFirstTabbable, getElementDir, toAriaBoolean } from "../../utils/dom"; -import { guid } from "../../utils/guid"; import { isActivationKey } from "../../utils/key"; import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale"; import { @@ -26,7 +25,7 @@ import { import { Status } from "../interfaces"; import { BlockSectionMessages } from "./assets/block-section/t9n"; import { BlockSectionToggleDisplay } from "./interfaces"; -import { CSS, ICONS } from "./resources"; +import { CSS, ICONS, IDS } from "./resources"; import { componentFocusable, LoadableComponent, @@ -117,8 +116,6 @@ export class BlockSection implements LocalizedComponent, T9nComponent, LoadableC @Element() el: HTMLCalciteBlockSectionElement; - private guid = guid(); - @State() effectiveLocale: string; @Watch("effectiveLocale") @@ -213,41 +210,46 @@ export class BlockSection implements LocalizedComponent, T9nComponent, LoadableC const toggleLabel = open ? messages.collapse : messages.expand; - const { guid } = this; - const regionId = `${guid}-region`; - const buttonId = `${guid}-button`; - const headerNode = toggleDisplay === "switch" ? (
-
- {text} +
+
+ {text} +
+ {this.renderStatusIcon()}
- - {this.renderStatusIcon()} + {/* we use calcite-label to use a simple component that will allow us to prevent keyboard focus by setting tabindex="-1" on the host */} + + +
) : (