Skip to content

Commit 1a9c15c

Browse files
authored
fix(action-bar): no longer delegates focus when clicked on non-focusable region (#7310)
**Related Issue:** #6462 ## Summary This PR will fix focusing `calcite-action` in `calcite-action-bar` when user clicks on non-focusable area. Neither the collapse button nor slotted `calcite-action` will be focused when clicked on non-focusable area.
1 parent 7f486eb commit 1a9c15c

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

packages/calcite-components/src/components/action-bar/action-bar.e2e.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { html } from "../../../support/formatting";
33
import { accessible, defaults, focusable, hidden, reflects, renders, slots, t9n } from "../../tests/commonTests";
44
import { CSS, SLOTS } from "./resources";
55
import { overflowActionsDebounceInMs } from "./utils";
6+
import { getFocusedElementProp } from "../../tests/utils";
67

78
describe("calcite-action-bar", () => {
89
describe("renders", () => {
@@ -247,6 +248,21 @@ describe("calcite-action-bar", () => {
247248
focusTargetSelector: "calcite-action"
248249
}
249250
);
251+
252+
it("should not focus any action element when clicked on non-focusable region", async () => {
253+
const page = await newE2EPage();
254+
await page.setContent(html` <calcite-action-bar layout="horizontal" style="width: 100%">
255+
<calcite-action-group> <calcite-action text="Add" icon="plus"> </calcite-action> </calcite-action-group
256+
></calcite-action-bar>`);
257+
258+
const actionBarElRect = await page.evaluate(() => {
259+
const actionBarEl = document.querySelector("calcite-action-bar");
260+
return actionBarEl.getBoundingClientRect().toJSON();
261+
});
262+
263+
await page.mouse.click(actionBarElRect.right / 2, actionBarElRect.y + actionBarElRect.bottom / 2);
264+
expect(await getFocusedElementProp(page, "tagName", { shadow: true })).not.toBe("CALCITE-ACTION");
265+
});
250266
});
251267

252268
describe("slots", () => {

packages/calcite-components/src/components/action-bar/action-bar.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
:host([layout="vertical"]) {
1818
@apply flex-col;
19+
.action-group--bottom {
20+
margin-block-start: auto;
21+
}
1922
}
2023

2124
:host([layout="horizontal"]) {
2225
@apply flex-row;
26+
.action-group--bottom {
27+
@apply ms-auto;
28+
}
2329
}
2430

2531
:host([layout="vertical"][overflow-actions-disabled]) {
@@ -53,5 +59,5 @@
5359
}
5460

5561
.action-group--bottom {
56-
@apply flex-grow justify-end;
62+
@apply justify-end;
5763
}

packages/calcite-components/src/components/action-bar/action-bar.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
connectConditionalSlotComponent,
1818
disconnectConditionalSlotComponent
1919
} from "../../utils/conditionalSlot";
20-
import { getSlotted, slotChangeGetAssignedElements } from "../../utils/dom";
20+
import { focusFirstTabbable, getSlotted, slotChangeGetAssignedElements } from "../../utils/dom";
2121
import {
2222
componentFocusable,
2323
LoadableComponent,
@@ -53,14 +53,20 @@ import {
5353
@Component({
5454
tag: "calcite-action-bar",
5555
styleUrl: "action-bar.scss",
56-
shadow: {
57-
delegatesFocus: true
58-
},
56+
shadow: true,
5957
assetsDirs: ["assets"]
6058
})
6159
export class ActionBar
6260
implements ConditionalSlotComponent, LoadableComponent, LocalizedComponent, T9nComponent
6361
{
62+
//--------------------------------------------------------------------------
63+
//
64+
// Element
65+
//
66+
//--------------------------------------------------------------------------
67+
68+
@Element() el: HTMLCalciteActionBarElement;
69+
6470
// --------------------------------------------------------------------------
6571
//
6672
// Properties
@@ -157,8 +163,6 @@ export class ActionBar
157163
//
158164
// --------------------------------------------------------------------------
159165

160-
@Element() el: HTMLCalciteActionBarElement;
161-
162166
mutationObserver = createObserver("mutation", () => {
163167
const { el, expanded } = this;
164168
toggleChildActionText({ el, expanded });
@@ -245,7 +249,7 @@ export class ActionBar
245249
async setFocus(): Promise<void> {
246250
await componentFocusable(this);
247251

248-
this.el?.focus();
252+
focusFirstTabbable(this.el);
249253
}
250254

251255
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)