TR/PRES/RJ N. 002/2019




TR/PRES/RJ N. 001/2019




Edital/PRES/RJ 0002/2019




Edital/PRES/RJ 0001/2019


Editais 2019
Encontre aqui todos os editais do Hospital Getúlio Vargas

React Scrollspy - API

In this section you will find advanced information about the Scrollspy component. You will learn which modules are required in this component, what are the possibilities of configuring the component, and what events and methods you can use in working with it.


Import statement

React scrollspy can use other components, like ListGropu or Navbar in addition to present current scroll location, so rememeber about proper imports.

Main Scrollspy components:


        import { MDBScrollspyBox, MDBScrollspyList, MDBScrollspyListItem, MDBScrollspyText  } from "mdbreact";
      

Import statement

In order to use Scrollspay you have to define scrollable container, and sections inside of it and determine which section is visible.

Our suggestion is to use React ref to watch it's offsetTop property. Then we compare it with offsetTop of nested sections to determine which is active.

Also rememeber that Scrollspy elements (sections and navigation) have to be wrapped inside MDBScrollspyBox and sections have to be inside MDBScrollspyTex.

Sample code looks like this:


          import React from "react";
          import ReactDOM from 'react-dom';
          import {
          MDBScrollspyBox,
          MDBScrollspyList,
          MDBScrollspyListItem,
          MDBScrollspyText
          } from "mdbreact";
          import DocsLink from "../DocsLink";

          class ScrollSpyPage extends React.Component {
          constructor(props) {
            super(props);
            this.state = {
              active: 0,
              sections: []
            };

            this.scrollSpyText = React.createRef();
          }

          componentDidMount() {
            let sections = this.scrollSpyText.current.getElementsByTagName("h4");
            this.setState({ sections });
          }

          handleScroll = (e) => {
            const scrollTop = e.target.scrollTop;
            const sections = this.state.sections;
            const lastIndex = sections.length - 1;

            for (let i = 0; i < lastIndex; i++) { if ((scrollTop> sections[i].offsetTop - 20) && (scrollTop < sections[i +
              1].offsetTop - 20)) { this.setState({ active: i }); } }; if (scrollTop> sections[lastIndex].offsetTop - 20)
              this.setState({ active: lastIndex });
          }

          render() {
            return (
              

API Reference: ScrollspyBox Properties

The table below shows the configuration options of the MDBScrollspyBox component.

Name Type Default Description Example
className String Adds custom class to the Stepper component

API Reference: ScrollspyText Properties

The table below shows the configuration options of the MDBScrollspyText component.

Name Type Default Description Example
className String Adds custom class to the Stepper component
scrollSpyRef oneOfType[function, object] The React Ref which points on to the div wrapping all the scrollspy content

API Reference: ScrollspyList Properties

The table below shows the configuration options of the MDBScrollspyList component.

Name Type Default Description Example
className String Adds custom class to the Stepper component
color String default Changes the background color of the tab scrollspy panel

API Reference: ScrollspyListItem Properties

The table below shows the configuration options of the MDBScrollspyListItem component.

Name Type Default Description Example
active Boolean false Sets active state of the list item
className String Adds custom class to the Stepper component