buildo / react-cookie-banner

React Cookie banner which can be automatically dismissed with a scroll. Because fuck The Cookie Law, that's why.
http://react-components.buildo.io/#cookiebanner
MIT License
182 stars 19 forks source link

Doesn't work when used in conjunction with React-Custom-Scrollbars #50

Closed andrea-ligios closed 3 years ago

andrea-ligios commented 6 years ago

Hi, I've noticed that using React-Cookie-Banner along with React-Custom-Scrollbars the on-scroll dismission doesn't work, most likely because the latter is handling the scrolling event, preventing CookieBanner to be aware of what's going on. Do you think is there a way to make them work together?

FrancescoCioria commented 6 years ago

Hi @andrea-ligios

The only way I can come up with is you handling the scroll event and dismissing the cookie banner from outside but I realise it's not optimal:

import CookieBanner from 'react-cookie-banner';
import { BannerContent } from 'react-cookie-banner';
handleScroll = () => {
  if (this._dismissCookieBanner) {
    this._dismissCookieBanner();
  }
}
<Scrollbars onScroll={this.handleScroll} {...}>
  <CookieBanner>
    (onAccept) => {
      this._dismissCookieBanner = onAccept;
      return <BannerContent onAccept={onAccept} {...} />
    }
  </CookieBanner>
</Scrollbars>

NOTE: I haven't tested it so I'm not sure it works correctly