Skip to content

Navya/fix/modal focus effect split - #587

Open
navyamidha95339-arch wants to merge 2 commits into
mainfrom
navya/fix/modal-focus-effect-split
Open

Navya/fix/modal focus effect split#587
navyamidha95339-arch wants to merge 2 commits into
mainfrom
navya/fix/modal-focus-effect-split

Conversation

@navyamidha95339-arch

Copy link
Copy Markdown
Collaborator

Modal: split focus-on-open effect from keydown/focus-trap (AP-029)
Summary
Fixes a bug in the shared Modal component where a parent re-render while the modal is open (which creates a new inline onClose function) would re-run the whole effect and re-steal focus back to the first focusable element — even if the user had since focused something else inside the modal.

Checklist

✅ Focus-on-open in its own [open]-only effect
✅ Keydown + focus-trap in a separate effect (still keyed on [open, onClose] to use the latest onClose, but doesn't touch focus)
✅ Focus restored to the previously-focused element on close
✅ Regression-tested existing modals — ran the full test suite; all Modal-dependent tests pass. One pre-existing, unrelated failure in ProtectedRoute.test.jsx (hasExpiredToken is not a function) — not touched by this change.
Evidence
Added tests to Modal.test.jsx:

Parent re-render with a new inline onClose does not move focus away from whatever the user has focused
Focus is still restored to the previously-focused element on close

Note: While rebasing onto latest main, found main already had a very similar effect split from another recent commit — this PR keeps the more descriptive comments/eslint-disable from my original work and adds the regression tests, which weren't present before.

…(AP-029)

- Focus-on-open now runs only on [open] change, so a parent re-render
  with a new inline onClose no longer re-steals focus
- Keydown/focus-trap listener stays on [open, onClose] to use the
  latest onClose, without touching focus itself
- Added regression tests: parent re-render doesn't move focus,
  focus still restores to the previously-focused element on close
- Note: ran full test suite as regression check — 1 pre-existing
  unrelated failure in ProtectedRoute.test.jsx (hasExpiredToken),
  not touched by this change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant