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

Add support for retrieving HTMLElement by Dash component ID in clientside callbacks. #3208

Open
ctdunc opened this issue Mar 11, 2025 · 1 comment
Labels
feature something new P2 considered for next cycle

Comments

@ctdunc
Copy link

ctdunc commented Mar 11, 2025

This has been discussed on the forum. A feature request seems more appropriate.

Is your feature request related to a problem? Please describe.
When using clientside callbacks and pattern matching, the idiomatic for getting access to third party javascript objects seems to be (an example from ag Grid) :

clientside_callback(
    """
(grid_id, html_id, ...) => {
  // works 
  const gridApi = dash_ag_grid.getApi(id);
  // doesn't work
  const el = document.querySelector(`div#{html_id}`);
}
    """,
    Output(MATCH, "id"),
    Input({"type": "ag-grid", "index": MATCH}, "id"),
    Input({"type": "html-element", "index": MATCH}, "id"),
    # ... any other inputs that would be used here to trigger this behavior
)

Describe the solution you'd like
I would like Dash to expose a method like dash_clientside.get_element_by_id(id: String | Object<String, String | _WildCard>): HTMLElement which takes advantage of dash internals correctly to replicate this use case.

Describe alternatives you've considered
There is a forum post describing an implementation of stringifyId that can query HTMLElements using document.querySelector. However, even the author acknowledges that the behavior may not be consistent, and runtime checks are necessary to ensure correctness. Plus, if Dash ever changes how object IDs are serialized for use in the DOM, any projects depending on this solution will break in unexpected ways.

@gvwilson gvwilson changed the title [Feature Request] Add support for retrieving HTMLElement by Dash component ID in clientside callbacks. Add support for retrieving HTMLElement by Dash component ID in clientside callbacks. Mar 11, 2025
@gvwilson gvwilson added feature something new P2 considered for next cycle labels Mar 11, 2025
@gvwilson
Copy link
Contributor

Thanks @ctdunc - I'll see if we can get this into the next work cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

2 participants