Improve Canvas Tab Support#399
Open
PauloMFJ wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces custom tab navigation for cards within the tldraw canvas, allowing users to seamlessly step through focusable card elements. It also refactors the focus trap utility and updates related CSS styles. The review feedback highlights several critical improvements: ensuring the capture-phase tab listener does not break custom interactive elements (like menus or dialogs), fixing a strict weak ordering violation in the card sorting logic, correctly targeting the last focusable element when navigating backwards with Shift+Tab, and excluding hidden inputs from the tabbable elements selector.
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.
Overview
Adds keyboard tab navigation through card content on the tldraw canvas, which tldraw normally swallows to cycle shape selection.
Changes
registerCardTabNavigation— a capture-phase Tab/Shift+Tab handler that steps through a flat list of every card's focusable elements in reading order (top-to-bottom, left-to-right), wrapping at the ends. It skips culled cards, stays out of the way of open dialogs and tldraw text editing, dives into the selected card when tabbing in from the canvas, and callsmarkEventAsHandledso tldraw ignores the event.AtlasProvider— registers on editor mount, cleans up on unmount.:focus-within(not just selection) so it's reachable via Tab.useFocusTrapimprovements — export and broadenTABBABLE_ELEMENTS(add inputs/selects/textareas, exclude disabled) for reuse; guard against non-HTMLElementactive elements.basenow sits afterprimitive. This was changed becausetldrawhas a defaultoutline: noneon*elements which was overriding ourbasestyle. Ourbaseis quite lean so this change is safe.