Conversation
In order to show developers how to intercept tldraw's Tab-based shape navigation and redirect focus to custom UI, this PR adds a new example demonstrating a focus trap pattern with a contextual toolbar. The example registers a capture-phase `keydown` listener in `onMount` that intercepts Tab before tldraw's own handler, redirecting focus between the canvas and a contextual toolbar. It also handles Shift+Tab cycling and Escape to return focus to the canvas. Relates to #2549 ### Change type - [x] `other` ### Test plan 1. Open the "Escape shape focus trap" example 2. Click on the geo shape to select it 3. Press Tab — focus should move to the first toolbar button (Duplicate) 4. Press Tab again — focus moves to the Delete button 5. Press Tab again — focus returns to the canvas 6. Press Shift+Tab to cycle backwards through toolbar buttons 7. Press Escape while focused in the toolbar — focus returns to the canvas ### Release notes - Add example showing how to intercept Tab navigation to focus a custom contextual toolbar ### Code changes | Section | LOC change | | ------------- | ---------- | | Documentation | +220 / -0 | <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: adds a self-contained UI example and docs demonstrating keyboard focus handling without changing core library behavior. > > **Overview** > Adds a new `escape-shape-focus-trap` UI example that renders a contextual toolbar for selected shapes and uses a capture-phase `keydown` listener to override tldraw’s Tab-based shape navigation. > > The example demonstrates trapping `Tab`/`Shift+Tab` within toolbar buttons, restoring focus back to the canvas at the ends of the cycle, and handling `Escape` to return focus, with accompanying README guidance. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit af19804. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )