'Jump to html anchor using dash-bootstrap-component button in python

I'm trying to get a button to jump/scroll to a certain part of the webpage using dash-bootstrap-components. The anchor is added to the URL correctly, but the webpage doesn't move.

import dash_html_components as html
import dash_bootstrap_components as dbc

layout = html.Div([
...
  html.Div([
    dbc.Button('Record Information', id='record-info-btn', href='#record-info'
                className='btn btn-orange align-middle btn btn-secondary')])
...
  html.Div([
    dbc.Form([
      html.Div([
        dbc.FormGroup([
          html.Div([
            html.H3('Record Information', id='record-info')
            ...
          ])
        ])
      ])
    ])
  ])
], className='whitContainerHalf')

I've tried using dbc.NavLink instead of Button, but the same thing happens.



Solution 1:[1]

According to the dbc documentation, Button has an href field that can link to an internal id or an external url; however, according to an issue on their repo, it doesn't work for internal ids. You have to use html.A() to jump to the section.

import dash_html_components as html
import dash_bootstrap_components as dbc

layout = html.Div([
...
  html.Div([
    html.A(dbc.Button('Record Information', id='record-info-btn', 
                      className='btn btn-orange align-middle btn btn-secondary'), 
           href='#record-info')
  ])
...
  html.Div([
    dbc.Form([
      html.Div([
        dbc.FormGroup([
          html.Div([
            html.H3('Record Information', id='record-info')
            ...
          ])
        ])
      ])
    ])
  ])
], className='whiteContainerHalf')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tstar