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

feat(tooltip): allow custom CSS classes for displaying tooltips #4016

Conversation

emyarod
Copy link
Member

@emyarod emyarod commented Sep 18, 2019

Closes #4015

This PR extracts the tooltip display code in a new mixin called tooltip--visible()

Changelog

New

  • tooltip--visible() Sass mixin containing style rules needed to display definition and icon tooltips

Changed

  • refactor tooltip positioning selectors to remove unneeded :hover and :focus selectors

Testing / Reviewing

  1. Create a new tooltip example with test classes (in this example, it is .bx--test and .bx--test--focus)
<div class="{{@root.prefix}}--tooltip--definition {{@root.prefix}}--tooltip--a11y">
  <button
    class="{{@root.prefix}}--tooltip__trigger {{@root.prefix}}--tooltip--a11y {{@root.prefix}}--tooltip--left {{@root.prefix}}--tooltip--align-start">
    <span class="{{@root.prefix}}--assistive-text">Filter</span>
    {{ carbon-icon 'Filter16' }}
  </button>
  <span aria-describedby="test"
    class="{{@root.prefix}}--test {{@root.prefix}}--tooltip--a11y {{@root.prefix}}--test--focus">
    Definition Tooltip (open)
  </span>
  <div class="bx--assistive-text" id="test" role="tooltip">Brief description of the dotted, underlined word
    above.</div>
</div>
  1. apply the default tooltip mixins and the new tooltip mixin to the test classes
.#{$prefix}--test {
  @include tooltip--trigger('definition', 'bottom');
  @include tooltip--placement('definition', 'bottom', 'center');
}

.#{$prefix}--test--focus {
  @include tooltip--visible();
}

ensure that the tooltip is open by default and ensure existing tooltip implementation is not broken

@emyarod emyarod requested a review from a team as a code owner September 18, 2019 03:02
@ghost ghost requested review from alisonjoseph and joshblack September 18, 2019 03:02
@emyarod emyarod force-pushed the 4015-support-custom-css-class-for-showing-tooltips branch from b64f389 to 44f6d2d Compare September 18, 2019 03:03
@emyarod
Copy link
Member Author

emyarod commented Sep 18, 2019

cc @elizabethsjudd due to overlap with #3115 #3151

@netlify
Copy link

netlify bot commented Sep 18, 2019

Deploy preview for the-carbon-components ready!

Built with commit b64f389

https://deploy-preview-4016--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Sep 18, 2019

Deploy preview for carbon-components-react ready!

Built with commit b64f389

https://deploy-preview-4016--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Sep 18, 2019

Deploy preview for carbon-elements ready!

Built with commit b64f389

https://deploy-preview-4016--carbon-elements.netlify.com

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

🎉 - Thanks @emyarod!

@elizabethsjudd We are making a change to ally style rules like https://github.com/carbon-design-system/carbon/blob/v10.6.0/packages/components/src/globals/scss/_tooltip.scss#L92-L107 regardless of tooltip's active state, wanted to make sure it won't cause any adverse effect to what you implemented. Thanks!

packages/components/src/globals/scss/_tooltip.scss Outdated Show resolved Hide resolved
@netlify
Copy link

netlify bot commented Sep 18, 2019

Deploy preview for the-carbon-components ready!

Built with commit 363fb0a

https://deploy-preview-4016--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Sep 18, 2019

Deploy preview for carbon-components-react ready!

Built with commit 363fb0a

https://deploy-preview-4016--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Sep 18, 2019

Deploy preview for carbon-elements ready!

Built with commit 363fb0a

https://deploy-preview-4016--carbon-elements.netlify.com

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

I feel like this is a larger change that we should first decide on in the issue before bringing on an implementation as this heavily ties into tooltips and our ability to make sure they're accessible. I think there are also other approaches we might be able to take on here if we need a generalized tooltip component for these cases

@emyarod
Copy link
Member Author

emyarod commented Sep 19, 2019

Let’s go with a staged approach to help read-only text input go forward

  • Slight API change that helps achieve the read-only text input
  • re-examination of the feature set and architecture of the tooltip as a whole afterwards

&:hover + .#{$prefix}--assistive-text,
&:focus + .#{$prefix}--assistive-text {
.#{$prefix}--assistive-text,
+ .#{$prefix}--assistive-text {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand what this sibling selector is doing?

Copy link
Member Author

Choose a reason for hiding this comment

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

prior to #3115 and #3151 we used ::after pseudoelements to create the tooltip body. this pattern was changed in those PRs so that the tooltip body is now a div (div.bx--assistive-text), which can be a sibling or child of the tooltip trigger

the current PR just does these things: deduplicate and simplify selectors, and extract the styles for displaying the tooltip into a mixin

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, do we still need the &::after rule then?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes until the next major version release (for backwards compatibility)

// Forces visible state for definition and icon only tooltip
/// @access public
/// @group tooltip
@mixin tooltip--visible() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this mixin meant to be public/used elsewhere? Seems unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm ok with making it private, the idea was to allow the "tooltip visible" rules to be applied to the tooltip trigger wrapper when the tooltip trigger itself cannot display the tooltip properly (e.g. when the trigger is an input field/form control)

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Can we defer on read-only until there is a project that can take it on? Seems like there are a couple tooltip-related decisions that it impacts and I'd hate to introduce broader changes without giving it more thought.

@asudoh
Copy link
Contributor

asudoh commented Sep 23, 2019

Let's limit the scope of tooltip change to introducing a CSS class for the focused state, as what this PR does, to have the read-only text input feature to go forward.

@alisonjoseph alisonjoseph removed their request for review October 8, 2019 15:15
@vpicone
Copy link
Contributor

vpicone commented Oct 10, 2019

Should we close this? Not sure if the issue it's attached to is still a concern?

@asudoh
Copy link
Contributor

asudoh commented Oct 10, 2019

@shixiedesign @carbon-design-system/design Do we still want tooltip shown on read-only test input as its focused? Asking this question because #4015 and this PR seems for enhancing tooltip style for that purpose. Thanks!


.#{$prefix}--assistive-text,
+ .#{$prefix}--assistive-text {
clip: auto;
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't clip: auto the default? Is the a reason we set it here?

Copy link
Contributor

@vpicone vpicone left a comment

Choose a reason for hiding this comment

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

Not sure we're still pursuing this but lgtm!

@joshblack
Copy link
Contributor

Should we go ahead and close this unless there is a designer/dev on a project team that can pick this up?

@asudoh
Copy link
Contributor

asudoh commented Oct 18, 2019

@emyarod I think you are still pursuing this, is it correct?

@emyarod
Copy link
Member Author

emyarod commented Oct 21, 2019

yes the remaining work is complete minus the tooltip behavior which depends on this PR

@aagonzales
Copy link
Member

I don't know the history of this problem and Shixie has been off-boarded, but was tooltip added to read-only text input as a band-aid? Why was it needed in the first place?

How do I see the read-only variant? I don't see a knob for that in the story book.

@joshblack
Copy link
Contributor

We should try and save this for when a project team can work on/address this. I think the decisions made for this have broad impact and could require alignment from design/dev/a11y which are hard when we're all working on a different project at the moment 👍

@joshblack
Copy link
Contributor

Going to close this until we can pick things back up 👍

@joshblack joshblack closed this Nov 6, 2019
@emyarod emyarod deleted the 4015-support-custom-css-class-for-showing-tooltips branch August 30, 2021 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ability to define a CSS class to forcibly display tooltips
5 participants