Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal/FocusTrap: useLayoutEffect #357

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tasty-clocks-rule.md
@@ -0,0 +1,6 @@
---
"@cambly/syntax-core": minor
"@syntax/storybook": minor
---

Modal/FocusTrap: useLayoutEffect
4 changes: 2 additions & 2 deletions packages/syntax-core/src/Modal/FocusTrap.tsx
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, type ReactElement } from "react";
import React, { useRef, type ReactElement, useLayoutEffect } from "react";

function queryFocusableAll(el: HTMLDivElement): NodeListOf<HTMLElement> {
// Focusable, interactive elements that could possibly be in children
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function FocusTrap({
const elRef = useRef<HTMLDivElement | null>(null);
const previouslyFocusedElRef = useRef<HTMLElement | null>(null);

useEffect(() => {
useLayoutEffect(() => {
const { current: element } = elRef;

// Focus the first child element among all the focusable, interactive elements within `children`
Expand Down