Skip to content

Commit d211122

Browse files
Issue 5782 (#5783)
* updated docs for editable file such that renderProps will have the desired effect if the instructions are followed * Update docs/libraries/slate-react/editable.md * Update docs/libraries/slate-react/editable.md * Update editable.md fix incorrect code format label * Update docs/libraries/slate-react/editable.md --------- Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
1 parent 5c4c0d8 commit d211122

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

docs/libraries/slate-react/editable.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export interface RenderLeafProps {
136136

137137
Example usage:
138138

139-
```typescript
139+
```jsx
140140
<Editor
141141
renderLeaf={({ attributes, children, leaf }) => {
142142
return (
@@ -206,14 +206,22 @@ An example usage might look like:
206206
207207
```jsx
208208
<Editable
209-
renderPlaceholder={({ attributes, children }) => (
210-
<div {...attributes} style={{ fontStyle: 'italic', color: 'gray' }}>
211-
{children}
212-
</div>
213-
)}
209+
placeholder="Enter text here..."
210+
renderPlaceholder={({ attributes, children }) => {
211+
const styledAttributes = {
212+
...attributes,
213+
style: {
214+
...attributes.style,
215+
color: 'gray',
216+
},
217+
}
218+
return <div {...styledAttributes}>{children}</div>
219+
}}
214220
/>
215221
```
216222
223+
Note that the `attributes` prop that comes in will contain a `style` object already. This object contains important styling properties which will make the placeholder behave like a placeholder. As such, it is advisable to extend styles and to focus on things like changing colors, opacity etc. Changing positioning, for example, could cause undesirable behavior.
224+
217225
#### `scrollSelectionIntoView?: (editor: ReactEditor, domRange: DOMRange) => void`
218226
219227
Slate has its own default method to scroll a DOM selection into view that works for most cases; however, if the default behavior isn't working for you, possible due to some complex styling, you may need to override the default behavior by providing a different function here.

0 commit comments

Comments
 (0)