Skip to content

added static prop to remove event listener #2370

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
wants to merge 11 commits into from

Conversation

AnnMarieW
Copy link
Collaborator

@AnnMarieW AnnMarieW commented Dec 21, 2022

As reported on the forum, components with event listeners can cause issues with screen readers.

https://community.plotly.com/t/how-to-remove-events-from-dash-html-components-to-avoid-misinterpretation-by-screen-readers/70477

This PR adds a disable_n_clicks prop to all html components, giving the ability to remove the event listener.

By default, n_clicks will be enabled on any html component that has an id. If n_clicks is not used in a callback for that component, the event listener can be removed by setting disable_n_clicks=True`

For example:

  • No event listener:
    html.Div()
    html.Div(id="my-id", disable_n_clicks=True)

  • onClick event listener:
    html.Div(id="my-id")

Contributor Checklist

  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@AnnMarieW
Copy link
Collaborator Author

Needs a better name for the prop than static since that may imply that no callbacks can be done on the component. Perhaps it should be disable_n_clicks ?

@T4rk1n
Copy link
Contributor

T4rk1n commented Jan 9, 2023

Needs a better name for the prop than static since that may imply that no callbacks can be done on the component. Perhaps it should be disable_n_clicks ?

I like disable_n_clicks, it's more explicit than static.

On another note, I don't think n_clicks changes requires a re-render, perhaps add memo with a custom handler or refactor the component back to classes and implement shouldComponentUpdate.

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.

💃

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

Why did the favicon change in this PR? Can you revert that?

After that this looks great! 💃

@AnnMarieW
Copy link
Collaborator Author

This pull request was re-created in 2389 to remove the files included in error.

@AnnMarieW AnnMarieW closed this Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants