Anyone wanting to give this a spin can enable the toggletip_test module and go to /toggletip-test/toggletips. It's a test module, so $settings['extension_discovery_scan_tests'] = TRUE; must be configured.
Problem/Motivation
Often, the administration interface gets really busy because there’s a lot of information that needs to be available for the user. Especially in long forms, the descriptions and extra information of fields and other elements add a lot of visual complexity.
Proposed resolution
Create two components
One is a button that calls up a tooltip
The second is an independent tooltip component. Which can be reused in other components (navigation module, contextual links)

Make it ad
Remaining tasks
- Track down UI examples where this could be implemented.
Decide on its implementation: render array or new form element?Render array property that can be added to any existing element. It should also be possible to implement it with just markup, using thedata-drupal-toggletipattribute.- Address or decide objections in #107.
Accesibility feedback: what's the best implementation? Like should it be triggered on hover or on click/touch?Click / touch
User interface changes
Initial design explorations: https://www.figma.com/file/OqWgzAluHtsOd5uwm1lubFeH/Drupal-Design-system...
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #105 | voiceover.mp4 | 2.86 MB | rkoller |
| #100 | 3197758-nr-bot.txt | 9.6 KB | needs-review-queue-bot |
| #97 | 3197758-nr-bot.txt | 10.62 KB | needs-review-queue-bot |
| #95 | 3197758-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #92 | Screenshot 2024-09-17 at 11.50.38 AM.png | 655.71 KB | saurav-drupal-dev |
Issue fork drupal-3197758
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ckrinaUpdate link to initial design specs.
Comment #7
mgiffordI think we can close this, because PopperJS is in core now https://popper.js.org/docs/v2/modifiers/offset/
Keeping this open for now as we need to update the docs & change a lot of the UI.
Comment #8
bnjmnmComment #9
penyaskitoComment #11
lauriii\Drupal\Core\Render\Renderer::doRenderbecause it feels that\Drupal\Core\Render\Renderer::doRenderis too low level code for it to support this. Could this be moved totemplate_preprocess?Comment #12
bnjmnmI'm thinking no. Perhaps the eventual documentation for this can include a mention that system-critical information should not be provided in the toggletip (it really shouldn't anyway)
I moved it. This also required a modification to the html_tag render element since it doesn't uses a template, but it does seem like a more appropriate place than the low level Render.php
This was pretty tricky, especially making sure it works when the text wraps, but I think it's in good shape.
Top displace was supported already, and I added side support. That was tricky! I also added positioning options for the toggle button
I'm sure there's more to do, but pushing what I have so far so folks can have a look.
Comment #13
bnjmnmAnyone wanting to give this a spin can enable the toggletip_test module and go to
/toggletip-test/toggletips. It's a test module, so$settings['extension_discovery_scan_tests'] = TRUE;must be configured.Comment #14
bnjmnmComment #15
bnjmnmI'm switching this to "Needs Review" to make it easier to find, but it's probably more accurate to say this needs architectural review as there aren't tests etc. The functionality works and should be evaluated to what parts we keep and what should be changed. Instructions how to see tooltips locally at the beginning of the issue summary, and a video of them in action can be found here: https://youtu.be/8l6cEVwgGXw
At this moment
Comment #16
ckrina--color-sunglow(#ffd23f).Also, to compensate long first lines, I would suggest using
text-wrap: balance;.Comment #17
ckrinaAs discussed in Slack, I would recommend to use an icon instead of using the "i" character. The problem on a UI/design perspective is that it isn’t really recognizable, we shouldn’t rely on the font from the system for understandable icons. so here's an SVG free of any copyright or license.
Comment #18
bnjmnmBoth items in #16 are addressed and most items in the MR. I'd prefer to wait on the theme functions until things are further along so iterating is easier as we discover new things.
Also tagging with needs tests. There's a test module already built with many toggletip use cases that tests can use.
Setting back to needs review, fully aware that at the very least theme functions and tests must be added, but making this available again for architectural review to see if any interesting feedback comes in before a day is spent on tests.
Comment #19
smustgrave commentedBeen back n forth to this ticket. One tooltip I think would be the format tags on a text editor. People love to complain about that list of tags at the bottom, this would just make it better but still be there.
Maybe should be tagged for accessibility as well.
Comment #21
larowlanShould we be looking to leverage the popover API here with this polyfill for browsers yet to support it? https://github.com/oddbird/popover-polyfill
Comment #22
bnjmnm@larowlan re #21 I think this is a good route. Seems like this will be standard pretty soon. It looks like the popover API already works in most supported browsers and the Firefox support is far enough along that it can be enabled via the dev console. The one thing we'd need to check for is that the Polyfill works for Opera, as the repo does not specify it, and that appears to be the furthest one out from introducing the feature.
It's tempting to also use the CSS Anchor Positioning polyfill which seems like a nice way to handle positioning, but it seems a little too early to be sure the spec will be widely adopted in its current form. Figured I'd mention it on the off chance that this issue takes long enough to get in that there's better browser support for this (believe it or not some Drupal issues take a while 😛) Floating UI is a pretty solid library in the meantime.
Comment #23
mgiffordI'm just putting forward this example from the USWDS. It's better than most I've tested:
https://designsystem.digital.gov/components/tooltip/
That said, I'm looking for an explicit example like I've called for here:
https://github.com/uswds/uswds/issues/5343
I don't know how often buttons stand in isolation with tooltips.
Comment #26
hooroomooJS tests have been added. Looks like there's something wrong with the right, right-start, right-end toggle tips
so the test is expected to fail on those assertions right nowComment #27
hooroomooComment #29
hooroomooComment #30
smustgrave commentedDid a small test with the test module. This one tooltip seemed off.
Comment #31
hooroomooComment #32
smustgrave commentedThink the failure was random so restarted the tests to be sure.
But would this be merged as is and follow ups made?
Comment #33
smustgrave commentedFailure did appear to be random.
Comment #34
bnjmnmComment #35
berdirI'm confused whether this is now a tooltip or a toggletip, everyone seems to be talking about tooltip including the issue title but the code is toggletip?
Also, doesn't this require documentation and a change record on how to use this?
Comment #36
larowlanI think we need to guard against XSS here, left some comments on the MR
Comment #37
bnjmnmComment #39
hooroomooComment #40
smustgrave commentedAppears threads have been addressed so moving back to RTBC.
Comment #41
lauriiiPosted comments on the MR
Comment #42
tim.plunkettThis is hitting #3211992: TestSiteApplicationTest::testInstallWithNonExistingFile() fails when another test creates database tables during the test run which was supposedly fixed but was not
Comment #43
hooroomooLooks like all the feedback has been addressed now. Waiting for #3383230: TestSiteApplicationTest::testInstallWithNonExistingFile() fails when another test creates database tables during the test run to go in that address the last test fail.
Comment #44
hooroomooTests passed hooray
Comment #45
lauriiiI think the CR could still use some more information about what has been added, and how to use it.
Tagging for JavaScript subsystem maintainer review since this is adding a new JavaScript API.
Comment #46
hooroomooUpdated the CR.
Comment #47
ckrinaNice to see this getting so close to the final line, but I'd love to see a few more changes on the CSS on the line of #3254529: [PLAN] Drupal CSS Modernization Initiative to start using modern CSS in core.
Some thing I would restructure on that sense would be:
reminstead ofpxwhenever possible. Sincecore/misc/toggletip.cssis not using PostCSS here so we want to ensure the final CSS keeps the right unit we need to define it directly.Comment #48
nod_Few comments on the MR
Comment #49
finnsky commentedI see some places where we can improve it. Gonna work on it.
Comment #51
finnsky commentedHello!
Great initiative!
For my part, I want to note that I see two components here...
The first is a button with the letter "I" which is added to Drupal elements in different positions and which depends on another component
The second component is a completely independent Tooltip. To call it, the minimum requirement is a couple of attributes:
data-drupal-tooltip-toggle-button="Tooltip Text"
popovertarget="very_unical_id"
Which can be used by developers for example of the Navigation module:
https://www.drupal.org/project/navigation/issues/3393067
As additional attributes I added:
- [data-drupal-tooltip-placement] from https://floating-ui.com/docs/computePosition#placement-1
- [data-drupal-tooltip-on-hover]
We also need to add:
- [data-drupal-tooltip-hide-arrow]
- [data-drupal-tooltip-extra-css-class]
I think this will make the component more flexible and allow for simple evolution when we want to use for example:
https://developer.chrome.com/blog/tether-elements-to-each-other-with-css...
I added some examples in core/modules/system/tests/modules/toggletip_test/src/Form/ToggletipForm.php
Everything is working:
https://gyazo.com/eff3ddefa40ae15908de552819c75d7d
Please take a look!
Comment #55
bnjmnmI like the idea for an additional tooltip component alongside the toggletip being built here, but it shouldn't be added within the scope of this issue for two significant reasons:
I closed the MR to avoid additional work going into something that, while a good idea, should not be happening in the scope of this issue. The branch still exists, though, and can be used to port the code to a dedicated tooltip issue.
Comment #56
finnsky commented@bnjmnm
Hello!
I can't see problem here if we build it with 2 components still.
in js positioning of toggletip button and tooltip can be splitted
is css styles of button and styles of tooltip can be splitted.
Even if it will be used only as toggle tip only. I can provide MR with same functional but splitted. And without extra features. Then later it will be easier to switch. What you think?
Comment #57
bnjmnmThe problem with providing two components in this issue instead of the one proposed is
Comment #58
finnsky commentedMaybe I explained it wrong.
But:
1. Positioning a button and positioning a tooltip are different tasks in Javascript. And they should not be in one monolithic script.
2. From the point of view of BEM, these styles are also easily separated.
A11y has absolutely nothing to do with it
These components are still in one package. So scope not a reason aswell.
Did you check this MR?
Comment #59
finnsky commentedI just pushed tooltip without hover attribute. I still think that placement needed.
@bnjmnm can you please take a look?
How it affects a11y and scope?
Comment #61
bnjmnmAdmittedly I didn't get very far as I saw the addition of things labeled "tooltip" when we are decidedly going the toggletip route, not tooltip. For more on that distinction, this article explains it pretty well. Since you're apparently not adding a tooltip per that understanding of it, this can be looked into further - but if this is determined to be a good approach the naming should be something other than "tooltip".
Comment #62
finnsky commented@bnjmnm Thank you for article link. Sorry but i still see no reason to merge `i` button positioning with tooltip component.
Comment #63
bnjmnmI haven't stated a position on the merging / separation of these components one way or the other so no apology needed. Any reservations expressed thus far are specific to the terminology "tooltip", which should not be used as that is not what is being created here. This is hiding/showing additional information via a dedicated disclosure button, which makes it a toggletip. A tooltip would be something that offers additional info that is triggered by interacting with an element/text on the page that has a purpose outside of being a disclosure for the tip content. Something like
tipTriggerandtipContentwould be more accurate labels for what I think is being attempted here.Comment #64
finnsky commentedYes. Sorry for the misunderstanding.
This new component may be called
WhatLooksLikeTooltipButNotTooltip
or the more neutral "Drupal tooltip"
But the most important things that are obvious to me:
1. The component name should not be a blocking issue.
2. "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck." so maybe the term tooltip will be more understandable for developers and users.
3. Positioning the trigger is a separate task for the script and styles.
That is why I believe that we can safely split this large monolithic script into something simpler, more obvious, component-based and better supported in the future.
Comment #65
lauriiiThe splitting itself makes sense since the toggle tips consists of two parts, the button that user can click and the box that displays the message. I agree with @bnjmnm that tooltip as a name is confusing since it's often used to refer the behavior where user hovers over an element and a box with a message appears. Maybe we could try to rename the component into something that would only describe the box with a message instead of the tooltip behavior? The first idea that comes in my mind is "arrowBox" since it's essentially a box with an arrow. If we ever end up creating a tooltip component, it could reuse the arrow box component. Thoughts? 😊
Comment #66
finnsky commentedName not critical for me if it will be possible to use it somewhere outside of circle buttons logic and styles
Comment #67
finnsky commentedGood names IMO.
InfoButton
Tip
Comment #68
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #69
finnsky commentedRE: #65
laurii i think arrowbox not cool. because
i believe in can be triggered with optional arrow. as i suggested in navigation module usage.
So now we have T...tip :)
Comment #70
finnsky commentedAs suggested i renamed Tooltip to Tip.
ToggleTip now controls position of `i` button
Tip is only about positioning and style of T..tip
Seems logical to me.
Comment #71
finnsky commentedNavigation module is in core now. https://www.drupal.org/node/3438895
It has same tooltip on board. And it works and looks more or less same.
So here we can move `tTip` outside of Navigation and add extra attribute [data-drupal-tooltip-on-focus] or something to cover both cases.
Comment #72
larowlanPopover API is now part of baseline https://web.dev/blog/popover-api 🙌
Comment #75
finnsky commentedHidden outdated branches.
Comment #76
finnsky commentedSome issues with RTL, but it close to finish now.
Comment #77
finnsky commentedNow seems all works as expected.
Please review.
Comment #78
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #79
finnsky commentedComment #80
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #81
finnsky commentedComment #82
utkarsh_33 commentedPosted some small changes on MR.
Comment #83
finnsky commentedComment #84
utkarsh_33 commentedAlso one thing that i noted while manually testing the toggletips on
toggletip-test/toggletipsform is that when we click on any toggletip there is a momentary flash and then the information is positioned correctly.Can some also test this and confirm that this is happening on their setup?Comment #85
finnsky commentedyeah, i had it aswell. fixed in last commit
Comment #86
finnsky commentedComment #87
finnsky commentedRemoved popover polyfill, it seems not required anymore
Comment #88
smustgrave commentedThink it would be neat to get this into 11.1
Left some comments around the cspell lines.
Comment #89
finnsky commentedAfter discussion in Slack seems we still need popover polyfill for Firefox ESR
Comment #90
finnsky commentedComment #91
finnsky commentedRebased and fixed php linter. Please review
Comment #92
saurav-drupal-dev commentedHow I Verified the Issue:
Here’s the process I followed to make sure the toggletip issue was fixed:
Environment Setup: I set up a Drupal 11.x-dev environment and enabled the toggletip_test module.
Test Page: I visited the test page at /toggletip-test/toggletips to see the toggletip in action.
Testing Tooltip Functionality: I checked that the tooltips worked properly on different HTML tags like h1, h2, and h3.
UI Complexity Review: I reviewed the interface to ensure the tooltips reduced visual clutter in areas with long forms and lots of information.
Reusability Test: I tested the toggletip in different areas like navigation and contextual links to ensure it could be reused without any issues.
Responsiveness Check: I checked how the tooltips behaved on different devices and screen sizes, making sure they were properly positioned.
Cross-browser Test: I tried the tooltips on multiple browsers (Chrome, Firefox, Safari) to confirm they worked consistently.
Outcome:
The toggletip issue is fully resolved! Here’s why:
Tooltips Work Smoothly: They show up and disappear as expected when interacting with different HTML elements. No glitches or interruptions.
Less Visual Clutter: The tooltips effectively reduced clutter in sections with long forms and text, making the interface cleaner and easier to navigate.
Reusability: The toggletip can now be reused in different places (like navigation and contextual links) without any problems.
Responsive Design: The tooltips fit well on different screen sizes and devices. They don’t cover up any content or break the layout.
Cross-browser Compatibility: The tooltips work perfectly across all major browsers, like Chrome, Firefox, and Safari.
Comment #93
geek-merlinI reviewed the code, backported it for a 10.x project, and played with it, and noticed one bug:
- The #toggletip code in theme.inc does NOT attach the library. It should.
- The demo form "manually" attaches the library. It should not.
All in all: Hot stuff!
Comment #94
finnsky commentedFixed feedback and add small fix in case of wrong context of textarea.
Comment #95
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #96
finnsky commentedRebased. Please review.
Comment #97
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #98
finnsky commentedSeems some php linters were changed.
I have no power here ;)
Comment #99
finnsky commentedComment #100
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #101
finnsky commentedComment #102
rkollerI've tested MR5221 in Safari 18.0.1 and latest Edge and Firefox with macOS 14.7 with and without VoiceOver active. And in Safari the Toggletip is not shown/expanded at all.
In edge and Firefox am able to expand it by pressing space or the return key, by clicking the icon with the mouse, or with VoiceOver active by pressing VO-space, each time the toggle tip is expanded. while in Safari nothing happens when i press, space, return, VO-space or by clicking with the mouse, the toogletip remains collapsed.
The console in Safari shows the following warning:
The atDescription property of toggle button 27qvhmhw12i-toggle is empty, and is using a default value. To be sufficiently accessible, this property should describe the information this button reveals.in toggletip-js:133Setting it back to needs work
Comment #105
rkollerand i've tested the toggle with voiceover in edge. unfortunately keycstr the app i am using to show the keys i've pressed isnt showing any voiceover keycombinations (anything with VO = ctrl and option) . but if i wouldnt have the visual context i would consider the toggle tip experience in the aural inteface challenging. i've recorded a short video (voiceover.mp4)
And one additional detail. the toggle button border has #d3d4d9 against the white background, which leads to a color contrast of only 1.5:1... SC1.4.11, to being able to recognize the button, would require at least 3:1
Comment #106
finnsky commentedI found original bug with safari.
https://github.com/hotwired/turbo/issues/1245
If i just create node with button and popover it works. But if it is inside any form. it doesn't work in safari
Comment #107
geek-merlinHi @finnsky and all,
this is a great step forward, and this is why i cherry-picked this early for use in one project. (And i see my initial feedback was helpful, nice!).
Here is some more feedback:
- I like the '#help' approach, it makes altering existing elements possible (without additional wrapper).
- In the current approach, the trigger button is added with javascript, leveraging a library that does the positioning. This gave us some pain in our project.
- (1) First, js-added stuff is a PITA for theming (it's like select box improvements, where we switched to sumoselect, as it responds to CSS).
- (2) But the killer was, the javascript totally breaks when the element is not in the viewort initially, like with tabs and other disclosure elements.
- I doubt that (2) can be healed robustly, and tbh. in face of (1) we don't think putting effort in it is worth it.
- The result was, that we had to abandon this approach, and roll our own.
You can find our approach here and pick whatever you like: https://gitlab.com/geeks4change/modules/h4d_help
I suggest using this approach, because:
- It builds the markup server-side, so it works without JS (at least soon-ish, when the polyfills are obsoleted)
- It is stylable via CSS
- It works with tabs and other disclosure elements
- Apart from the popover polyfill, it uses anchor positioning for the toggle and help (native in chromium-based browsers, polyfilled in others) in its anchor-position variant. (The anchor-positioning Insert-Area variant is even nicer "soon" but not polyfilled yet.)
So needs-work for that imho.
Comment #108
finnsky commentedI think it is ok about button positioning with js.
But we need to clean different position calculations for button.
And move them to css:has()
Comment #109
geek-merlinComment #110
ressaThis would be a great feature! We could all use more time to work on Drupal, but if you have time at some point, perhaps it's most likely to get done, if you implement the changes you suggest in comment #107 @geek-merlin?
Comment #112
finnsky commentedComment #113
joachim commentedWhich element types support '#toggletip'? Should the CR say which ones, or how to identify which ones?
We're putting the trait into so many elements -- what's the reason for not just putting it in the base class?
'content' => '<p>My content inside the toggletip</p>',Can you put a render array inside this instead of HTML?
Comment #114
finnsky commented@joachim
@phenaproxima
Thanks for the review, it was really needed!
I simplified the code based on your recommendation.
Yes, it's possible! The current CR doesn't reflect the status of the code.
I want to first make sure everything is correct from a backend perspective and then prepare a CR.
Yes, that's a good idea!
Comment #115
markconroy commentedJust a note on #107, I really like the idea of using a component based on anchor positioning, since we are working with what is native in browsers, and a lot less for us to maintain with a custom implementation.
Added to that anchor-positioning has just become stable in Firefox (release 147 about 3 weeks ago):
It's definitely worth looking into that as a solution.
Comment #116
finnsky commentedWell, this MR already uses anchor-positioning to position buttons.
Comment #117
smustgrave commentedSorry to be that guy but with default_admin added assuming we will need to take that into account. Stable9 I'm not 100% sure as know some time we don't touch that (but don't remove just mentioned)
@markcontroy as the markup maintainer are you fine with this approach that we could maybe remove that tag?
Comment #118
markconroy commented@smustgrave - yep, looks good to me. Thanks for checking.
Comment #119
finnsky commentedComment #120
kentr commentedNot sure that this passes the Hoverable condition of SC 1.4.13 Content on Hover or Focus (Level AA).
The hover examples in the demo do not let me move the pointer from the trigger to the additional content.
From the above link:
Comment #121
kentr commentedAdditional note to my last comment:
Adrian Roselli called out a tooltip example on Web.dev for failing the Hoverable condition: https://github.com/GoogleChrome/web.dev/issues/8959
Comment #122
kentr commentedWe generally trust Adrian Roselli, and SC 1.4.13 is pretty clear.
Also from the link in #120:
So, I'm going out on a limb that it does need to pass the Hoverable condition and flagging for accessibility review to confirm.