mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 03:32:36 +02:00
committed by
Ian Storm Taylor
parent
3b16a1c3f0
commit
0e95b02399
@@ -28,7 +28,6 @@ const MentionExample = () => {
|
|||||||
const chars = CHARACTERS.filter(c =>
|
const chars = CHARACTERS.filter(c =>
|
||||||
c.toLowerCase().startsWith(search.toLowerCase())
|
c.toLowerCase().startsWith(search.toLowerCase())
|
||||||
).slice(0, 10)
|
).slice(0, 10)
|
||||||
const suggest = target && chars.length > 0
|
|
||||||
|
|
||||||
const onKeyDown = useCallback(
|
const onKeyDown = useCallback(
|
||||||
event => {
|
event => {
|
||||||
@@ -62,14 +61,14 @@ const MentionExample = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (suggest) {
|
if (target && chars.length > 0) {
|
||||||
const el = ref.current
|
const el = ref.current
|
||||||
const domRange = ReactEditor.toDOMRange(editor, target)
|
const domRange = ReactEditor.toDOMRange(editor, target)
|
||||||
const rect = domRange.getBoundingClientRect()
|
const rect = domRange.getBoundingClientRect()
|
||||||
el.style.top = `${rect.top + window.pageYOffset + 24}px`
|
el.style.top = `${rect.top + window.pageYOffset + 24}px`
|
||||||
el.style.left = `${rect.left + window.pageXOffset}px`
|
el.style.left = `${rect.left + window.pageXOffset}px`
|
||||||
}
|
}
|
||||||
}, [index, search, target])
|
}, [chars.length, editor, index, search, target])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate
|
<Slate
|
||||||
@@ -108,7 +107,7 @@ const MentionExample = () => {
|
|||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
placeholder="Enter some text..."
|
placeholder="Enter some text..."
|
||||||
/>
|
/>
|
||||||
{suggest && (
|
{target && chars.length > 0 && (
|
||||||
<Portal>
|
<Portal>
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
Reference in New Issue
Block a user