In #1490402: Redesign tabs and the content header we introduced a new tooltip style for the shortcuts link in the header.

#2170947: Visual cleanup of Edit shortcuts link could use this same style and it's possible other interfaces could have a use for a tooltip. Let's abstract it out into it's own CSS component.

Remaining tasks

- Decide on an appropriate jQuery tooltip plugin
- Implement it
- Restyle the tooltip to match the tour tooltips
- Test in Bartik and Stark

Comments

lewisnyman’s picture

Issue summary: View changes
lewisnyman’s picture

Related issues: +#1921044: Align the styling of tool tips to be more consistent with Seven
lewisnyman’s picture

Status: Active » Needs review
StatusFileSize
new4.79 KB

That was easier than I thought.

lewisnyman’s picture

Once #1921044: Align the styling of tool tips to be more consistent with Seven is committed, we should definitely try and bring the two closer together.

philipz’s picture

This looks good but the tooltip is always to the right of the parent element isn't it? Maybe there could be also a modifier class when it should be to the left like it needs to be in #2170947: Visual cleanup of Edit shortcuts link - comment #13.

Or we could add that when/if it really will be needed later :)

lewisnyman’s picture

Yeah I was thinking the same thing. We should probably add a little arrow similar to the tooltips in #1921044: Align the styling of tool tips to be more consistent with Seven

philipz’s picture

Absolutely! :) I was thinking the tool tips in joyride are looking nice with the arrow, little less opaque and with smaller radius (it looks smaller).

lewisnyman’s picture

Yeah, I think they should be able to share the same classes as long as we can wrangle the joyride templates enough. We will need a variant to change the radius but I can't decide if we should have a tooltip--small or tooltip--large variant.

lewisnyman’s picture

Issue tags: +JavaScript

The more I think about this, the more I think we should be using the title attribute and Javascript to create and style these tooltips. It would be good to get an opinion from a Javascript maintainer.

I know jQuery UI provides this functionality, bootstrap also provides a really nice attribute only API for this http://getbootstrap.com/javascript/#tooltips

lewisnyman’s picture

Issue summary: View changes

There are loads of ways of adding this tooltip functionality with just CSS. Should we do that instead? What are the browser requirements?

lewisnyman’s picture

Component: Seven theme » CSS
Issue tags: -JavaScript

I am 100% convinced we should do this is pure CSS. If we're going to use a library to do this (why not?) then we might as well add this to every theme. I'm going to work on a patch to add hint.css

lewisnyman’s picture

StatusFileSize
new9.61 KB

This needs theming to match Seven's tooltips but so cool :)

Status: Needs review » Needs work

The last submitted patch, 12: 2207383-tooltip-component-12.patch, failed testing.

lewisnyman’s picture

Status: Needs work » Needs review
Issue tags: +frontend
StatusFileSize
new3.29 KB
new12.28 KB

Added Seven CSS and attempted to fix failing tests

Status: Needs review » Needs work

The last submitted patch, 14: 2207383-tooltip-component-14.patch, failed testing.

lewisnyman’s picture

I've opened an issue with hint.css to separate out the styling so it's not so overbearing https://github.com/chinchang/hint.css/issues/80

sqndr’s picture

lewisnyman’s picture

Yep :) let's try and push forward on this

sqndr’s picture

Assigned: Unassigned » sqndr

I'll give this a go.

Update 1:
- I've applied the patch from Lewis. The tooltips look good, but the <em> tags are displayed as code. I'm looking for a solution for this at the moment.
- Screenshot of the issue be found here.

@LewisNyman: It's a bit off topic, but is there a style guide for these elements? Should I add some documentation on how developers/themers can use this new design element? Where can this documentation be found? ;-)

Update 2:
Small coding remarks:

+++ b/core/modules/shortcut/shortcut.module
@@ -393,14 +393,18 @@ function shortcut_preprocess_page(&$variables) {
+          'attributes' => array ('class' => array('hint--right'), 'data-hint' => $link_text, 'title' => $link_text)

- array () should be array() - so with no space.
- there should be a , at the end of the line.

sqndr’s picture

Issue summary: View changes
StatusFileSize
new12.34 KB
new1.09 KB

Here's a new patch with the small remarks from comment #19. Still needs work, since the <em>'s are an issue. I've updated the issue summary.

sqndr’s picture

Assigned: sqndr » Unassigned
sqndr’s picture

Status: Needs work » Needs review
StatusFileSize
new1.22 KB
new13.44 KB
new12.39 KB

OK. I've solved the issue with the <em>. I've changed the %shortcut_set into @shortcut_set .

Hint CSS in action!

sqndr’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 22: 2207383-tooltip-component-22.patch, failed testing.

sqndr’s picture

Issue summary: View changes

Change the Issue summary. Since we've made some changes to the html, the tests for the shortcut module are failing. These tests need some work.

lewisnyman’s picture

@LewisNyman: It's a bit off topic, but is there a style guide for these elements? Should I add some documentation on how developers/themers can use this new design element? Where can this documentation be found? ;-)

We do not have a good process for documenting the style guide yet, see #2102191: Discuss the availiable solutions to document the Seven style guide

I'm happy to start pushing along with that.

lewisnyman’s picture

Status: Needs work » Needs review
Issue tags: +Accessibility
StatusFileSize
new969 bytes
new13.46 KB

Ok, looks like we have to keep some text inside the link. That makes sense for screen readers anyway.

sqndr’s picture

+++ b/core/core.libraries.yml
@@ -281,6 +281,13 @@ html5shiv:
+      assets/vendor/hint.css/hint.css: { }

I don't think there should be a space?
{ } -> {}

The rest of the patch looks good.

sqndr’s picture

Status: Needs review » Needs work
Issue tags: +CSS novice, +Novice

To-do: Remove the space from the last patch. Added the novice tag.

pushpinderchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new367 bytes
new13.46 KB

Removed extra space as mentioned by @sqndr in #28 and #29. Please review the rerolled patch.

sqndr’s picture

Status: Needs review » Reviewed & tested by the community

@er.pushpinderrana - Thanks for change. Marking this as RTBC!

lewisnyman’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
Issue tags: -CSS novice, -Novice +Needs change record

I am happy for this to be committed now, as long as we have a follow up to implement hint.base.css when it lands in the master branch: https://github.com/chinchang/hint.css/blob/add-a-base-build/hint.base.css

We haven't really changed the mark up that much, and the new attributes don't affect accessibility, so I don't think this requires a hard accessibility review.

We need a change record because this is an API addition? Let's also give this a quick sanity check in Stark and Bartik.

mgifford’s picture

I just saw this.

There are still accessibility issues with hint.css https://github.com/chinchang/hint.css/issues/81

I'm happy to report that it works well with keyboard users.

The problems with screen readers may be that there's still no best practice that's well supported for tooltips.

I created this issue with hint.css:
https://github.com/chinchang/hint.css/issues/81

Also filed issues with NVDA & ChromeVox.

mgifford’s picture

Was there any consideration of http://jqueryui.com/tooltip/

This too has known accessibility issues:
https://www.ssbbartgroup.com/blog/2013/07/03/jquery-ui-accessibility-ana...

But I'm not clear what version it was tested against.

@falcon03 suggested that actually a year ago https://www.drupal.org/node/1919940#comment-7234280

Notes too from Twitter with @scott_gonzalez:
https://twitter.com/scott_gonzalez/status/484402080677777408
https://github.com/jquery/jquery-ui/commit/b9e438d07c370ac2d4b198048feb6...

This is probably the better way to proceed.

mgifford’s picture

Well, the jQuery Tooltips are certainly available:
core/assets/vendor/jquery.ui/ui/jquery.ui.tooltip.js

Seems pretty powerful http://www.tutorialspoint.com/jqueryui/jqueryui_tooltip.htm

I'm just not sure how to use it.

nod_’s picture

StatusFileSize
new13.71 KB
new2.21 KB

I'll be less categorical than sun is in #1919940-6: Build API to Replace Links using Title Attributes with Proper Accessible, Themable Tooltips, by saying that any solution that requires jQuery is a no-go. It'd mean we're back to jQuery (and some jQueryUI) being loaded on all pages.

I agree with him that it's not the place of Drupal to take care of this but if we can do something for a11y, why not.

That said, rerolled patch to use libraries properly.

lewisnyman’s picture

As a frontend dev, I would much rather use lightweight CSS plugin than a jquery plugin, jquery UI has always had terrible mark up and really annoying CSS to override. It looks like the author of hint.css recommends aria-label which looks like an accessible solution. If we add that to the implementation here, with a recommendation in documentation, is that enough?

sun’s picture

StatusFileSize
new70.06 KB
new68.15 KB

Fanciness may be an argument, but Accessibility is not a good argument to bring up for Hint.css, because its tooltips may appear outside of the visible viewport and are thus not accessible.

Hint.css:

Hint.css tooltips exceed visible viewport; text not readable.

Native UA tooltips:

Native Title UA tooltips can appear outside of the browser window to be readable.

For the UA demo, a title="" attribute was added to the download button on http://kushagragour.in/lab/hint/

UA tooltips can be displayed outside of the browser window, and they are automatically repositioned in case the tooltip does not fit on the screen.

Since purely CSS-positioned (ahead of rendering time), Hint.css tooltips are hard cut-off on the visible browser window viewport. The tooltip text does not soft-wrap even in situations in which the whole tooltip could fit on screen.

This applies to all possible tooltip directions, whereas the bottom and top directions are most problematic, since those may simply be rendered off-screen. In the right and bottom directions, a tooltip causes browser scrollbars to appear on hover on smaller screens.

Lastly, unless I'm missing something, the data-hint attribute is unknown to screen-readers, so any contained help text won't be announced. I assume the source attribute would have to be changed to consume one of the ARIA description attributes instead.

Bottom line: Hint.css looks like a great effort and library. I like the idea. But without some minimal JavaScript for positioning & text-wrapping (& scaling), I don't see how it can reliably work for tooltips in today's world of vastly different screen sizes. In its current form, it clearly introduces accessibility problems (even for users not having a visual disability).

lewisnyman’s picture

@sun Can we not just position them on the other side for these situations? eg. hint--left?

sun’s picture

The attempt to control layout/positioning in HTML (via classes) is conceptually flawed. Normally, layout/positioning exclusively belongs into CSS. However, CSS still lacks conditional screen/box selector constraints at the element level that would allow to prevent tooltips from appearing cut-off/incomplete or off-screen/invisible. At this point, the necessary level of positioning control can only be achieved through JS in a reliable way.

Due to that, we should move forward with a CSS + JS based solution.

I'm not sure why a potential dependency on jQuery presents any kind of problem? Tooltips normally appear on more complex user interfaces only (e.g., forms) and those pages have a very high probability of requiring jQuery either way already.

(That's not to be meant as an endorsement for the jQuery Tooltip library [there are popular alternatives], but only meant to say that I can't get behind the resistance to a JS based library.)

nod_’s picture

jQuery based library is my issue. But I guess one could just do away with the library and use the default browser tooltips.

lewisnyman’s picture

We could add this implementation just to Seven? Then it wouldn't affect frontend pages, most admin pages load jQuery anyway I assume.

There is a use case to add tooltips to some of the toolbar icons though, but the toolbar loads jQuery anyway so that isn't a problem.

lewisnyman’s picture

Issue summary: View changes
lewisnyman’s picture

Ok, it's a shame we can't do this is in pure CSS but I think using a jQuery plugin isn't going to upset anyone if this is going to be used on pages that load jQuery anyway, right @nod_?

I've updated the remaining tasks with this in mind.

nod_’s picture

I'm ok with implementing that with jQuery if it's Seven only.

droplet’s picture

Sites owner always expected more than just showing the hints, Pure CSS libs never able to fulfill their needs.

anyway, #1890266: dropbutton text fails to retain .dropbutton-widget width has same issue mentioned in Comment #38. (sometimes a hint could be a dropdown menu, just see how do you styling it.)

lewisnyman’s picture

StatusFileSize
new4.14 KB

Ok, here's a go at implementing jquery.ui.tooltip with the Seven styling.

It kinds of shows how much we use the title attribute all over the UI that aren't always obvious. We should probably have a data attribute to opt in to this styling. I kind of wish we were using a plugin with a more modern API.

Status: Needs review » Needs work

The last submitted patch, 47: tooltip-component-2207383-47.patch, failed testing.

lewisnyman’s picture

Status: Needs work » Needs review
StatusFileSize
new4.95 KB

I forgot to add the new files

Status: Needs review » Needs work

The last submitted patch, 49: tooltip-component-2207383-49.patch, failed testing.

nod_’s picture

Less code than expected, nice.

From what I tested, jquery handles the offscreen situation nicely but there are a few styling issues.

Background should be opaque, not transparent. It's not legible when there is text under the tooltip (which is very often). Position of the tooltip isn't helping much, either top or bottom is more helpful.

with $(document).tooltip(); and a black background the tooltips looks good enough.

lewisnyman’s picture

I would really like for it to be easy to change the position of the tooltip on a case per case basis, what works for some does not work great for others.

Also, the idea of using the tooltip for any element that has a 'title' attribute feels really flawed, we use the title attribute in lots of situations to provide context to screen reader users only, and the sometimes unnecessary information can be distracting for visual users. eg. The toolbar menu items. I'm guessing this is one of the reasons the tooltip for title attributes has effectively been removed from modern browsers.

Ideally we could do this without JS, similar to how hint.css uses variant classes. I'm tempted to explore another JS solution which has a more modern API :\

Anonymous’s picture

May be we can use something like this http://cssdeck.com/labs/hint-css-tooltip
We should take tooltip text from some data attribute, for exmple data-tooltip.

lewisnyman’s picture

@bobrov1989 If you read through the initial comments that idea what shot down because it's impossible to adjust the position based on viewport width/height. I would still prefer that over nothing...

mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Postponed

Would love to have it, but....

joelpittet’s picture

Status: Postponed » Active

Open for business

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

emma.maria’s picture

Issue tags: +Needs design, +Usability

Added tags + updated to 8.2.x.

Note: Discussion for a solution is very much needed before any patches appear for this issue.

yoroy’s picture

Design solutions should probably also take the design of the Tour module call-outs into account.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

We need to keep in mind WCAG 2.1 when building this.

Success Criterion 1.4.13 Content on Hover or Focus

"Where receiving and removing pointer hover or keyboard focus triggers additional content to become visible and hidden, respectively, the following are true:

Dismissable
- A mechanism is available to dismiss the additional content without moving pointer hover or keyboard focus, unless the additional content communicates an input error or does not obscure or replace other content;
Hoverable
- If pointer hover can trigger the additional content, then the pointer can be moved over the additional content without the additional content disappearing;
Persistent
- The additional content remains visible until the hover or focus trigger is removed, the user dismisses it, or its information is no longer valid.

Exception: The visual presentation of the additional content is controlled by the user agent and is not modified by the author."

andrewmacpherson’s picture

Thanks for linking the WCAG 2.1 criterion. More information is available in the draft of Understanding Content on Hover or Focus, with diagrams.

The WAI-ARIA Authoring Practices includes a pattern for accessible behaviours of a tooltip widget. If we follow this, we'll need some ARIA attributes to establish the tooltip role and relationship with the trigger element.

A few things about the WCAG 2.1 Success Criterion 1.4.13 Content on Hover or Focus...

Dismissable
- A mechanism is available to dismiss the additional content without moving pointer hover or keyboard focus, unless the additional content communicates an input error or does not obscure or replace other content;

The WAI-ARIA Authoring Practices assumes the escape key will provide the means of dismissing the tooltip. This would rule out a pure-CSS approach.

Hoverable
- If pointer hover can trigger the additional content, then the pointer can be moved over the additional content without the additional content disappearing;

This is important for screen magnifiers. A tooltip may be too large to fit inside the magnifier's viewport, so moving the pointer over the tooltip itself may be necessary in order to read it all. If the tooltip is offset from the trigger in any way (e.g. speech bubble style, with a connecting triangle) then we'd need to account for moving the pointer across a short empty area, e.g. use a slight delay before it disappears.

Exception: The visual presentation of the additional content is controlled by the user agent and is not modified by the author.

Basically, this means the HTML title attribute is exempt from this WCAG criterion. But that's a cop-out really - the point of this issue is that we want accessible tooltips, and the HTML title attribute won't suffice. The Understanding Content on Hover or Focus draft explains: "This criterion does not attempt to solve such issues when the appearance of the additional content is completely controlled by the user agent. A prominent example is the common behavior of browsers to display the title attribute in HTML as a small tooltip.".

The "add to shortcuts" tooltip in Seven passes this success criterion. For dismissable, it passes because it doesn't obscure any content. That's not because of the component itself though, it's because nothing is placed after it in that region.

andrewmacpherson’s picture

Forgot to say, I'd like to follow the ARIA Authoring Practices on this one.

volkerk’s picture

StatusFileSize
new7.57 KB

Reworked #49 for 8.6.x

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Status: Active » Needs review

Thanks for the patch @volkerk - I'm just moving this to Needs Review as that way the bot will check it. Core's probably moved since then, so....

Sorry it took me 6 months to notice your patch!!!

Do you have any screenshots of it?

Also wanted to post Scott Vinkle's Tooltip solution so we'd have that in the mix:
https://inclusive-components.design/tooltips-toggletips/

Status: Needs review » Needs work

The last submitted patch, 70: tooltip-component-2207383-70.patch, failed testing. View results

kostyashupenko’s picture

Issue tags: +Needs reroll
kostyashupenko’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new7.58 KB

Status: Needs review » Needs work

The last submitted patch, 75: tooltip-component-2207383-75.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kostyashupenko’s picture

During reroll i got only 1 conflict here
/core/modules/shortcut/shortcut.module -L 359

<<<<<<< 3ba6bc11689c4691063a46ac03ef933885f16f2b
        '#title' => new FormattableMarkup('<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>', ['@text' => $link_text]),
=======
        '#title' => SafeMarkup::format('<span class="shortcut-action__icon"><span class="shortcut-action__message">@text</span></span>', ['@text' => $link_text]),
>>>>>>> Applying patch from issue 2207383 comment 12571588

so i changed in on
'#title' => new FormattableMarkup('<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>', ['@text' => $link_text]),

andypost’s picture

I see no reason to use formattable markup here - it looks more like inline template

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Here's an approach to using tooltips with WCAG 2.1 - https://sarahmhigley.com/writing/tooltips-in-wcag-21/

bojanz’s picture

Note that core is about to adopt Popper.js in #3074267: Replace jQuery UI position() with PopperJS.

Popper.js has an optional Tooltip,js addon which might be useful here: https://popper.js.org/tooltip-examples.html

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mherchel’s picture

Status: Needs work » Closed (outdated)
Issue tags: -JavaScript +JavaScript

Closing this as outdated since PopperJS now exists (see comment #81)

mgifford’s picture

Updated link to the one provided by @bojanz in #81 above. Should be https://popper.js.org/docs/v2/modifiers/offset/ or something like that.