alicelieutier / smoothScroll

A teeny tiny smooth scroll script with ease-in-out effect and no jQuery.
MIT License
537 stars 128 forks source link

Not triggered in some react-bootstrap components #34

Closed johnhorsema closed 7 years ago

johnhorsema commented 8 years ago

I am using this with react-bootstrap components. I have imported smoothscroll with import Scroll from 'smoothscroll' in the render() method.

All dropdown items do not work, except those in <Nav pullRight>. `

superhussain commented 8 years ago

React doesn't play well with hash links. What you could do is create a function to manually do the scroll.

It could look something like this:

import React from "react";
import smoothScroll from 'smoothscroll';

export default class Nav extends React.Component {
  handleScrollClick(event) {
    var scrollId = this.props.data.href;
    var scrollElement = document.querySelector(scrollId);
    smoothScroll(scrollElement);

    event.preventDefault();
  }

  render() {
    return (
      <Nav>
        <NavDropdown>
          <MenuItem eventKey={2.1} href="#bio" onClick={this.handleScrollClick.bind(this)}>...</MenuItem>
          ...
        </NavDropdown>
      </Nav>
    );
  }
}