1+ import { useEffect , useRef } from 'react'
12import { Editor } from '@tiptap/core'
23import {
34 MdFormatBold ,
@@ -13,13 +14,46 @@ import { HighlightMarker } from '@icons'
1314import ToolbarButton from '@components/TipTap/toolbar/ToolbarButton'
1415
1516const FormatSelection = ( { isVisible, editor } : { isVisible : boolean ; editor : Editor } ) => {
17+ const containerRef = useRef < HTMLDivElement > ( null )
18+ const timeoutRef = useRef < NodeJS . Timeout | undefined > ( undefined )
19+
20+ // Handle visibility and transitions
21+ useEffect ( ( ) => {
22+ const container = containerRef . current
23+ if ( ! container ) return
24+
25+ // Clear any pending timeout
26+ if ( timeoutRef . current ) {
27+ clearTimeout ( timeoutRef . current )
28+ }
29+
30+ if ( isVisible ) {
31+ // Show: make visible immediately for smooth transition
32+ container . style . visibility = 'visible'
33+ } else {
34+ // Hide: wait for transition to complete (300ms), then hide from DOM
35+ timeoutRef . current = setTimeout ( ( ) => {
36+ if ( container && ! isVisible ) {
37+ container . style . visibility = 'hidden'
38+ }
39+ } , 300 )
40+ }
41+
42+ return ( ) => {
43+ if ( timeoutRef . current ) {
44+ clearTimeout ( timeoutRef . current )
45+ }
46+ }
47+ } , [ isVisible ] )
48+
1649 return (
1750 < div
18- className = { `tiptap-toolbar-mobile__format-selection bg-base-100 absolute top-0 left-0 z-0 w-full space-y-6 rounded-t-3xl px-4 py-6 transition-all ${
51+ ref = { containerRef }
52+ className = { `tiptap-toolbar-mobile__format-selection bg-base-100 absolute top-0 left-0 z-0 w-full space-y-6 rounded-t-3xl px-4 py-6 transition-all duration-300 ${
1953 isVisible
20- ? 'block -translate-y-[134px] shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1),_0_-2px_4px_-1px_rgba(0,0,0,0.06)]'
21- : 'hidden translate-y-[0] '
22- } `} >
54+ ? 'pointer-events-auto -translate-y-[134px] opacity-100 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1),_0_-2px_4px_-1px_rgba(0,0,0,0.06)]'
55+ : 'pointer-events-none translate-y-0 opacity-0 '
56+ } `} >
2357 < div className = "flex items-center justify-between" >
2458 < ToolbarButton
2559 onTouchEnd = { ( ) => editor . chain ( ) . focus ( ) . toggleBold ( ) . run ( ) }
0 commit comments