Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Makes targetable Tooltips interactive #3520

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

Open
AnnMarieW wants to merge 3 commits into plotly:dev
base: dev
Choose a base branch
Loading
from AnnMarieW:make-targetable-tooltip-interactive

Conversation

@AnnMarieW
Copy link
Collaborator

@AnnMarieW AnnMarieW commented Nov 18, 2025
edited
Loading

closes #2759

This PR fixes the issue where it was not possible to interact with Tooltip content (like clicking on a button) without setting the pointer-events styling.

It sets pointer-events to auto on the tooltip content when targetable=True

TO DO:

  • Add test. Should this PR target dash 3 or be deferred to dash 4?
  • Update docs

Here is an app similar to the one @celia-lm used in the issue. It would make a good example for the docs too!

from dash import Dash, dcc, html, Input, Output, no_update, callback, ctx
import plotly.express as px
fig = px.scatter(x=[1, 2, 3], y=[1, 2, 1], text=["A", "B", "C"])
fig.update_traces(hoverinfo="none", hovertemplate=None, marker=dict(size=40))
fig.update_traces(textfont_color="white")
app = Dash(__name__)
app.layout = html.Div(
 [
 html.H3("Tooltip button callback output"),
 html.Div("No tooltip button clicked yet", id="out"),
 dcc.Graph(id="graph", figure=fig, clear_on_unhover=True),
 dcc.Tooltip(
 id="tooltip",
 targetable=True,
 children=html.Button(id="hover-click", children="Click me!"),
 ),
 ],
 style={"margin": "20px"},
)
# adapted from https://dash.plotly.com/dash-core-components/tooltip#styling-tooltip-with-background-and-border-color
@callback(
 Output("tooltip", "show"),
 Output("tooltip", "bbox"),
 Input("graph", "hoverData"),
 Input("hover-click", "n_clicks"),
)
def update_tooltip_content(hoverData, clicks):
 # close the tooltip when the button is clicked
 if ctx.triggered_id == "hover-click":
 return False, no_update
 # keep the tooltip open if we move away from the point, until we hover over another point
 if hoverData is None:
 return no_update, no_update
 pt = hoverData["points"][0]
 bbox = pt["bbox"]
 return True, bbox
@callback(
 Output("out", "children"),
 Input("hover-click", "n_clicks"),
 prevent_initial_call=True,
)
def save_changes(clicks):
 return f"Button has been clicked {clicks} times!"
if __name__ == "__main__":
 app.run(debug=True)

tootip-pr

Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

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

Reviewers

@T4rk1n T4rk1n T4rk1n approved these changes

@ndrezn ndrezn Awaiting requested review from ndrezn ndrezn is a code owner

@emilykl emilykl Awaiting requested review from emilykl emilykl is a code owner

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

dcc.Tooltip children isn't clickable even with targetable=True

2 participants

AltStyle によって変換されたページ (->オリジナル) /