Skip to content

Commit 519a11c

Browse files
authored
fix(block-section): restore block toggling when clicking on the header switch (#9472)
**Related Issue:** #9454 ## Summary Fixes toggling issue caused by moving switch outside toggle container. This regression was introduced by #9194.
1 parent 0ec0371 commit 519a11c

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

packages/calcite-components/src/components/block-section/block-section.e2e.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,38 @@ describe("calcite-block-section", () => {
172172
const element = await page.find("calcite-block-section");
173173
const toggleSpy = await element.spyOnEvent("calciteBlockSectionToggle");
174174
const toggle = await page.find(`calcite-block-section >>> .${CSS.toggle}`);
175+
let expectedClickEvents = 1;
175176

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

178179
await toggle.click();
179180

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

184185
await toggle.click();
185186

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

191+
if ((await element.getProperty("toggleDisplay")) === "switch") {
192+
const switchToggle = await page.find(`calcite-block-section >>> .${CSS.switch}`);
193+
194+
await switchToggle.click();
195+
196+
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
197+
expect(await element.getProperty("open")).toBe(true);
198+
expect(toggle.getAttribute("aria-expanded")).toBe("true");
199+
200+
await switchToggle.click();
201+
202+
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
203+
expect(await element.getProperty("open")).toBe(false);
204+
expect(toggle.getAttribute("aria-expanded")).toBe("false");
205+
}
206+
190207
const keyboardToggleEmitter =
191208
toggle.tagName === "CALCITE-ACTION"
192209
? (
@@ -204,14 +221,14 @@ describe("calcite-block-section", () => {
204221
await keyboardToggleEmitter.press(" ");
205222
await page.waitForChanges();
206223

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

211228
await keyboardToggleEmitter.press("Enter");
212229
await page.waitForChanges();
213230

214-
expect(toggleSpy).toHaveReceivedEventTimes(4);
231+
expect(toggleSpy).toHaveReceivedEventTimes(expectedClickEvents++);
215232
expect(await element.getProperty("open")).toBe(false);
216233
expect(toggle.getAttribute("aria-expanded")).toBe("false");
217234
}

packages/calcite-components/src/components/block-section/block-section.scss

-13
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@
4949
}
5050
}
5151

52-
.label {
53-
@apply flex items-center justify-center my-1;
54-
55-
margin-inline-start: var(--calcite-spacing-md);
56-
}
57-
5852
.section-header__text {
5953
@apply my-0
6054
flex-auto;
@@ -81,13 +75,6 @@
8175
color: var(--calcite-color-text-1);
8276
}
8377
}
84-
85-
.switch {
86-
@apply flex items-center;
87-
88-
inset-block-start: 50%;
89-
transform: translate(0, 50%);
90-
}
9178
}
9279

9380
.status-icon {

packages/calcite-components/src/components/block-section/block-section.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,8 @@ export class BlockSection implements LocalizedComponent, T9nComponent, LoadableC
268268

269269
{this.renderIcon(this.iconEnd)}
270270
{this.renderStatusIcon()}
271-
{/* we use calcite-label to use a simple component that will allow us to prevent keyboard focus by setting tabindex="-1" on the host */}
271+
<calcite-switch checked={open} class={CSS.switch} inert label={toggleLabel} scale="s" />
272272
</div>
273-
<calcite-label class={CSS.label} layout="inline" tabIndex={-1}>
274-
<calcite-switch checked={open} class={CSS.switch} label={toggleLabel} scale="s" />
275-
</calcite-label>
276273
</div>
277274
) : (
278275
<div

packages/calcite-components/src/components/block-section/resources.ts

-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ export const IDS = {
66
export const CSS = {
77
chevronIcon: "chevron-icon",
88
content: "content",
9-
focusGuard: "focus-guard",
109
iconStart: "icon--start",
1110
iconEnd: "icon--end",
1211
invalid: "invalid",
13-
label: "label",
1412
sectionHeader: "section-header",
1513
sectionHeaderText: "section-header__text",
1614
statusIcon: "status-icon",

0 commit comments

Comments
 (0)