Skip to content

Commit 86d143f

Browse files
authored
fix (accordion block): enable text selection if accordion is inside columns (#3364)
* fix text selection if accordion is inside columns * add fallback
1 parent 003ebf8 commit 86d143f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/block/accordion/frontend-accordion.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)