Repository navigation
refactor(menu): a separator is not something you can click - #614
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #336.
MenuItemwas one interface with an optionalseparator, 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.
ContextMenurenders 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: booleanand stops matching the union. Worth the explicit type to keep the guarantee.Verification
Unit 2036, browser 297, 0 lint errors.