Skip to content

Commit 6e04b27

Browse files
Add test
1 parent 232d5df commit 6e04b27

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

packages/web-components/fast-foundation/src/toolbar/toolbar.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,56 @@ describe("Toolbar", () => {
259259

260260
await disconnect();
261261
});
262+
263+
it("should handle focusin when focusableElements becomes undefined", async () => {
264+
const { element, connect, disconnect, document, startButton } = await setup();
265+
266+
await connect();
267+
268+
const tempButton = document.createElement('button');
269+
document.body.appendChild(tempButton);
270+
tempButton.focus();
271+
await DOM.nextUpdate();
272+
273+
expect(document.activeElement).to.equal(tempButton);
274+
275+
Reflect.set(element as object, "focusableElements", undefined);
276+
await DOM.nextUpdate();
277+
278+
startButton.focus();
279+
await DOM.nextUpdate();
280+
281+
expect(document.activeElement).to.equal(startButton);
282+
283+
tempButton.remove();
284+
await disconnect();
285+
});
286+
287+
it("should handle keydown when focusableElements becomes undefined", async () => {
288+
const { element, connect, disconnect, document, startButton } = await setup();
289+
290+
await connect();
291+
292+
const tempButton = document.createElement("button");
293+
document.body.appendChild(tempButton);
294+
tempButton.focus();
295+
await DOM.nextUpdate();
296+
297+
expect(document.activeElement).to.equal(tempButton);
298+
299+
startButton.focus();
300+
await DOM.nextUpdate();
301+
302+
Reflect.set(element as object, "reduceFocusableElements", () => undefined);
303+
Reflect.set(element as object, "focusableElements", undefined);
304+
await DOM.nextUpdate();
305+
306+
pressRightArrowKey(element);
307+
await DOM.nextUpdate();
308+
309+
expect(document.activeElement).to.equal(startButton);
310+
311+
tempButton.remove();
312+
await disconnect();
313+
});
262314
});

packages/web-components/fast-foundation/src/toolbar/toolbar.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ export class Toolbar extends FoundationElement {
157157
public connectedCallback() {
158158
super.connectedCallback();
159159
this.direction = getDirection(this);
160-
if (!this.slottedItems?.length && !this.childItems?.length) {
161-
this.reduceFocusableElements();
162-
}
163160
}
164161

165162
/**
@@ -225,7 +222,7 @@ export class Toolbar extends FoundationElement {
225222
protected get allSlottedItems(): (HTMLElement | Node)[] {
226223
return [
227224
...this.start.assignedElements(),
228-
...(this.slottedItems ?? []),
225+
...this.slottedItems,
229226
...this.end.assignedElements(),
230227
];
231228
}

0 commit comments

Comments
 (0)