Skip to content

Add id to radioitems.options options so that one can attach tooltips to them #377

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

Closed
Jerry-Ma opened this issue May 23, 2020 · 5 comments
Closed

Comments

@Jerry-Ma
Copy link

Hi,

Thank you for this fantastic package!

I started to play with the radio items and found that currently it is not easy to add tooltips for the items.

The issue is that dbc.Tooltip needs an target property but if we use a plain dbc.RadioItems, the created option items do not have an id.

I also tried using the stand alone radio item approach, and I can create the layout as expected, but
I have no idea how to implement the mutually exclusive checking behavior using clientside callbacks (I saw some discussion here #241).

Any suggestions?

@Jerry-Ma Jerry-Ma changed the title Add id to radioitems.options options so that one can attach tooltip to them Add id to radioitems.options options so that one can attach tooltips to them May 23, 2020
@Jerry-Ma
Copy link
Author

It appears that one does not need id because I found that the target property is passed as is to the react component underlying, so a css selector can be passed:

for i in range(len(options)):
     target=f'radio_items_id > .custom-radio:nth-of-type({i + 1}) label'
     dbc.Tooltip(target=target, ...)

@tcbegley
Copy link
Collaborator

That looks like a nice workaround!

I'll look at adding label_id and input_id options to RadioItems and Checklist

@tcbegley
Copy link
Collaborator

Adding this in #379, seems to work well 👍

import dash
import dash_bootstrap_components as dbc

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container(
    [
        dbc.RadioItems(
            id="radios",
            options=[
                {"label": f"Item {i}", "value": i, "label_id": f"my-label-{i}"}
                for i in range(5)
            ],
        )
    ]
    + [
        dbc.Tooltip(f"Tooltip for item {i}", target=f"my-label-{i}")
        for i in range(5)
    ]
)

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

Will close this when it makes it into a release.

@Jerry-Ma
Copy link
Author

Great, thank you very much!

@tcbegley
Copy link
Collaborator

This is now available in version 0.10.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