SIGN IN SIGN UP

Give a modal the keyboard focus before it appears (#2522)

FocusLayer moves the focus in a setTimeout, since a layer is usually
created while its element is still being built and cannot take focus
until it is attached. That left a window in which the dialog was on
screen without the focus. A key pressed then went to whatever was
focused before, and for a nested modal the parent's tab trap sent the
focus back to the opening button. This is the projects modals test
failing now and then on CI.

modal() now focuses the dialog itself, right after attaching it.
removeLayer() does the same on the way out: when the focus has fallen to
the body it restores it synchronously rather than a tick later, so
closing a nested modal hands the focus straight back to its parent. That
second part applies to every FocusLayer, not only modals, in the case
where its element left the page and took the focus with it.

Checked by setting both of FocusLayer's timers to 250ms and showing
consistent failure of the old code and success with the new. The
AttachmentsWidget test naturally tests the removeLayer part since its
editor is both a cell editor and a modal.
P
Paul Fitzpatrick committed
4f0b3056321067f39139678438c84454444c43b7
Parent: 806f446
Committed by GitHub <noreply@github.com> on 8/17/2026, 4:40:13 PM