@@ -33,6 +33,8 @@ class StackableAccordion {
3333 // Prevent text selection while animating
3434 el . style . userSelect = 'none'
3535
36+ clearTimeout ( el . textSelectTimeout )
37+
3638 // When inside columns, flex prevents the accordion closing animation, this hack fixes it.
3739 const doWrapHack = ! ! el . closest ( '.stk-block-columns' )
3840 let wrapper = null
@@ -54,14 +56,18 @@ class StackableAccordion {
5456 } , ANIM_OPTS )
5557 }
5658
57- // When the animation is done, allow text selection again.
59+ // When the animation is done, remove wrapper and allow text selection again.
5860 el . anim . onfinish = el . anim . oncancel = ( ) => {
61+ if ( doWrapHack ) {
62+ removeWrapperHack ( el , wrapper )
63+ }
5964 el . style . userSelect = 'auto'
6065 }
6166
62- if ( doWrapHack ) {
63- removeWrapperHack ( el , wrapper )
64- }
67+ // Fallback to make sure accordion text is selectable just incase the onfinish or oncancel doesn't fire.
68+ el . textSelectTimeout = setTimeout ( ( ) => {
69+ el . style . userSelect = 'auto'
70+ } , 700 )
6571 }
6672 } )
6773 } )
@@ -197,11 +203,9 @@ class StackableAccordion {
197203 }
198204
199205 const removeWrapperHack = ( el , wrapper ) => {
200- el . anim . onfinish = el . anim . oncancel = ( ) => {
201- // Unwrap el from the div
202- wrapper . parentNode ?. insertBefore ( el , wrapper )
203- wrapper ?. remove ( )
204- }
206+ // Unwrap el from the div
207+ wrapper . parentNode ?. insertBefore ( el , wrapper )
208+ wrapper ?. remove ( )
205209 }
206210 }
207211}
0 commit comments