mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-19 14:44:39 +01:00
Fix scroll into view to scroll parent scrollables (#4369)
This commit is contained in:
parent
46c8871c9c
commit
c217dbb5b9
5
.changeset/poor-moose-approve.md
Normal file
5
.changeset/poor-moose-approve.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': patch
|
||||
---
|
||||
|
||||
Scroll when inserting new text will now scroll parent scrollables
|
@ -216,7 +216,6 @@ export const Editable = (props: EditableProps) => {
|
||||
)
|
||||
scrollIntoView(leafEl, {
|
||||
scrollMode: 'if-needed',
|
||||
boundary: el,
|
||||
})
|
||||
// @ts-ignore
|
||||
delete leafEl.getBoundingClientRect
|
||||
|
70
site/examples/scroll-into-view.tsx
Normal file
70
site/examples/scroll-into-view.tsx
Normal file
@ -0,0 +1,70 @@
|
||||
import React, { useState, useMemo } from 'react'
|
||||
import { createEditor, Descendant } from 'slate'
|
||||
import { Slate, Editable, withReact } from 'slate-react'
|
||||
import { withHistory } from 'slate-history'
|
||||
import { css } from 'emotion'
|
||||
import range from 'lodash/range'
|
||||
|
||||
/**
|
||||
* This is an example we can use to test the scrollIntoView functionality in
|
||||
* `Editable`. Keeping it here for now as we may need it to make sure it is
|
||||
* working properly after adding it.
|
||||
*
|
||||
* If all is good, we can remove this example.
|
||||
*
|
||||
* Note:
|
||||
* The example needs to be added to `[example].tsx` before it can be used.
|
||||
*/
|
||||
|
||||
const ScrollIntoViewExample = () => {
|
||||
return (
|
||||
<div
|
||||
className={css`
|
||||
height: 320px;
|
||||
overflow-y: scroll;
|
||||
`}
|
||||
>
|
||||
<div
|
||||
className={css`
|
||||
height: 160px;
|
||||
background: #e0e0e0;
|
||||
`}
|
||||
/>
|
||||
<div
|
||||
className={css`
|
||||
height: 320px;
|
||||
overflow-y: scroll;
|
||||
`}
|
||||
>
|
||||
<PlainTextEditor />
|
||||
</div>
|
||||
<div
|
||||
className={css`
|
||||
height: 160px;
|
||||
background: #e0e0e0;
|
||||
`}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const PlainTextEditor = () => {
|
||||
const [value, setValue] = useState<Descendant[]>(initialValue)
|
||||
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
|
||||
return (
|
||||
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
|
||||
<Editable placeholder="Enter some plain text..." />
|
||||
</Slate>
|
||||
)
|
||||
}
|
||||
|
||||
const initialValue: Descendant[] = range(5).map(() => ({
|
||||
type: 'paragraph',
|
||||
children: [
|
||||
{
|
||||
text: `There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.`,
|
||||
},
|
||||
],
|
||||
}))
|
||||
|
||||
export default ScrollIntoViewExample
|
Loading…
x
Reference in New Issue
Block a user