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(block-section): restore block toggling when clicking on the header switch #9472

Merged
merged 1 commit into from
Jun 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,38 @@ describe("calcite-block-section", () => {
const element = await page.find("calcite-block-section");
const toggleSpy = await element.spyOnEvent("calciteBlockSectionToggle");
const toggle = await page.find(`calcite-block-section >>> .${CSS.toggle}`);
let expectedClickEvents = 1;

expect(toggle.getAttribute("aria-expanded")).toBe("false");

await toggle.click();

expect(toggleSpy).toHaveReceivedEventTimes(1);
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
expect(await element.getProperty("open")).toBe(true);
expect(toggle.getAttribute("aria-expanded")).toBe("true");

await toggle.click();

expect(toggleSpy).toHaveReceivedEventTimes(2);
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
expect(await element.getProperty("open")).toBe(false);
expect(toggle.getAttribute("aria-expanded")).toBe("false");

if ((await element.getProperty("toggleDisplay")) === "switch") {
const switchToggle = await page.find(`calcite-block-section >>> .${CSS.switch}`);

await switchToggle.click();

expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
expect(await element.getProperty("open")).toBe(true);
expect(toggle.getAttribute("aria-expanded")).toBe("true");

await switchToggle.click();

expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
expect(await element.getProperty("open")).toBe(false);
expect(toggle.getAttribute("aria-expanded")).toBe("false");
}

const keyboardToggleEmitter =
toggle.tagName === "CALCITE-ACTION"
? (
Expand All @@ -204,14 +221,14 @@ describe("calcite-block-section", () => {
await keyboardToggleEmitter.press(" ");
await page.waitForChanges();

expect(toggleSpy).toHaveReceivedEventTimes(3);
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
expect(await element.getProperty("open")).toBe(true);
expect(toggle.getAttribute("aria-expanded")).toBe("true");

await keyboardToggleEmitter.press("Enter");
await page.waitForChanges();

expect(toggleSpy).toHaveReceivedEventTimes(4);
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
expect(await element.getProperty("open")).toBe(false);
expect(toggle.getAttribute("aria-expanded")).toBe("false");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@
}
}

.label {
@apply flex items-center justify-center my-1;

margin-inline-start: var(--calcite-spacing-md);
}

.section-header__text {
@apply my-0
flex-auto;
Expand All @@ -81,13 +75,6 @@
color: var(--calcite-color-text-1);
}
}

.switch {
@apply flex items-center;

inset-block-start: 50%;
transform: translate(0, 50%);
}
}

.status-icon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,8 @@ export class BlockSection implements LocalizedComponent, T9nComponent, LoadableC

{this.renderIcon(this.iconEnd)}
{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 */}
<calcite-switch checked={open} class={CSS.switch} inert label={toggleLabel} scale="s" />
</div>
<calcite-label class={CSS.label} layout="inline" tabIndex={-1}>
<calcite-switch checked={open} class={CSS.switch} label={toggleLabel} scale="s" />
</calcite-label>
</div>
) : (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ export const IDS = {
export const CSS = {
chevronIcon: "chevron-icon",
content: "content",
focusGuard: "focus-guard",
iconStart: "icon--start",
iconEnd: "icon--end",
invalid: "invalid",
label: "label",
sectionHeader: "section-header",
sectionHeaderText: "section-header__text",
statusIcon: "status-icon",
Expand Down
Loading