Skip to content
Prev Previous commit
Next Next commit
chore(page): dynamic focus on title/content
  • Loading branch information
Aslam97 committed Sep 11, 2024
commit 960dc761e1f0c877cdfefd07d0e43e480ac4fa6b
10 changes: 8 additions & 2 deletions web/components/routes/page/detail/PageDetailRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {

const titleEditor = useEditor({
immediatelyRender: false,
autofocus: true,
autofocus: false,
extensions: [
FocusClasses,
Paragraph,
Expand Down Expand Up @@ -245,7 +245,13 @@ const DetailPageForm = ({ page }: { page: PersonalPage }) => {
useEffect(() => {
isTitleInitialMount.current = true
isContentInitialMount.current = true
}, [])

if (!page.title) {
titleEditor?.commands.focus()
} else {
contentEditorRef.current?.editor?.commands.focus()
}
}, [page.title, titleEditor, contentEditorRef])

return (
<div className="relative flex grow flex-col overflow-y-auto [scrollbar-gutter:stable]">
Expand Down