# Telegram Web A focus trap

Source: [src/util/trapFocus.ts](https://github.com/Ajaxy/telegram-tt/blob/28ffcf710b15571e5a2f7bb3bdce3fc90fc8ec80/src/util/trapFocus.ts),
fixed official Web A commit `28ffcf710b15571e5a2f7bb3bdce3fc90fc8ec80`.
The actual caller is [src/components/ui/Modal.tsx](https://github.com/Ajaxy/telegram-tt/blob/28ffcf710b15571e5a2f7bb3bdce3fc90fc8ec80/src/components/ui/Modal.tsx),
which imports `trapFocus` and activates it while a modal is open. No nonexistent
`useFocusTrap` module or invented source path is cited.

`upstream-trapFocus.ts` is the complete unmodified source. It has no additional
file copyright notice; copyright remains with Ajaxy and upstream contributors.
`LICENSE` is the full unmodified upstream GPL version 3 license.

Modified by EssayPilot on 2026-10-02. `trap-focus.mjs` directly adapts the live
focusable query, current index lookup, forward/backward wrap and focus operation.
Changes: remove TypeScript/global event listener, inject document/window, use the
shared Telegram keyboard stack, ignore IME, exclude unavailable/disabled/inert
controls, include native details summaries, respect positive tabindex order,
prevent scrolling on focus, and handle an empty dialog/Shift-Tab from outside.
For a focused roving `tabindex=-1` item inside the dialog, continue from its DOM
position to the next/previous sequential control instead of the dialog edge.

`dialog-layer.mjs` supplies EssayPilot-specific lifecycle, dynamic-surface refresh,
background inert management, reference-counted scroll ownership, top-layer Esc,
nested topic-menu dismissal and focus restoration. It imports only the focus
adapter and the existing keyboard adapter; no Teact or chat dependencies.

This derived code is GPL-3.0-only and comes WITHOUT ANY WARRANTY. See LICENSE
and the root front-end source-distribution notice.
