Skip to content

Commit

Permalink
fix(action-bar): no longer delegates focus when clicked on non-focusa…
Browse files Browse the repository at this point in the history
…ble 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.
  • Loading branch information
anveshmekala authored Jul 12, 2023
1 parent 7f486eb commit 1a9c15c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { html } from "../../../support/formatting";
import { accessible, defaults, focusable, hidden, reflects, renders, slots, t9n } from "../../tests/commonTests";
import { CSS, SLOTS } from "./resources";
import { overflowActionsDebounceInMs } from "./utils";
import { getFocusedElementProp } from "../../tests/utils";

describe("calcite-action-bar", () => {
describe("renders", () => {
Expand Down Expand Up @@ -247,6 +248,21 @@ describe("calcite-action-bar", () => {
focusTargetSelector: "calcite-action"
}
);

it("should not focus any action element when clicked on non-focusable region", async () => {
const page = await newE2EPage();
await page.setContent(html` <calcite-action-bar layout="horizontal" style="width: 100%">
<calcite-action-group> <calcite-action text="Add" icon="plus"> </calcite-action> </calcite-action-group
></calcite-action-bar>`);

const actionBarElRect = await page.evaluate(() => {
const actionBarEl = document.querySelector("calcite-action-bar");
return actionBarEl.getBoundingClientRect().toJSON();
});

await page.mouse.click(actionBarElRect.right / 2, actionBarElRect.y + actionBarElRect.bottom / 2);
expect(await getFocusedElementProp(page, "tagName", { shadow: true })).not.toBe("CALCITE-ACTION");
});
});

describe("slots", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@

:host([layout="vertical"]) {
@apply flex-col;
.action-group--bottom {
margin-block-start: auto;
}
}

:host([layout="horizontal"]) {
@apply flex-row;
.action-group--bottom {
@apply ms-auto;
}
}

:host([layout="vertical"][overflow-actions-disabled]) {
Expand Down Expand Up @@ -53,5 +59,5 @@
}

.action-group--bottom {
@apply flex-grow justify-end;
@apply justify-end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
connectConditionalSlotComponent,
disconnectConditionalSlotComponent
} from "../../utils/conditionalSlot";
import { getSlotted, slotChangeGetAssignedElements } from "../../utils/dom";
import { focusFirstTabbable, getSlotted, slotChangeGetAssignedElements } from "../../utils/dom";
import {
componentFocusable,
LoadableComponent,
Expand Down Expand Up @@ -53,14 +53,20 @@ import {
@Component({
tag: "calcite-action-bar",
styleUrl: "action-bar.scss",
shadow: {
delegatesFocus: true
},
shadow: true,
assetsDirs: ["assets"]
})
export class ActionBar
implements ConditionalSlotComponent, LoadableComponent, LocalizedComponent, T9nComponent
{
//--------------------------------------------------------------------------
//
// Element
//
//--------------------------------------------------------------------------

@Element() el: HTMLCalciteActionBarElement;

// --------------------------------------------------------------------------
//
// Properties
Expand Down Expand Up @@ -157,8 +163,6 @@ export class ActionBar
//
// --------------------------------------------------------------------------

@Element() el: HTMLCalciteActionBarElement;

mutationObserver = createObserver("mutation", () => {
const { el, expanded } = this;
toggleChildActionText({ el, expanded });
Expand Down Expand Up @@ -245,7 +249,7 @@ export class ActionBar
async setFocus(): Promise<void> {
await componentFocusable(this);

this.el?.focus();
focusFirstTabbable(this.el);
}

// --------------------------------------------------------------------------
Expand Down

0 comments on commit 1a9c15c

Please sign in to comment.