2016-07-11 15:59:00 -07:00
# `<Editor>`
2016-07-11 13:19:39 -07:00
2016-07-11 15:53:26 -07:00
```js
2017-09-11 18:11:45 -07:00
import { Editor } from 'slate-react'
2016-07-11 15:53:26 -07:00
```
2016-07-11 13:19:39 -07:00
The top-level React component that renders the Slate editor itself.
2017-10-27 13:39:06 -07:00
## Props
2016-07-11 13:22:41 -07:00
```js
< Editor
2017-08-17 19:24:31 +02:00
autoCorrect={Boolean}
autoFocus={Boolean}
className={String}
2018-10-09 14:03:27 -07:00
commands={Object}
2016-07-11 13:19:39 -07:00
onChange={Function}
2018-10-09 14:03:27 -07:00
placeholder={String | Element}
2016-07-11 13:19:39 -07:00
plugins={Array}
2018-10-09 14:03:27 -07:00
queries={Object}
2016-07-17 15:57:27 -07:00
readOnly={Boolean}
2017-08-17 19:24:31 +02:00
role={String}
2018-10-09 14:03:27 -07:00
schema={Object}
2017-08-17 19:24:31 +02:00
spellCheck={Boolean}
2017-10-27 13:39:06 -07:00
value={Value}
2016-07-11 19:28:35 -07:00
style={Object}
2017-08-17 19:24:31 +02:00
tabIndex={Number}
2016-07-11 13:19:39 -07:00
/>
```
2017-08-17 19:24:31 +02:00
### `autoCorrect`
2018-02-07 15:58:41 +00:00
2017-08-17 19:24:31 +02:00
`Boolean`
2018-06-12 10:42:09 -07:00
Whether or not the editor should attempt to autocorrect spellcheck errors.
2017-08-17 19:24:31 +02:00
### `autoFocus`
2018-02-07 15:58:41 +00:00
2017-08-17 19:24:31 +02:00
`Boolean`
2018-06-12 10:42:09 -07:00
Whether or not the editor should attempt to give the contenteditable element focus when it's loaded onto the page.
2017-08-17 19:24:31 +02:00
2017-01-19 02:29:37 +01:00
### `className`
2018-02-07 15:58:41 +00:00
2016-07-12 11:23:07 -07:00
`String`
2016-07-11 19:28:35 -07:00
2018-06-12 10:42:09 -07:00
An optional class name to apply to the contenteditable element.
2016-07-11 19:28:35 -07:00
2016-07-12 11:23:07 -07:00
### `onChange`
2018-02-07 15:58:41 +00:00
2017-09-05 18:03:41 -07:00
`Function onChange(change: Change)`
2016-07-11 13:38:45 -07:00
2017-10-27 13:39:06 -07:00
A change handler that will be called with the `change` that applied the change. You should usually pass the newly changed `change.value` back into the editor through its `value` property. This hook allows you to add persistence logic to your editor.
2016-07-11 13:38:45 -07:00
2017-10-27 14:50:27 -07:00
### `placeholder`
2018-02-07 15:58:41 +00:00
2017-10-27 14:50:27 -07:00
`String || Element`
A placeholder string (or React element) that will be rendered as the default block type's placeholder.
2016-07-12 11:23:07 -07:00
### `plugins`
2018-02-07 15:58:41 +00:00
2016-07-12 11:23:07 -07:00
`Array`
2016-07-11 19:28:35 -07:00
2017-09-11 18:11:45 -07:00
An array of [`Plugins` ](./plugins.md ) that define the editor's behavior.
2016-07-11 19:28:35 -07:00
2016-07-17 15:57:27 -07:00
### `readOnly`
2018-02-07 15:58:41 +00:00
2016-07-17 15:57:27 -07:00
`Boolean`
Whether the editor should be in "read-only" mode, where all of the rendering is the same, but the user is prevented from editing the editor's content.
2017-08-17 19:24:31 +02:00
### `role`
2018-02-07 15:58:41 +00:00
2017-08-17 19:24:31 +02:00
`String`
ARIA property to define the role of the editor, it defaults to `textbox` when editable.
2017-10-27 14:50:27 -07:00
### `spellCheck`
2018-02-07 15:58:41 +00:00
2017-10-27 14:50:27 -07:00
`Boolean`
2016-07-11 19:28:35 -07:00
2018-06-12 10:42:09 -07:00
Whether or not spellcheck is turned on for the editor.
2016-07-11 19:28:35 -07:00
2016-07-12 11:23:07 -07:00
### `style`
2018-02-07 15:58:41 +00:00
2016-07-12 11:23:07 -07:00
`Object`
2016-07-11 19:28:35 -07:00
2018-06-12 10:42:09 -07:00
An optional dictionary of styles to apply to the contenteditable element.
2016-07-11 19:28:35 -07:00
2017-01-19 02:29:37 +01:00
### `tabIndex`
2018-02-07 15:58:41 +00:00
2017-08-17 19:24:31 +02:00
`Number`
2017-01-19 02:29:37 +01:00
Indicates if it should participate to [sequential keyboard navigation ](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex ).
2017-10-27 14:50:27 -07:00
### `value`
2018-02-07 15:58:41 +00:00
2017-10-27 14:50:27 -07:00
`Value`
2016-07-11 18:58:00 -07:00
2017-10-27 14:50:27 -07:00
A [`Value` ](../slate/value.md ) object representing the current value of the editor.
2016-07-11 18:58:00 -07:00
2017-10-27 13:39:06 -07:00
## Plugin-like Props
2016-07-11 13:47:28 -07:00
2017-09-11 18:11:45 -07:00
In addition to its own properties, the editor allows passing any of the properties that a [plugin ](./plugins.md ) defines as well.
2016-07-11 13:47:28 -07:00
2017-01-19 02:29:37 +01:00
These properties are actually just a convenience—an implicit plugin definition. Internally, they are grouped together and turned into a plugin that is given first priority in the plugin stack.
2016-07-11 13:47:28 -07:00
For example, these two snippets of code are equivalent:
2016-07-11 13:31:08 -07:00
```js
2016-07-11 13:49:02 -07:00
const plugins = [
somePlugin
]
2016-07-11 13:33:46 -07:00
2016-07-11 13:31:08 -07:00
< Editor
2016-07-11 13:38:45 -07:00
onKeyDown={myKeyHandler}
2016-07-11 13:33:46 -07:00
plugins={plugins}
2017-10-27 13:39:06 -07:00
value={value}
2016-07-11 13:31:08 -07:00
/>
```
```js
2016-07-11 13:35:34 -07:00
const editorPlugin = {
2017-01-19 02:29:37 +01:00
onKeyDown: myKeyHandler
2016-07-11 13:35:34 -07:00
}
2016-07-11 13:31:08 -07:00
const plugins = [
2016-07-11 13:35:34 -07:00
editorPlugin,
somePlugin
2016-07-11 13:31:08 -07:00
]
< Editor
plugins={plugins}
2017-10-27 13:39:06 -07:00
value={value}
2016-07-11 13:31:08 -07:00
/>
```
2016-07-11 13:19:39 -07:00
2016-07-22 17:15:46 -07:00
### `onBeforeInput`
2018-02-07 15:58:41 +00:00
2016-07-28 17:36:32 -07:00
### `onBlur`
2018-02-07 15:58:41 +00:00
2017-03-19 05:40:22 +05:45
### `onFocus`
2018-02-07 15:58:41 +00:00
2016-07-28 17:36:32 -07:00
### `onCopy`
2018-02-07 15:58:41 +00:00
2016-07-28 17:36:32 -07:00
### `onCut`
2018-02-07 15:58:41 +00:00
2016-07-22 17:15:46 -07:00
### `onDrop`
2018-02-07 15:58:41 +00:00
2016-07-22 17:15:46 -07:00
### `onKeyDown`
2018-02-07 15:58:41 +00:00
2017-08-25 15:24:15 +10:00
### `onKeyUp`
2018-02-07 15:58:41 +00:00
2016-07-22 17:15:46 -07:00
### `onPaste`
2018-02-07 15:58:41 +00:00
2016-07-28 17:36:32 -07:00
### `onSelect`
2018-02-07 15:58:41 +00:00
2016-08-14 18:29:00 -07:00
### `schema`
2016-07-22 17:15:46 -07:00
2017-09-11 18:11:45 -07:00
To see how these properties behave, check out the [Plugins reference ](./plugins.md ).