Skip to content

Keep keyboard focus in the config store's delete confirmation - #177

Merged
YektaY merged 2 commits into
mainfrom
yektay/config-store-delete-focus
Nov 12, 2026
Merged

YektaY merged 2 commits into
mainfrom
yektay/config-store-delete-focus

Conversation

@YektaY

@YektaY YektaY commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Moved from slaclab/react-trace-archive#177. Its review history and CI runs stay in the archive.

Description

  • src/components/ConfigStoreModal.tsx:
    • The delete confirmation gets a config-store-delete-confirm class, and the store's ComposedModal lists it in selectorsFloatingMenus. The store's focus wrap then lets focus move into the confirmation, and the confirmation's own wrap keeps Tab inside it.
    • When the confirmation closes, focus goes back to the row's Delete button. After a delete, that row is gone (the list reloads), so focus goes to the store's scrollable body instead. The body now has aria-label="Config store", since it can receive focus.
  • src/components/ConfigStoreModal.test.tsx: a regression test for opening the confirmation and closing it with Escape, plus a focus check on the existing delete test.

Motivation

The delete confirmation is a second ComposedModal stacked over the store (from 9a93996). When it opened and focused its Cancel button, the store's Carbon focus wrap (handleBlur → wrapFocus) saw focus leave for an element after it in the DOM and moved it back to the store's first button, the Close (X) button. So with the dialog open:

  • focus stayed on the store's X behind the dialog, and its "Close" tooltip opened;
  • Tab moved through the store, so a keyboard user couldn't reach Cancel or Delete;
  • the first Escape only closed the tooltip.

Separately, closing the confirmation left focus on the hidden dialog, so the next Tab left the store for the page behind it.

Now, when the confirmation opens, focus is on Cancel (Carbon's default for danger modals). Tab and Shift+Tab cycle through Close, Cancel and Delete. One Escape closes the dialog, and focus returns to the store.

After Cancel or Escape, the row's Delete icon button gets focus back and Carbon shows its "Delete" tooltip, as it does for any focused icon button. Closing the store from there takes two Escapes, the same as before the confirmation opened.

About the test

jsdom differs from a browser here in three ways, and the test works around each one:

  • offsetParent is always null, and Carbon's focus wrap skips elements without one, so the store's wrap could never move focus. The test stubs it to parentElement.
  • When a blur handler moves focus, jsdom lets the outer focus() call win, while Chrome keeps the inner one. So activeElement ends on Cancel even without the fix. The test also checks that no focusin lands outside the confirmation, and that check fails without the fix.
  • scrollIntoView is missing. Carbon's modal calls it when focus moves inside a scrolling ModalBody, so it is stubbed for every test in the file.

Removing selectorsFloatingMenus fails the new test. Removing the focus-return effect fails both the new test and the delete test.

Overlap with #129

#129 (still open) rewrites ConfigStoreModal.tsx and keeps this dialog structure. Whichever PR merges second needs these four changes ported by hand: the class on the confirmation, selectorsFloatingMenus on the store, recording the Delete button that opened the confirmation, and the effect that returns focus when it closes.

Screenshots

Checked live against a local Canopy backend. Main: focus on the store's X, "Close" tooltip open, Tab cycling the store. This branch: focus on Cancel (with focus ring), Tab cycling within the confirmation, focus back on the row button after Escape and Cancel, and on the store body after a delete.

Pre-merge checklist

  • Code works interactively in the browser
  • New/changed components are covered in the test suite where possible
  • Test suite passes locally (npm test)
  • Linting passes (npm run lint)
  • Test suite passes on GitHub Actions

The delete confirmation is a second ComposedModal stacked over the store.
When it opened and focused its Cancel button, the store's focus wrap saw
focus leave for an element after it and pulled it back to the store's
Close button. Focus stayed behind the dialog with the Close tooltip open,
Tab cycled through the store, and the first Escape only closed the tooltip.

List the confirmation in the store's selectorsFloatingMenus so the store
lets focus move into it; the confirmation's own wrap keeps Tab inside it.
When the confirmation closes, return focus to the row's Delete button, or
to the store body after a delete removes that row, so Tab stays in the
store instead of escaping to the page behind it.
@YektaY
YektaY requested a review from a team as a code owner November 12, 2026 06:34

@jbellister-slac jbellister-slac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, no blocking issues, two small inline notes.

Checked locally by claude at 1ac39af against Carbon 1.108.0:

  • The store's blur handler skips its focus wrap when the new target matches selectorsFloatingMenus, so listing the confirmation's class there is the supported way to exempt it.
  • The focus-return cleanup runs after the commit that closes the confirmation, so the confirmation's own wrap is already off.
  • The test claims in the description hold: removing selectorsFloatingMenus fails the new test, and removing the focus return fails both the new test and the delete test.
  • Full suite (409 tests), pnpm lint and tsc -b pass.

Comment thread src/components/ConfigStoreModal.tsx Resolved
Comment thread src/components/ConfigStoreModal.tsx Resolved
Address review feedback on the delete-confirmation focus fix:

- When the confirmation closes, fall back to the store body if the row's
  Delete button is still connected but disabled, not only when it's gone.
  focus() on a disabled button does nothing, so focus would stay on the
  hidden confirmation if the list reload ever lands in a later render.
- Name the store's scrolling region "Config store contents" so it doesn't
  repeat the dialog title for screen reader users.
@YektaY
YektaY merged commit 54748ed into main Nov 12, 2026
5 checks passed
@YektaY
YektaY deleted the yektay/config-store-delete-focus branch November 12, 2026 23:53
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.

2 participants