Skip to content

refactor(menu): a separator is not something you can click - #614

Merged
EVWorth merged 1 commit into
mainfrom
refactor/menuitem-separator-union
Sep 10, 2026
Merged

EVWorth merged 1 commit into
mainfrom
refactor/menuitem-separator-union

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Closes #336.

MenuItem was one interface with an optional separator, so every separator had to carry a meaningless label and an empty handler — twelve copies of { label: "", separator: true, onClick: () => {} } across the app.

It's a union now. A separator carries nothing, because it does nothing. All twelve call sites lost their no-ops.

The issue's premise was wrong

These aren't focus traps. ContextMenu renders a separator as a <div>, never a button, so nothing could ever focus one. The no-op handlers were noise, not a bug — the fix is to stop writing them, not to guard against them.

There's now a test asserting a separator stays out of the tab order, so the claim is checked rather than assumed.

A test that had stopped meaning anything

One existing test asserted the text "Separator" didn't appear as a button. No separator has a label any more, so that would pass whatever the component did. It now counts reachable items instead: four entries, one a separator, three buttons.

Two annotations

A separator inside a spread or a conditional array widens to separator: boolean and stops matching the union. Worth the explicit type to keep the guarantee.

Verification

Unit 2036, browser 297, 0 lint errors.

MenuItem was one interface with an optional `separator`, so every separator
had to carry a meaningless label and an empty handler — twelve copies of
`{ label: "", separator: true, onClick: () => {} }` across the app (#336).

It is a union now. A separator carries nothing, because it does nothing, and
the type says so. All twelve call sites lost their no-ops.

The issue called these focus traps. They are not: ContextMenu renders a
separator as a `<div>`, never a button, so nothing could ever focus one. The
no-op handlers were noise rather than a bug, and the fix is to stop writing
them rather than to guard against them. There is now a test asserting a
separator stays out of the tab order, so the claim is checked rather than
assumed.

One existing test asserted that the text "Separator" did not appear as a
button. No separator has a label any more, so that assertion would pass
whatever the component did. It now counts the reachable items instead:
four entries, one of them a separator, three buttons.

Two call sites needed an explicit type. A separator inside a spread or a
conditional array widens to `separator: boolean`, which stops matching the
union — worth the annotation to keep the guarantee.

Closes #336

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit e406560 into main Sep 10, 2026
12 checks passed
@EVWorth
EVWorth deleted the refactor/menuitem-separator-union branch September 10, 2026 11:22
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.

[P1/bug] Context menu separator entries are typed as onClick no-ops — focus traps

1 participant