Skip to content

Commit

Permalink
fix: allow focusing an empty editor
Browse files Browse the repository at this point in the history
Fixes #446
  • Loading branch information
petyosi committed May 4, 2024
1 parent 500b7ff commit e2585b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/examples/basics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export function Bare() {
)
}

export function FocusEmpty() {
const ref = React.useRef<MDXEditorMethods>(null)
return (
<>
<button onClick={() => ref.current?.focus()}>Focus</button>
<MDXEditor ref={ref} markdown="" placeholder="Hello..." onChange={console.log} />
</>
)
}

export function Placeholder() {
return (
<>
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,8 @@ export const corePlugin = realmPlugin<{
})

newEditor.update(() => {
const markdown = params?.initialMarkdown.trim()
if (markdown) {
tryImportingMarkdown(r, $getRoot(), markdown)
}
const markdown = params?.initialMarkdown.trim() ?? ''
tryImportingMarkdown(r, $getRoot(), markdown)

const autoFocusValue = params?.autoFocus
if (autoFocusValue) {
Expand Down

0 comments on commit e2585b8

Please sign in to comment.