tiptap/docs/api/commands/focus.md
Angad Sethi e9926438ea
docs: Typo in Focus Command Documentation of Editor (#2476)
A pretty small fix. The word `boolean` was misspelled.
2022-02-03 10:15:34 +01:00

34 lines
1012 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# focus
This command sets the focus back to the editor.
When a user clicks on a button outside the editor, the browser sets the focus to that button. In most scenarios you want to focus the editor then again. Thats why youll see that in basically every demo here.
See also: [setTextSelection](/api/commands/set-text-selection), [blur](/api/commands/blur)
## Parameters
`position: 'start' | 'end' | 'all' | number | boolean | null (false)`
By default, its restoring the cursor position (and text selection). Pass a position to move the cursor too.
`options: { scrollIntoView: boolean }`
Defines whether to scroll to the cursor when focusing. Defaults to `true`.
## Usage
```js
// Set the focus to the editor
editor.commands.focus()
// Set the cursor to the first position
editor.commands.focus('start')
// Set the cursor to the last position
editor.commands.focus('end')
// Selects the whole document
editor.commands.focus('all')
// Set the cursor to position 10
editor.commands.focus(10)
```