Skip to content

Commit 357b885

Browse files
authored
fix: Focus trap: remove delay when focusing on first/last item when wrapping focus (#4966)
* fix: Focus trap: remove delay when focusing on first/last item when wrapping focus * remove comment about delay, remove test clock ticks
1 parent f78aed3 commit 357b885

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

components/focus-trap/focus-trap.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ class FocusTrap extends FocusMixin(LitElement) {
117117
// user is exiting trap via forward tabbing...
118118
const firstFocusable = getNextFocusable(this.shadowRoot.querySelector('.d2l-focus-trap-start'));
119119
if (firstFocusable) {
120-
// Delay to re-apply the focus effects as a visual clue when there is only one focusable element
121-
setTimeout(() => firstFocusable.focus(), 50);
120+
firstFocusable.focus();
122121
return;
123122
}
124123
}
@@ -141,8 +140,7 @@ class FocusTrap extends FocusMixin(LitElement) {
141140
// user is exiting trap via back tabbing...
142141
const lastFocusable = getPreviousFocusable(this.shadowRoot.querySelector('.d2l-focus-trap-end'));
143142
if (lastFocusable) {
144-
// Delay to re-apply the focus effects as a visual clue when there is only one focusable element
145-
setTimeout(() => lastFocusable.focus(), 50);
143+
lastFocusable.focus();
146144
return;
147145
}
148146
}

components/focus-trap/test/focus-trap.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,12 @@ describe('d2l-focus-trap', () => {
106106
it('wraps to first', async() => {
107107
focusTrap.querySelector('#last').focus();
108108
focusTrap.shadowRoot.querySelector('.d2l-focus-trap-end').focus();
109-
clock.tick(50);
110109
expect(document.activeElement).to.equal(elem.querySelector('#first'));
111110
});
112111

113112
it('wraps to last', () => {
114113
focusTrap.querySelector('#first').focus();
115114
focusTrap.shadowRoot.querySelector('.d2l-focus-trap-start').focus();
116-
clock.tick(50);
117115
expect(document.activeElement).to.equal(elem.querySelector('#last'));
118116
});
119117

0 commit comments

Comments
 (0)