react-turnstile icon indicating copy to clipboard operation
react-turnstile copied to clipboard

Is it possible to tell if the captcha is visible?

Open sketchbuch opened this issue 1 year ago • 2 comments

I want to add a spacing between it and some buttons, but only when it is visible

sketchbuch avatar Mar 22 '24 14:03 sketchbuch

You can use the onBeforeInteractive callback, which runs before the challenge becomes interactive.

Example:

import { Turnstile } from '@marsidev/react-turnstile'
import React from 'react'

export default function Page() {
  const [isVisible, setIsVisible] = React.useState(false)

  return (
    <React.Fragment>
      <Turnstile
        siteKey="3x00000000000000000000FF"
        onBeforeInteractive={() => setIsVisible(true)}
      />

      {isVisible && <button>Conditional Button</button>}
    </React.Fragment>
  )
}

marsidev avatar Apr 27 '24 02:04 marsidev

yeah, but I want to know if it is visible. After onAfterInteractive fires it can still be visible. Because of this, when onBeforeInteractive fires it xcan already be visible.

sketchbuch avatar Apr 27 '24 19:04 sketchbuch

We don't have a onVisible callback, but we you can use the ResizeObserver API to achive what you need. Check this demo.

marsidev avatar Jun 10 '24 17:06 marsidev