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

Handle non-empty whitespace textContent in Tooltip trigger #36588

Merged
merged 3 commits into from
Jul 6, 2022

Conversation

nwalters512
Copy link
Contributor

@nwalters512 nwalters512 commented Jun 15, 2022

If a Tooltip trigger has non-empty textContent that consists solely of whitespace, Bootstrap will remove the title but won't add an aria-label with the contents of title. Here's a reproduction of this: https://jsfiddle.net/nwalters512/7y8edzxr/7/. This is a poor experience for folks using screen readers, as they won't have any accessible label for the trigger.

This PR changes the JS to check the falseyness of textContent.trim() instead of textContent directly.

Copy link

@hebertcisco hebertcisco left a comment

Choose a reason for hiding this comment

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

It was really helpful to use the String.prototype.trim() method to handle white space, it's the right thing to do.

@GeoSot
Copy link
Member

GeoSot commented Jun 20, 2022

Thank you, @nwalters512 .
I am not sure is valid to auto-trim given strings, as it may be given on purpose (yes, of course, out of logic, as many other things I cannot understand myself)

As handy it may be, please try to add some tests to support your PR, and I would suggest making this change easy to applied everywhere. So probably, the best place is the TemplateFactory

@nwalters512
Copy link
Contributor Author

@GeoSot I can try adding some tests! Re: your recommendation to make this change in TemplateFactory, it's not clear to me how that would work, as none of the existing code in _fixTitle() is touching that. It's also not clear to me how much of this is actually reusable - this "fix title" seems pretty specific to tooltips.

@nwalters512
Copy link
Contributor Author

I added a test case in e2900e9. I verified that it failed before this change and now passes.

@GeoSot
Copy link
Member

GeoSot commented Jul 4, 2022

@nwalters51 I have understood your suggestion and the cause of the issue.
I am sorry for the misleading answer as my previous comment was out of topic

Many thanks for your help here

@GeoSot GeoSot removed the needs tests label Jul 5, 2022
@julien-deramond julien-deramond self-requested a review July 6, 2022 05:12
@julien-deramond julien-deramond merged commit 3f324ee into twbs:main Jul 6, 2022
@nwalters512 nwalters512 deleted the fix-tooltip-label branch June 7, 2023 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants