mauricevancooten / react-anchor-link-smooth-scroll

React component for anchor links using the smooth scroll polyfill.
243 stars 31 forks source link

Start Scrolling With Delay #30

Open NimaKaviyani opened 4 years ago

NimaKaviyani commented 4 years ago

Hi, I have an accordion component at bottom of the page, I want scrolling after it open. Is it possible to start scrolling with delay?

I try this code:

constructor(props) {
    super(props);
    this.state = {
        showUpload: false,
    };
    this.anchorRef = createRef();
}
showUploadBlock = () => {
    this.setState(prevState => ({
        showUpload: !prevState.showUpload,
    }), () => {
        if (this.state.showUpload) {
            setTimeout(() => {
                this.anchorRef.click();
            }, 5);
        }
    });
};
<Button
    onClick={this.showUploadBlock}
    variant="info"
    size="lg"
    block
>
    Upload File
</Button>
<AnchorLink
    ref={(ref) => {
        this.anchorRef = ref;
    }}
    href="#upload"
    className="invisible"
/>

But ref is not working.

tunztunztunz commented 3 years ago

I'm also curious if you can do it with this package.

NimaKaviyani commented 3 years ago

I'm also curious if you can do it with this package.

Unfortunately, I did not succeed. And I did not receive an answer after a year.