Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navLink active property not responding to callback #498

Closed
quandanrepo opened this issue Dec 18, 2020 · 5 comments
Closed

navLink active property not responding to callback #498

quandanrepo opened this issue Dec 18, 2020 · 5 comments

Comments

@quandanrepo
Copy link

quandanrepo commented Dec 18, 2020

  • dash==1.18.1
  • dash-bootstrap-components version: #0.11.0
  • components affected by bug: dash-bootstrap-component Nav and NavLink

What is happening?

In dash-bootstrap-components 0.11.0, the active property of a NavLink is not responding to a callback.

What should be happening?

The active tag should response to the callback and be overwritten by response. I.e. We want to set the a NavLink active property to 'True' upon initialising a dash app.

Code

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output

app = dash.Dash(
    __name__,
    external_stylesheets=[dbc.themes.BOOTSTRAP],
    suppress_callback_exceptions=True
)
server = app.server

sidebar = html.Div(
    [
        dbc.Nav(
            dbc.NavLink('test', href=f"/test", id=f"test-link"),
            vertical=True,
            pills=True
        )
    ]
)

content = html.Div(id='page-content')

app.layout = html.Div(
    [dcc.Location(id='url', refresh=False), sidebar, content]
)


@app.callback(Output('page-content', 'children'),
              Input('url', 'pathname'))
def display_page(pathname):
    if pathname in ['/']:
        return 'Test1'
    else:
        return '404'
@app.callback(Output(f'test-link', 'active'),
              Input('url', 'pathname'))
def initiate_active_tab(pathname):
    if pathname == '/':
        return True


if __name__ == '__main__':
    app.run_server(debug=True)
This was referenced Dec 18, 2020
@tcbegley
Copy link
Collaborator

Hey @quandanrepo

Thanks for raising this. There were some changes to the logic in NavLink in the last release and it looks like I introduced a bug, apologies.

I've just made a new pre-release that resolves this issue, could you try it out and let me know whether it fixes the bug at your end?

pip install dash-bootstrap-components==0.11.1rc1

@quandanrepo
Copy link
Author

Hi @tcbegley ,

Thanks for the quick reply.

I have just tested the code with the pre-release package and can confirm that I am getting expected behaviour from the callback now.

@quandanrepo
Copy link
Author

Will close this issue now

@tcbegley
Copy link
Collaborator

Great, thanks for checking and thanks again for reporting the issue. Apologies for letting the bug creep in. I've increased our test coverage so that it hopefully doesn't happen again.

Will make a full release with the fix tomorrow.

@tcbegley
Copy link
Collaborator

This fix is now available in dash-bootstrap-components 0.11.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants