Skip to content

Commit 4a068c2

Browse files
authored
fix(input-date-picker): bump focus-trap to pick up shadow DOM focus-handling fix (#14381)
**Related Issue:** #14174 ## Summary Picks up the fix for focus-trap/focus-trap#1885 from [`focus-trap`](https://github.com/focus-trap/focus-trap/releases/tag/v8.2.1).
1 parent bcdc970 commit 4a068c2

5 files changed

Lines changed: 50 additions & 15 deletions

File tree

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"color": "^5.0.3",
8282
"composed-offset-position": "^0.0.6",
8383
"es-toolkit": "^1.39.8",
84-
"focus-trap": "^8.0.1",
84+
"focus-trap": "^8.2.1",
8585
"interactjs": "^1.10.27",
8686
"lit": "^3.3.0",
8787
"sortablejs": "^1.15.6",

packages/components/src/components/combobox/combobox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,8 +1643,8 @@ export class Combobox extends LitElement implements LabelableComponent, Floating
16431643
key={item.guid || item.value || label}
16441644
label={label}
16451645
messageOverrides={!disabled ? { dismissLabel: messages.removeTag } : null}
1646-
onFocusIn={!disabled ? () => (this.activeChipIndex = index) : null}
16471646
oncalciteChipClose={!disabled ? () => this.calciteChipCloseHandler(item) : null}
1647+
onFocusIn={!disabled ? () => (this.activeChipIndex = index) : null}
16481648
scale={scale}
16491649
selected={item.selected}
16501650
tabIndex={!disabled && activeChipIndex === index ? 0 : -1}

packages/components/src/components/dialog/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,9 @@ export class Dialog extends LitElement implements OpenCloseComponentWithEl {
838838
loading={this.loading}
839839
menuOpen={this.menuOpen}
840840
messageOverrides={this.messageOverrides}
841-
onKeyDown={this.handlePanelKeyDown}
842841
oncalcitePanelClose={this.handleInternalPanelCloseClick}
843842
oncalcitePanelScroll={this.handleInternalPanelScroll}
843+
onKeyDown={this.handlePanelKeyDown}
844844
overlayPositioning={this.overlayPositioning}
845845
ref={this.panelRef}
846846
scale={this.scale}

packages/components/src/components/input-date-picker/input-date-picker.browser.e2e.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { h } from "@arcgis/lumina";
1+
import { h, JsxNode, LitElement } from "@arcgis/lumina";
22
import { describe, it, expect } from "vitest";
33
import { mount } from "@arcgis/lumina-compiler/testing";
4+
import { page, userEvent } from "vitest/browser";
45
import {
56
defaults,
67
focusable,
@@ -15,7 +16,8 @@ import {
1516
} from "../../tests/commonTests/browser";
1617
import { mockConsole } from "../../tests/utils/logging";
1718
import { defaultValidity } from "../../tests/commonTests/browser/defaults";
18-
import { InputDatePicker } from "./input-date-picker";
19+
import { afterNextTask } from "../../tests/utils/timing";
20+
import type { InputDatePicker } from "./input-date-picker";
1921

2022
describe("defaults", () => {
2123
defaults(
@@ -119,6 +121,39 @@ describe("is form-associated", () => {
119121
});
120122
});
121123

124+
describe("focus-trap behavior", () => {
125+
mockConsole();
126+
127+
it("restores focus to input-date-picker after closing when inside a focus-trapping parent in shadow DOM", async () => {
128+
const dialogTestId = "test-dialog";
129+
const pickerTestId = "test-picker";
130+
131+
class Test extends LitElement {
132+
render(): JsxNode {
133+
return (
134+
<calcite-dialog data-testid={dialogTestId} open>
135+
<calcite-input-date-picker data-testid={pickerTestId} value="2024-05-05" />
136+
</calcite-dialog>
137+
);
138+
}
139+
}
140+
141+
await mount(Test);
142+
const picker = page.getByTestId(pickerTestId);
143+
144+
await userEvent.click(picker);
145+
await userEvent.keyboard("{Tab}{Enter}");
146+
147+
// focus-trap delays focus handling by default -- https://github.com/focus-trap/focus-trap/#delayinitialfocus
148+
await afterNextTask();
149+
150+
expect(document).toHaveProperty(
151+
"activeElement.shadowRoot.activeElement.dataset.testid",
152+
pickerTestId,
153+
);
154+
});
155+
});
156+
122157
describe("minAsDate and maxAsDate properties", () => {
123158
it("honors minAsDate and maxAsDate properties by updating out-of-range value to the closest valid value", async () => {
124159
const { el, component } = await mount<InputDatePicker>(

0 commit comments

Comments
 (0)