Skip to content

fix(staff): close staff modal on Escape key - #1136

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-issue-1098-r1
Oct 14, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-issue-1098-r1

Conversation

@khaira777

@khaira777 khaira777 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1098

Intent

Verify and implement the surgical fix for FreeOpenSourcePOS/FloCafe issue #1098 ("Staff modal dialog does not close on Escape key"): in frontend/src/app/(dashboard)/staff/page.tsx, handle Escape key presses while the Staff create/edit modal is open so pressing Escape closes the modal cleanly. Deliver via the no-mistakes pipeline as its own PR with Fixes #1098 in the PR summary.

Address all review comments on PR #1136 before merging:

  1. The Reset Password modal is controlled by showResetPw, but the new Escape listener only handles showForm. Make sure Escape also closes the Reset Password modal, without changing its password-reset behavior.
  2. Restore keyboard focus to the button that opened the modal when it closes: return focus to the original Add Staff trigger, Edit Staff trigger, or Reset Password trigger when the respective modal closes.
  3. Extend the browser tests to verify: Escape closes Add Staff, Escape closes Edit Staff, Escape closes Reset Password, focus returns to the correct trigger after closing, non-Escape keys do not dismiss a modal, and keyboard listeners are cleaned up and do not accumulate across repeated opens.
  4. Remove the #1098 reference and redundant step-description comments from tests/auth-ui-deterministic.test.ts to comply with AGENTS.md.

What Changed

  • Attach a keydown listener in frontend/src/app/(dashboard)/staff/page.tsx while the create/edit Staff modal (showForm) or Reset Password modal (showResetPw) is open so pressing Escape closes the active dialog and cleans up the listener.
  • Track the originating Add Staff, Edit Staff, and Reset Password trigger elements via refs, restore keyboard focus to the corresponding button when its modal closes, and add role="dialog", aria-modal="true", and aria-labelledby="reset-password-modal-title" to the Reset Password modal container.
  • Add deterministic unit coverage in tests/auth-ui-deterministic.test.ts and Playwright E2E coverage in frontend/e2e/layout-integrity.spec.ts verifying Escape dismissal, non-Escape key preservation, trigger focus restoration, and listener cleanup across repeated modal open/close cycles.

Fixes #1098

Risk Assessment

✅ Low: The change is a small, well-bounded UI update that closes the Staff and Reset Password modals on Escape, restores focus to the originating trigger button, and covers the behavior in deterministic and browser E2E tests.

Testing

Ran the deterministic auth/staff UI test suite (npm run test:auth-ui-deterministic), built the backend and static frontend (npm run build && npm run build:frontend), executed the Playwright browser E2E test (e2e/layout-integrity.spec.ts -g "staff modals close on Escape"), and drove a live Chromium session against tests/e2e-server.cjs to capture visual screenshots and verify focus restoration, listener cleanup, and Reset Password PUT /api/staff/:id submission; all checks and scenarios passed.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Pressing Escape while the Add Staff modal is open closes the dialog and restores keyboard focus to the Add Staff button ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape" and `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TT…
Pressing Escape while the Edit Staff modal is open closes the dialog and restores keyboard focus to the Edit button for that staff row ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape" and `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TT…
Pressing Escape while the Reset Password modal is open closes the dialog and restores keyboard focus to the Reset PW button without altering normal password-reset submission behavior ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape", `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TTC9R…
Pressing non-Escape keys (character keys, Tab, ArrowLeft, Backspace, Enter) inside Add Staff, Edit Staff, or Reset Password modals leaves the modal open ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape" and `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TT…
Repeatedly opening and closing Add Staff, Edit Staff, and Reset Password modals cleans up window keydown listeners on close and never accumulates listeners ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape", npm run test:auth-ui-deterministic, and `~/…

Add Staff modal open after typing and pressing Tab (non-Escape keys do not dismiss)
Add Staff modal closed on Escape with focus restored to Add Staff button
Edit Staff modal open after pressing ArrowLeft (non-Escape keys do not dismiss)
Edit Staff modal closed on Escape with focus restored to Edit button
Reset Password modal open after typing and pressing Enter (non-Escape keys do not dismiss)
Reset Password modal closed on Escape with focus restored to Reset PW button

Evidence: Live Playwright focus restoration, listener count, and Reset Password submission verification

{ "baselineListeners": 2, "finalListeners": 2, "focusAfterAdd": { "tag": "BUTTON", "text": "Add Staff" }, "focusAfterEdit": { "tag": "BUTTON", "text": "Edit" }, "focusAfterResetEscape": { "tag": "BUTTON", "text": "Reset PW" }, "focusAfterResetSubmit": { "tag": "BUTTON", "text": "Reset PW" }, "resetPasswordPutStatus": 200 }

{
  "baselineListeners": 2,
  "finalListeners": 2,
  "focusAfterAdd": {
    "tag": "BUTTON",
    "text": "Add Staff"
  },
  "focusAfterEdit": {
    "tag": "BUTTON",
    "text": "Edit"
  },
  "focusAfterResetEscape": {
    "tag": "BUTTON",
    "text": "Reset PW"
  },
  "focusAfterResetSubmit": {
    "tag": "BUTTON",
    "text": "Reset PW"
  },
  "resetPasswordPutStatus": 200
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ frontend/src/app/(dashboard)/staff/page.tsx - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Pressing Escape while the Add Staff modal is open closes the dialog and restores keyboard focus to the Add Staff button ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape" and `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TT…
Pressing Escape while the Edit Staff modal is open closes the dialog and restores keyboard focus to the Edit button for that staff row ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape" and `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TT…
Pressing Escape while the Reset Password modal is open closes the dialog and restores keyboard focus to the Reset PW button without altering normal password-reset submission behavior ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape", `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TTC9R…
Pressing non-Escape keys (character keys, Tab, ArrowLeft, Backspace, Enter) inside Add Staff, Edit Staff, or Reset Password modals leaves the modal open ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape" and `~/.no-mistakes/evidence/01M4W2AJ4KFGMH9TT…
Repeatedly opening and closing Add Staff, Edit Staff, and Reset Password modals cleans up window keydown listeners on close and never accumulates listeners ✅ pass live npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape", npm run test:auth-ui-deterministic, and `~/…
  • npm run test:auth-ui-deterministic
  • npm run build && npm run build:frontend
  • npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "staff modals close on Escape"
  • node -e "...live Playwright verification with screenshots and Reset Password PUT check against tests/e2e-server.cjs..."
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c6083ed2-606f-4e0f-b459-84e840288b85

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Staff modal now closes when user presses Escape key.

The Escape behavior appears safe, but the new test comments must follow the repository’s explicit comment rule before merging.

Findings

  1. P2 Comments break repository rules ▶

Summary

The PR makes Escape close the Add Staff and Edit Staff dialogs through the existing closeForm handler.

  • Escape closes the Add Staff and Edit Staff forms.

Reviews (1) · Last reviewed commit: "fix(staff): close staff modal on Escape ..." · Reviewed by Greptile

Comment thread tests/auth-ui-deterministic.test.ts Resolved
@khaira777

Copy link
Copy Markdown
Contributor Author

The Escape handler correctly closes the Add Staff and Edit Staff modals, and the listener cleanup looks sound. However, I found additional gaps when checking the Staff page and the linked issue's accessibility requirements.

Please address these before merging:

  1. The Reset Password modal is controlled by showResetPw, but the new Escape listener only handles showForm. Please make sure Escape also closes the Reset Password modal, without changing its password-reset behavior.

  2. Restore keyboard focus to the button that opened the modal when it closes. The current implementation hides the dialog but does not return focus to the original Add Staff or Edit Staff trigger. Please handle Reset Password focus restoration too.

  3. Extend the browser tests to verify:

    • Escape closes Add Staff.
    • Escape closes Edit Staff.
    • Escape closes Reset Password.
    • Focus returns to the correct trigger after closing.
    • Non-Escape keys do not dismiss a modal.
    • Keyboard listeners are cleaned up and do not accumulate across repeated opens.
  4. Remove the #1098 reference and redundant step-description comments from tests/auth-ui-deterministic.test.ts to comply with AGENTS.md.

Reuse existing modal or focus-management patterns where practical. Keep the implementation focused on Staff modal keyboard behavior, preserve all existing form and password-reset functionality, and run the relevant unit and Playwright tests.

Please report the results before merging. No unrelated changes or refactoring.

@khaira777
khaira777 force-pushed the fm/flocafe-issue-1098-r1 branch from 7a0031c to 9911962 Compare October 14, 2026 02:16
@khaira777 khaira777 changed the title fix(staff): close staff modal on Escape key fix(staff): close staff modals on Escape and restore trigger focus Oct 14, 2026
@khaira777 khaira777 changed the title fix(staff): close staff modals on Escape and restore trigger focus fix(staff): close staff modal on Escape key Oct 14, 2026
Register a window keydown listener while the Staff create/edit modal is open so pressing Escape closes the modal via closeForm().

Fixes #1098
@khaira777
khaira777 force-pushed the fm/flocafe-issue-1098-r1 branch from 9911962 to 3e0a6fc Compare October 14, 2026 02:28
@khaira777
khaira777 enabled auto-merge (squash) October 14, 2026 02:28
@khaira777
khaira777 merged commit b2d2b06 into main Oct 14, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-issue-1098-r1 branch October 14, 2026 02:35
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.

fix(a11y): bind Escape key listener to dismiss back-office modal dialogs

1 participant