@@ -40,6 +40,10 @@ interface RenderOptions {
4040 * @param errorCode string
4141 */
4242 'error-callback' ?: ( errorCode : string ) => void ;
43+ /**
44+ * A JavaScript callback invoked before the challenge enters interactive mode.
45+ */
46+ 'before-interactive-callback' ?: ( ) => void ;
4347 /**
4448 * A JavaScript callback invoked when a given client/browser is not supported by the widget.
4549 */
@@ -145,7 +149,6 @@ export const getTunstileToken = async (captchaOptions: {
145149 } else {
146150 const visibleDiv = document . getElementById ( CAPTCHA_ELEMENT_ID ) ;
147151 if ( visibleDiv ) {
148- visibleDiv . style . display = 'block' ;
149152 widgetDiv = visibleDiv ;
150153 } else {
151154 console . error ( 'Captcha DOM element not found. Using invisible captcha widget.' ) ;
@@ -163,6 +166,14 @@ export const getTunstileToken = async (captchaOptions: {
163166 callback : function ( token : string ) {
164167 resolve ( [ token , id ] ) ;
165168 } ,
169+ 'before-interactive-callback' : ( ) => {
170+ const visibleWidget = document . getElementById ( CAPTCHA_ELEMENT_ID ) ;
171+ if ( visibleWidget ) {
172+ visibleWidget . style . maxHeight = 'unset' ;
173+ visibleWidget . style . minHeight = '68px' ; // this is the height of the Turnstile widget
174+ visibleWidget . style . marginBottom = '1.5rem' ;
175+ }
176+ } ,
166177 'error-callback' : function ( errorCode ) {
167178 errorCodes . push ( errorCode ) ;
168179 /**
@@ -211,7 +222,9 @@ export const getTunstileToken = async (captchaOptions: {
211222 if ( isInvisibleWidget ) {
212223 document . body . removeChild ( widgetDiv as HTMLElement ) ;
213224 } else {
214- ( widgetDiv as HTMLElement ) . style . display = 'none' ;
225+ ( widgetDiv as HTMLElement ) . style . maxHeight = '0' ;
226+ ( widgetDiv as HTMLElement ) . style . minHeight = 'unset' ;
227+ ( widgetDiv as HTMLElement ) . style . marginBottom = 'unset' ;
215228 }
216229 }
217230 }
0 commit comments