mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-15 11:44:05 +02:00
Make Editable accept 'as' prop (#3288)
* allow passing 'as' prop to render custom component * Update editable.tsx
This commit is contained in:
committed by
Ian Storm Taylor
parent
faf73d4521
commit
5bddee673f
@@ -57,22 +57,27 @@ export interface RenderLeafProps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `EditableProps` are passed to the `<Editable>` component.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type EditableProps = {
|
||||||
|
decorate?: (entry: NodeEntry) => Range[]
|
||||||
|
onDOMBeforeInput?: (event: Event) => void
|
||||||
|
placeholder?: string
|
||||||
|
readOnly?: boolean
|
||||||
|
role?: string
|
||||||
|
style?: React.CSSProperties
|
||||||
|
renderElement?: (props: RenderElementProps) => JSX.Element
|
||||||
|
renderLeaf?: (props: RenderLeafProps) => JSX.Element
|
||||||
|
as?: React.ElementType
|
||||||
|
} & React.TextareaHTMLAttributes<HTMLDivElement>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editable.
|
* Editable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const Editable = (
|
export const Editable = (props: EditableProps) => {
|
||||||
props: {
|
|
||||||
decorate?: (entry: NodeEntry) => Range[]
|
|
||||||
onDOMBeforeInput?: (event: Event) => void
|
|
||||||
placeholder?: string
|
|
||||||
readOnly?: boolean
|
|
||||||
role?: string
|
|
||||||
style?: React.CSSProperties
|
|
||||||
renderElement?: (props: RenderElementProps) => JSX.Element
|
|
||||||
renderLeaf?: (props: RenderLeafProps) => JSX.Element
|
|
||||||
} & React.TextareaHTMLAttributes<HTMLDivElement>
|
|
||||||
) => {
|
|
||||||
const {
|
const {
|
||||||
autoFocus,
|
autoFocus,
|
||||||
decorate = defaultDecorate,
|
decorate = defaultDecorate,
|
||||||
@@ -82,6 +87,7 @@ export const Editable = (
|
|||||||
renderElement,
|
renderElement,
|
||||||
renderLeaf,
|
renderLeaf,
|
||||||
style = {},
|
style = {},
|
||||||
|
as: Component = 'div',
|
||||||
...attributes
|
...attributes
|
||||||
} = props
|
} = props
|
||||||
const editor = useSlate()
|
const editor = useSlate()
|
||||||
@@ -400,7 +406,7 @@ export const Editable = (
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ReadOnlyContext.Provider value={readOnly}>
|
<ReadOnlyContext.Provider value={readOnly}>
|
||||||
<div
|
<Component
|
||||||
// COMPAT: The Grammarly Chrome extension works by changing the DOM
|
// COMPAT: The Grammarly Chrome extension works by changing the DOM
|
||||||
// out from under `contenteditable` elements, which leads to weird
|
// out from under `contenteditable` elements, which leads to weird
|
||||||
// behaviors so we have to disable it like editor. (2017/04/24)
|
// behaviors so we have to disable it like editor. (2017/04/24)
|
||||||
@@ -887,7 +893,7 @@ export const Editable = (
|
|||||||
renderLeaf={renderLeaf}
|
renderLeaf={renderLeaf}
|
||||||
selection={editor.selection}
|
selection={editor.selection}
|
||||||
/>
|
/>
|
||||||
</div>
|
</Component>
|
||||||
</ReadOnlyContext.Provider>
|
</ReadOnlyContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user