@@ -20,6 +20,7 @@ const Main = ({
2020 finishDelay = 0 ,
2121 loop = false ,
2222 pause = false ,
23+ hideCursorWhenDone = false ,
2324} : TypistProps ) => {
2425 const [ typedChildrenArray , setTypedChildrenArray ] = useState < TypedChildren [ ] > (
2526 [ ] ,
@@ -28,6 +29,8 @@ const Main = ({
2829 const clearTimerRef = useRef ( emptyFunc ) ;
2930 const loopRef = useRef ( loop ) ;
3031 const pauseRef = useRef ( pause ) ;
32+ const hideCursorWhenDoneRef = useRef ( hideCursorWhenDone ) ;
33+ const [ showCursor , setShowCursor ] = useState ( true ) ;
3134
3235 const timeoutPromise = useCallback ( ( delay : Delay ) => {
3336 return new Promise ( ( resolve , reject ) => {
@@ -73,7 +76,8 @@ const Main = ({
7376 useEffect ( ( ) => {
7477 loopRef . current = loop ;
7578 pauseRef . current = pause ;
76- } , [ loop , pause ] ) ;
79+ hideCursorWhenDoneRef . current = hideCursorWhenDone ;
80+ } , [ loop , pause , hideCursorWhenDone ] ) ;
7781
7882 useEffect ( ( ) => {
7983 const typedChildrenArray = getTypedChildrenArray ( children , splitter ) ;
@@ -86,6 +90,7 @@ const Main = ({
8690 ( async ( ) => {
8791 try {
8892 do {
93+ setShowCursor ( true ) ;
8994 setCurrentIndex ( - 1 ) ;
9095 const actions = getActions ( children , splitter ) ;
9196 if ( startDelay > 0 ) await timeoutPromise ( startDelay ) ;
@@ -107,6 +112,7 @@ const Main = ({
107112 }
108113 }
109114 onTypingDone ?.( ) ;
115+ setShowCursor ( false ) ;
110116 if ( finishDelay > 0 ) await timeoutPromise ( finishDelay ) ;
111117 if ( ! loopRef . current ) await loopPromise ( ) ;
112118 } while ( loopRef . current ) ;
@@ -123,7 +129,13 @@ const Main = ({
123129 } , [ restartKey , disabled ] ) ;
124130
125131 const typedChildren = typedChildrenArray [ currentIndex ] ;
126- return < > { cursor ? insertCursor ( typedChildren , cursor ) : typedChildren } </ > ;
132+ return (
133+ < >
134+ { cursor && showCursor
135+ ? insertCursor ( typedChildren , cursor )
136+ : typedChildren }
137+ </ >
138+ ) ;
127139} ;
128140
129141export default Main ;
0 commit comments