Mastermindzh / react-cookie-consent

A small, simple and customizable cookie consent bar for use in React applications.
https://mastermindzh.github.io/react-cookie-consent/
MIT License
603 stars 84 forks source link

Consent Modal disappears when I scroll down #184

Closed andrei-bh closed 1 year ago

andrei-bh commented 1 year ago

This is my code and its parent component includes scroll eventlistener

<CookieConsent
      buttonText="Allow Cookies"
      cookieName="allow-cookies"
      style={{ background: '#2B373B' }}
      buttonStyle={{
        background: 'rgba(76, 183, 129, 0.95)',
        color: '#fff',
        fontSize: '13px'
      }}
      expires={150}
    >
      <div className="mb-3">
        <b>Cookie Consent</b>
      </div>
      We use necessary cookies to make our site work. We&apos;d like
      to set additional cookies to understand site usage, make site
      improvements and to remember your settings. We also use cookies
      set by other sites to help deliver content from their services.
      View our Cookie Notice
      <div className="mt-3">
        <Button onClick={onHide} className="start-btn mb-3">
          Manage My Choices
        </Button>
        <Button onClick={onHide} className="start-btn mb-3">
          Reject Additional Cookies
        </Button>
        <Button onClick={onHide} className="start-btn mb-3">
          Accept Additional Cookies
        </Button>
      </div>
    </CookieConsent>

parent component

useEffect(() => {
    window.addEventListener('scroll', () =>
      setState({
        isScrolled: window.scrollY > 10
      })
    );
  }, []);

If I remove this part, then it works well but if it exists, then it disappears when I scroll down

andrei-bh commented 1 year ago

Ref: https://github.com/Mastermindzh/react-cookie-consent/issues/183

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.