-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(TooltipDefinition): support different elements as tooltip trigger #3986
Conversation
89de514
to
74105d8
Compare
Deploy preview for the-carbon-components ready! Built with commit 89de514 https://deploy-preview-3986--the-carbon-components.netlify.com |
Deploy preview for carbon-elements ready! Built with commit 89de514 |
Deploy preview for carbon-components-react ready! Built with commit 89de514 https://deploy-preview-3986--carbon-components-react.netlify.com |
Deploy preview for the-carbon-components ready! Built with commit b41ce29 https://deploy-preview-3986--the-carbon-components.netlify.com |
Deploy preview for carbon-components-react ready! Built with commit b41ce29 https://deploy-preview-3986--carbon-components-react.netlify.com |
Deploy preview for carbon-elements ready! Built with commit b41ce29 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for flexibility @emyarod! To go further on that, I'd go for renderTrigger
approach instead of as
approach.
74105d8
to
f436575
Compare
Why do we want this? I looked at the referenced issue that references a closed PR and I'm still not sure. Can you elaborate on why we'd want to do this? Also worth noting in your PR description (to make reviewing and testing simpler) is that it's not any element. It's a |
to remove the restriction on our React definition tooltip where the trigger element is a button
not sure what you mean by this since |
const triggerElementMap = { | ||
button: undefined, | ||
div: ({ id, children, ...props }) => ( | ||
<div aria-describedby={id} {...props}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-describedby
is intended for interactive elements and will be ignored by NVDA, VoiceOver when applied to divs and spans. This would need an interactive role of some kind to function as intended. The implicit role we get with button
covered us here, but now that we're allowing non-semantic markup maybe a role="tooltip"
would make up the difference. I'd need to test further once the changes were made.
https://developer.paciellogroup.com/blog/2017/07/short-note-on-aria-label-aria-labelledby-and-aria-describedby/
https://www.w3.org/TR/using-aria/#label-support
Also worth noting is when using aria-describedby
in Internet Explorer. MS requires the referenced element (via ID) be a Microsoft Accessible Element. Essentially it needs to have proper roles etc.
NOTE: this comment also applies to every other instance of this pattern throughout the rest of the PR. I'll keep it to one comment to avoid clutter/noise.
Why? |
To me, we need a firm reason why we'd want to subvert the established pattern (tooltips thrown by buttons) and "added flexibility" is not good enough considering the increased complexity and accessibility concerns introduced. |
f436575
to
8830b9e
Compare
@dakahn it's not our intention to make trigger elements I'm not sure where the added concerns about complexity and accessibility come from since the default behavior is unchanged, and we can't account for modifications by the user. but this PR removes a restriction on our definition tooltips which was found only in the React implementation. does that clarify things? |
@joshblack just to clarify, the default behavior is not changing and the trigger element will still be a if the concern is about the render prop providing too much flexibility we can revert to using the |
@emyarod all I’m trying to understand are what use-cases or problems are solved by this diff. I don’t think I understand yet what utility we gain for allowing flexible tags and naively it looks like an easy way to mess up the control (like in the storybook) in a way that seemingly is allowed by the library through the proposed changes. |
…rigger-button-base-elements
@joshblack the utility of this feature lies in allowing different elements launch tooltips, like links or other inputs. otherwise in those scenarios you end up with nested interactive elements and only the parent element launching the tooltip. in terms of implementation and documentation, if we are concerned about render props then we can revert to the |
@emyarod what kind of markup do these situations end up having? (roughly) |
@joshblack an example would be a tooltip attached to a link. currently with our React component it would be wrapped by a <button {...tooltipClasses}>
<a {...linkClasses}>Link</a>
</button> the tooltip would also not be visible when the link itself is focused (the second tab stop), it would only be visible when the button is focused (the first tab stop) |
@emyarod how do the proposed changes change the markup you shared for the as-is? |
@joshblack prior to the latest PR commit you would be able to set the element for the tooltip trigger with the |
@emyarod it would help out a ton if you could share the full markup of what you're envisioning the example you shared will become, that's what is tripping me up right now. The reason I ask is that changing the markup seems like it might not help as we are still dealing with two interactive nodes. If we change the tag to something non-interactive, then the tooltip itself will break due to either focus or If you have some examples to show how this could work, that would help me understand 👍 |
@joshblack with the render prop (or alternatively the for example the output of using <div class="bx--tooltip">
<button class="bx--tooltip--trigger">
<a href="/">Tooltip trigger text</a>
</button>
<div class="bx--assistive-text">Tooltip content</div>
</div> where a button is always the trigger element to <div class="bx--tooltip">
<a class="bx--tooltip--trigger" href="/">Tooltip trigger text</a>
<div class="bx--assistive-text">Tooltip content</div>
</div> if the issue is with the demo code as I mentioned it can be revised to better illustrate the feature, but currently users are restricted to |
Perfect, thanks for helping me understand! 🙏 I'm totally down if we limit the alternative tag to an |
As an aside, should we just have a general purpose tooltip component that works for the tags defined in: https://developer.paciellogroup.com/blog/2017/07/short-note-on-aria-label-aria-labelledby-and-aria-describedby/ ? Surprised we'd be using definition tooltip as that seems specifically for defining an item or term |
we should probably reevaluate the 3 separate tooltips for the next release since the definition tooltip seems to be used as a general purpose tooltip when icon tooltips are too limited and when it is not desirable to bring in the normal interactive tooltip due to the lack of alignment options |
Agreed, @dakahn has some thoughts on this too where we have true tooltips and then non-modal dialogues which are toggle-able tooltips, or just toggletips. |
so do we want to revert to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By being opinionated about the element used we can ensure the definition is accessible through keyboard navigation. If you set the element knob to div
in the storybook the definition is now inaccessible to keyboard users.
This seems like a bit of a footgun if we're relying on developers to use elements that are focusable.
@vpicone the examples can be modified after the implementation details have been nailed down. so it sounds like the |
@emyarod to Vince's point can we limit the scope of acceptable triggering elements? Specifically if they're not traditional "interactable" elements we're gonna need to get tricky with our aria. Happy to kick the tires whenever we get some examples up though 👍 There is the other issue of our DefinitionTooltips being togglable (persistent on click) as a requirement. Meaning having a link as the triggering element isn't going to work, right? |
What is the end goal of this change? Is it to be used with the read-only input PR as the style for the tooltip? If that's the case, I think we need to circle back with design to see if that's the intended usage for |
it would be easier to limit the acceptable trigger elements if we revert back to the read only input is dependent on #4016 and not this PR. the end goal of this PR is to reduce the number of tab stops interactive/keyboard focusable elements (like links) launching tooltips. we can also include a guideline that while it is possible to make elements focusable with |
Wouldn't this be creating a different experience for keyboard users vs mouse? |
not sure what you mean by this since the number of tab stops will not affect mouse users |
Hey -- sorry, was the work requested completed? What's the status of this PR? |
closing as this doesn't seem to be a use case we want to deal with |
Closes #3985
This PR allows users to specify the element for the definition tooltip trigger button instead of hard coding it to be a
button
elementChangelog
New
renderTrigger
prop which takes a function and becomes the output element for the trigger buttonTesting / Reviewing
Ensure the
renderTrigger
prop functions as expected