@@ -9,19 +9,19 @@ import './PopupReply.scss';
99
1010export type Props = {
1111 className ?: string ;
12+ defaultValue ?: string ;
1213 onCancel : ( text ?: string ) => void ;
1314 onChange : ( text ?: string ) => void ;
1415 onSubmit : ( text : string ) => void ;
1516 reference : HTMLElement ;
1617} ;
1718
18- export default function PopupReply ( { onCancel, onChange, onSubmit, ...rest } : Props ) : JSX . Element {
19+ export default function PopupReply ( { defaultValue , onCancel, onChange, onSubmit, ...rest } : Props ) : JSX . Element {
1920 const [ text , setText ] = React . useState ( '' ) ;
2021 const textareaRef = React . useRef < HTMLTextAreaElement > ( null ) ;
2122
2223 // Event Handlers
2324 const handleEvent = ( event : React . SyntheticEvent ) : void => {
24- event . preventDefault ( ) ;
2525 event . stopPropagation ( ) ;
2626 event . nativeEvent . stopImmediatePropagation ( ) ;
2727 } ;
@@ -46,8 +46,14 @@ export default function PopupReply({ onCancel, onChange, onSubmit, ...rest }: Pr
4646 onCancel ( text ) ;
4747 } ;
4848 const handleFirstUpdate = ( ) : void => {
49- if ( textareaRef . current ) {
50- textareaRef . current . focus ( ) ;
49+ const { current : textarea } = textareaRef ;
50+
51+ if ( textarea ) {
52+ const { value } = textarea ;
53+
54+ textarea . focus ( ) ;
55+ textarea . selectionStart = value . length ; // Force cursor to the end after focus
56+ textarea . selectionEnd = value . length ; // Force cursor to the end after focus
5157 }
5258 } ;
5359
@@ -58,6 +64,7 @@ export default function PopupReply({ onCancel, onChange, onSubmit, ...rest }: Pr
5864 ref = { textareaRef }
5965 className = "ba-Popup-text"
6066 data-testid = "ba-Popup-text"
67+ defaultValue = { defaultValue }
6168 onChange = { handleChange }
6269 onClick = { handleEvent }
6370 />
0 commit comments