@@ -3,8 +3,7 @@ import useMergedState from 'rc-util/lib/hooks/useMergedState';
3
3
import toArray from 'rc-util/lib/Children/toArray' ;
4
4
import KeyCode from 'rc-util/lib/KeyCode' ;
5
5
import warning from 'rc-util/lib/warning' ;
6
- import * as React from 'react' ;
7
- import { useState , useRef } from 'react' ;
6
+ import React , { useState , useRef , useEffect } from 'react' ;
8
7
import TextArea from 'rc-textarea' ;
9
8
import type { TextAreaProps } from 'rc-textarea' ;
10
9
import KeywordTrigger from './KeywordTrigger' ;
@@ -112,6 +111,8 @@ const Mentions = React.forwardRef<MentionsRef, MentionsProps>((props, ref) => {
112
111
const textareaRef = useRef < TextArea > ( null ) ;
113
112
const measureRef = useRef < HTMLDivElement > ( null ) ;
114
113
114
+ const getTextArea = ( ) => textareaRef . current ?. resizableTextArea ?. textArea ;
115
+
115
116
React . useImperativeHandle ( ref , ( ) => ( {
116
117
focus : ( ) => textareaRef . current ?. focus ( ) ,
117
118
blur : ( ) => textareaRef . current ?. blur ( ) ,
@@ -132,6 +133,13 @@ const Mentions = React.forwardRef<MentionsRef, MentionsProps>((props, ref) => {
132
133
} ) ;
133
134
134
135
// =============================== Open ===============================
136
+ useEffect ( ( ) => {
137
+ // Sync measure div top with textarea for rc-trigger usage
138
+ if ( measuring && measureRef . current ) {
139
+ measureRef . current . scrollTop = getTextArea ( ) . scrollTop ;
140
+ }
141
+ } , [ measuring ] ) ;
142
+
135
143
const [
136
144
mergedMeasuring ,
137
145
mergedMeasureText ,
@@ -242,8 +250,6 @@ const Mentions = React.forwardRef<MentionsRef, MentionsProps>((props, ref) => {
242
250
} ;
243
251
244
252
const selectOption = ( option : OptionProps ) => {
245
- const getTextArea = ( ) => textareaRef . current ?. resizableTextArea ?. textArea ;
246
-
247
253
const { value : mentionValue = '' } = option ;
248
254
const { text, selectionLocation } = replaceWithMeasure ( mergedValue , {
249
255
measureLocation : mergedMeasureLocation ,
0 commit comments