1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 13:59:47 +01:00

187 lines
3.9 KiB
Markdown
Raw Normal View History

2016-07-11 13:19:39 -07:00
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
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.
2016-07-11 15:28:20 -07:00
2016-07-11 15:59:00 -07:00
## Properties
2016-07-11 13:22:41 -07:00
```js
<Editor
autoCorrect={Boolean}
autoFocus={Boolean}
className={String}
2016-07-11 13:19:39 -07:00
onChange={Function}
plugins={Array}
2016-07-17 15:57:27 -07:00
readOnly={Boolean}
role={String}
spellCheck={Boolean}
2016-07-11 13:19:39 -07:00
state={State}
style={Object}
tabIndex={Number}
2016-07-11 13:19:39 -07:00
/>
```
### `autoCorrect`
`Boolean`
Whether the editor should attempt to autocorrect spellcheck errors.
### `autoFocus`
`Boolean`
An optional attribute that, when set to true, attempts to give the content editable element focus when it's loaded onto the page.
### `className`
2016-07-12 11:23:07 -07:00
`String`
An optional class name to apply to the content editable element.
2016-07-12 11:23:07 -07:00
### `onChange`
`Function onChange(change: Change)`
2016-07-11 13:38:45 -07:00
A change handler that will be called with the `change` that applied the change. You should usually pass the newly changed `change.state` back into the editor through its `state` property. This hook allows you to add persistence logic to your editor.
2016-07-11 13:38:45 -07:00
2016-07-12 11:23:07 -07:00
### `plugins`
`Array`
An array of [`Plugins`](./plugins.md) that define the editor's behavior.
2016-07-17 15:57:27 -07:00
### `readOnly`
`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.
### `spellCheck`
`Boolean`
Whether spellcheck is turned on for the editor.
### `role`
`String`
ARIA property to define the role of the editor, it defaults to `textbox` when editable.
2016-07-12 11:23:07 -07:00
### `state`
`State`
A [`State`](../slate/state.md) object representing the current state of the editor.
2016-07-12 11:23:07 -07:00
### `style`
`Object`
An optional dictionary of styles to apply to the content editable element.
### `tabIndex`
`Number`
Indicates if it should participate to [sequential keyboard navigation](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex).
## Placeholder Properties
```js
<Editor
2016-07-11 19:29:21 -07:00
placeholder={String || Element}
placeholderClassName={String}
placeholderStyle={Object}
/>
```
2016-07-12 11:23:07 -07:00
### `placeholder`
`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
### `placeholderClassName`
`String`
An optional class name to apply to the default block type's placeholder.
2016-07-12 11:23:07 -07:00
### `placeholderStyle`
`Object`
An optional dictionary of styles to apply to the default block type's placeholder. If `placeholder` is a string, and no class name or style dictionary is passed, this property will default to `{ opacity: '0.333' }`.
2016-07-11 13:27:34 -07:00
2016-07-11 18:54:15 -07:00
## Plugin-like Properties
2016-07-11 13:47:28 -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
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}
2016-07-11 13:31:08 -07:00
state={state}
/>
```
```js
2016-07-11 13:35:34 -07:00
const editorPlugin = {
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}
state={state}
/>
```
2016-07-11 13:19:39 -07:00
2016-07-22 17:15:46 -07:00
### `onBeforeInput`
2016-07-28 17:36:32 -07:00
### `onBlur`
### `onFocus`
2016-07-28 17:36:32 -07:00
### `onCopy`
### `onCut`
2016-07-22 17:15:46 -07:00
### `onDrop`
### `onKeyDown`
### `onKeyUp`
2016-07-22 17:15:46 -07:00
### `onPaste`
2016-07-28 17:36:32 -07:00
### `onSelect`
2016-08-14 18:29:00 -07:00
### `schema`
2016-07-22 17:15:46 -07:00
To see how these properties behave, check out the [Plugins reference](./plugins.md).
2016-07-12 10:43:24 -07:00
2016-07-11 13:19:39 -07:00
2016-07-11 15:59:00 -07:00
## Methods
2016-07-11 13:19:39 -07:00
2016-08-14 18:29:00 -07:00
### `blur`
`blur() => Void`
Programmatically blur the editor.
### `focus`
`focus() => Void`
2016-08-14 18:29:00 -07:00
Programmatically focus the editor.
### `getSchema`
2016-08-14 18:29:00 -07:00
`getSchema() => Schema`
Return the editor's current schema.
### `getState`
2016-07-12 11:23:07 -07:00
`getState() => State`
2016-07-11 13:19:39 -07:00
2016-08-14 18:29:00 -07:00
Return the editor's current state.
2016-07-11 13:27:34 -07:00
### `onChange`
`onChange(change: Change) => Void`
2016-07-11 13:27:34 -07:00
Invoking this method will update the state of the editor with the `change`, running it through all of it's plugins, and passing it the parent component, before it cycles back down as the new `state` property of the editor.