mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-08 16:26:29 +02:00
Documents how to implement a Void Element. (#4924)
* Documents how to implement a Void Element. * Tightens up phrasing
This commit is contained in:
@@ -11,6 +11,7 @@ interface Element {
|
||||
- [Behavior Types](element.md#element-behavior-types)
|
||||
- [Block vs. Inline](element.md#block-vs-inline)
|
||||
- [Void vs Not Void](element.md#void-vs-not-void)
|
||||
- [Rendering Void Elements](element.md#rendering-void-elements)
|
||||
- [Static methods](element.md#static-methods)
|
||||
- [Retrieval methods](element.md#retrieval-methods)
|
||||
- [Check methods](element.md#check-methods)
|
||||
@@ -30,6 +31,25 @@ A "block" element can only be siblings with other "block" elements. An "inline"
|
||||
|
||||
In a not "void" element, Slate handles the rendering of its `children` (e.g. in a paragraph where the `Text` and `Inline` children are rendered by Slate). In a "void" element, the `children` are rendered by the `Element`'s render code.
|
||||
|
||||
#### Rendering Void Elements
|
||||
|
||||
Void Elements must
|
||||
|
||||
- always have one empty child text node (for selection)
|
||||
- render using `attributes` and `children` (so, their outermost HTML element **can't** be an HTML void element)
|
||||
- set `contentEditable={false}` (for Firefox)
|
||||
|
||||
Typical rendering code will resemble this `thematic-break` (horizontal rule) element:
|
||||
|
||||
```javascript
|
||||
return (
|
||||
<div {...attributes} contentEditable={false}>
|
||||
{children}
|
||||
<hr />
|
||||
</div>
|
||||
)
|
||||
```
|
||||
|
||||
## Static methods
|
||||
|
||||
### Retrieval methods
|
||||
|
Reference in New Issue
Block a user