snehilvj / dmc-docs

Documentation for Dash Mantine Components library.
https://github.com/snehilvj/dash-mantine-components
MIT License
53 stars 17 forks source link

NavLink n_clicks not trigerring callbacks #46

Closed hwh1771 closed 4 weeks ago

hwh1771 commented 5 months ago

I have a basic usage here:

layout = dmc.NavLink(
    label='test link',
    id='test-navlink'
)

@callback(
    Output('test-navlink', 'active'),
    Input('test-navlink', 'n_clicks'),
    prevent_initial_call=True
)
def func(n_clicks):
    if n_clicks:
        return True
    return False

However, it seems that the callback is never trigerred, even with print statements in the callback.

AnnMarieW commented 4 weeks ago

Hi @hwh1771

Sorry for the long delay in answering. I'm unable to reproduce the issue in dmc. 0.14.4.

I'm going to close this for now, but please re-open if you have followup questions.

import dash_mantine_components as dmc
from dash import Dash, _dash_renderer, callback, Input, Output
from dash_iconify import DashIconify
_dash_renderer._set_react_version("18.2.0")

def get_icon(icon):
    return DashIconify(icon=icon, height=16)

app = Dash(external_stylesheets=dmc.styles.ALL)

app.layout = dmc.MantineProvider(
    dmc.NavLink(
        id="link",
        label="Toggle active",
        leftSection=get_icon(icon="bi:house-door-fill"),
        n_clicks=0,
        w=200
    ),
)

@callback(
    Output("link", "active"),
    Input("link", "n_clicks"),
)
def notify(n):
    if n % 2 == 0:
        return True
    return False

if __name__ == "__main__":
    app.run_server(debug=True)

dmcnavlink