Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent pressing escape when editing document name to bubble up to the editor #3725

Merged
merged 1 commit into from
May 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/dotcom/src/components/DocumentName/DocumentName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
TldrawUiDropdownMenuRoot,
TldrawUiDropdownMenuTrigger,
TldrawUiKbd,
preventDefault,
stopEventPropagation,
track,
useActions,
useBreakpoint,
Expand Down Expand Up @@ -258,18 +260,20 @@ const DocumentNameEditor = track(function DocumentNameEditor({
const handleKeydownCapture = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'Enter') {
e.preventDefault()
preventDefault(e)
// blur triggers save
inputRef.current?.blur()
} else if (e.key === 'Escape') {
e.preventDefault()
preventDefault(e)
stopEventPropagation(e)
// revert to original name instantly so that when we blur we don't
// trigger a save with the new one
setState((prev) => ({ ...prev, name: null }))
inputRef.current?.blur()
editor.getContainer().focus()
Copy link
Member

Choose a reason for hiding this comment

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

(i've been staring at focus too long). i don't think we need this line - looks like just doing stopEventPropagation will do the trick 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it, but then the second escape did not switch back to the select tool 🤷 Keyboard shortcuts worked, but escape didn't.

Copy link
Member

Choose a reason for hiding this comment

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

ahh interesting interesting, didn't realize that! can you add a note that that's what the focus does? definitely we'll forget why we put that there later :)

}
},
[setState]
[setState, editor]
)

const handleBlur = useCallback(() => {
Expand Down