Skip to content

Commit 4b4c6e2

Browse files
committed
Refactor focus management in MobileNavigation component
- Updated focus handling to ensure the first focusable element is only queried if the current target is a valid Element, improving accessibility and keyboard navigation.
1 parent 1493493 commit 4b4c6e2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/components/ui/mobile-navigation.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ export function MobileNavigation({ showWalletMenu, isLoggedIn, walletId, fallbac
133133
}
134134
// Focus the first focusable element in the sheet content
135135
e.preventDefault();
136-
const firstFocusable = e.currentTarget.querySelector('a, button, [tabindex]:not([tabindex="-1"])');
137-
if (firstFocusable && firstFocusable instanceof HTMLElement) {
138-
firstFocusable.focus();
136+
if (e.currentTarget && e.currentTarget instanceof Element) {
137+
const firstFocusable = e.currentTarget.querySelector('a, button, [tabindex]:not([tabindex="-1"])');
138+
if (firstFocusable && firstFocusable instanceof HTMLElement) {
139+
firstFocusable.focus();
140+
}
139141
}
140142
}}
141143
onInteractOutside={(e) => {

0 commit comments

Comments
 (0)