MoeraOrg / MoeraOrg/moera-issues

Trap focus in modal dialogs

Open
#415 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

client enhancement
Dominant language
No language data
Stars
20
Forks
0
PR merge metrics
No merged PRs in 30d

Description

focus-trap is de facto standard for trapping focus in modal dialogs. It may be added to ModalDialog with the following snippet:

useEffect(() => {
    if (modalDialog.current == null) {
        return () => {};
    }

    const trap = focusTrap.createFocusTrap(modalDialog.current, {
        allowOutsideClick: shadowClick,
        escapeDeactivates: onClose != null,
        preventScroll: false, // handled by useOverlay()
    });
    trap.activate();

    return () => trap.deactivate();
}, [onClose, shadowClick]);

But after that Tab navigation in some dialogs breaks and needs to be fixed in every dialog one-by-one.

Possibly, the modern approach would be to migrate to <dialog> and showModal().

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ModalDialog component and inspect how useOverlay() currently handles scrolling and focus. Evaluate the proposed focus-trap integration against each dialog, including the reported Tab-navigation failures, and compare it with the possible

and showModal() approach. Done means keyboard focus is correctly trapped and Tab navigation works in every dialog.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
accessibility, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.