Skip to content

Commit 6d4a983

Browse files
committed
fix(ui-a11y-utils): fix focus region skipping items after Drilldown/scrollbars
The core of the issue is that findFocusable cannot detect everything that can be focused reliably, e.g. browsers now focus on DOM elements that have scrollbars. The deleted code added the element with the scrollbar to the end of the focus region array, causing anything after it skipped when tabbing. The downside of deleting this code is that focus order breaks when the last element in a Popover/Modal is something that findFocusable does not detect e.g. a Menu (without a trigger, this is not detected because its tabIndex changes dynamically) Fixes INSTUI-4694
1 parent b94c875 commit 6d4a983

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

packages/ui-a11y-utils/src/scopeTab.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import {
2626
findDOMNode,
2727
findTabbable,
2828
isActiveElement,
29-
containsActiveElement,
30-
getActiveElement
29+
containsActiveElement
3130
} from '@instructure/ui-dom-utils'
3231
import type { UIElement } from '@instructure/shared-types'
3332

@@ -56,17 +55,13 @@ function scopeTab(
5655
return
5756
}
5857

59-
// Account for a changing tabindex of the active element
60-
// (a case that happens with Menu for KO a11y)
61-
if (containsActiveElement(element)) {
62-
const activeElement = getActiveElement()
63-
if (activeElement && tabbable.indexOf(activeElement) === -1) {
64-
tabbable.push(activeElement)
65-
}
66-
}
67-
6858
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1]
6959
const leavingFinalTabbable =
60+
// This can happen in Menu, where the first menu item becomes unfocusable
61+
// when its focused and tab is pressed, leaving one element
62+
// (the menu container) in the tabbable array, which is not the currently
63+
// active element
64+
tabbable.length < 2 ||
7065
isActiveElement(finalTabbable) ||
7166
// handle immediate shift+tab after opening with mouse
7267
isActiveElement(node) ||

regression-test/package-lock.json

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

regression-test/src/app/calendar/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ const Calendar = cl as any
3030
export default function CalendarPage() {
3131
return (
3232
<main className="flex gap-8 p-8 flex-col items-start axe-test">
33-
{/* Default config */}
34-
<Calendar />
35-
3633
{/* Default config with additional props */}
3734
<Calendar
3835
visibleMonth="2025-05"

regression-test/src/app/layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default function RootLayout({
3838
// we need to make a new Map to reset counting on the server side
3939
// on each page refresh TODO fix
4040
<html lang="en">
41+
<head>
42+
<title>Component visual and regression test suite</title>
43+
</head>
4144
<InstUISettingsProvider instanceCounterMap={new Map()}>
4245
<body className={inter.className}>{children}</body>
4346
</InstUISettingsProvider>

0 commit comments

Comments
 (0)