Skip to content

Commit

Permalink
feat: add autofocus for create post modal
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jan 16, 2024
1 parent cf73278 commit 0b2b654
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/posts/editor/HtmlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface HTMLEditorProps {
saveBodyDraft?: (body: string) => void
className?: string
showToolbar?: boolean
autoFocus?: boolean
}

export default function HtmlEditor({
Expand All @@ -16,13 +17,14 @@ export default function HtmlEditor({
saveBodyDraft,
className,
showToolbar,
autoFocus,
}: HTMLEditorProps) {
const editor = useCreateEditor(onChange, value, saveBodyDraft)

return (
<>
{showToolbar && <ToolBar editor={editor} />}
<EditorContent tabIndex={0} className={className} editor={editor} />
<EditorContent autoFocus tabIndex={0} className={className} editor={editor} />
</>
)
}
6 changes: 5 additions & 1 deletion src/components/posts/editor/ModalEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ export const PostEditorModalBody = ({
<SpaceSelector />
<Form.Item name={fieldName('body')} className='my-3'>
{/* value and onChange are provided by Form.Item */}
<HtmlEditor saveBodyDraft={saveDraft} className={clsx(styles.FastEditor, 'ant-input')} />
<HtmlEditor
autoFocus
saveBodyDraft={saveDraft}
className={clsx(styles.FastEditor, 'ant-input')}
/>
</Form.Item>
{imgUrl && (
<PreviewUploadedImage
Expand Down

0 comments on commit 0b2b654

Please sign in to comment.