Administration: Fix tooltip/toggletip nesting inside paragraphs#12592
Administration: Fix tooltip/toggletip nesting inside paragraphs#12592itzmekhokan wants to merge 4 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
`wp_get_tooltip_helper()` wrapped its output in a `div` and used a `dialog` element for toggletips. Both are flow content, so placing the markup inside a `p` (as with the "Remember Me" field on the login form) made the parser close the paragraph early and emit a stray empty `p`, adding an extra layout gap. Build the markup from phrasing content only: use a `span` wrapper for both types, and a `span` with `role="dialog"` (plus `aria-label`, `tabindex`, and `autofocus`) in place of the `dialog` element. This keeps the markup valid in a phrasing context while preserving the accessible name and focus handling. See #65660.
…helper. The `attributes` default in `wp_get_tooltip_helper()` was never read within the function, was not documented in the parameter list, and is not passed by any caller. Remove it as dead code. See #65660.
joedolson
left a comment
There was a problem hiding this comment.
I made a minor improvements to one of the supporting comments, but otherwise I think this is good to go.
Using sectioning elements (`div` and `dialog`) inside the generated markup meant that the function couldn't be used inside a `p` element, because sectioning elements aren't valid HTML inside `p`. To make the function more useful as a general utility, use only `span` and `button` elements to build the content, avoiding browser parser breaking behavior. Developed in #12592 Props joedolson, khokansardar. Fixes #65660. git-svn-id: https://develop.svn.wordpress.org/trunk@62800 602fd350-edb4-49c9-b593-d223f7449a82
Using sectioning elements (`div` and `dialog`) inside the generated markup meant that the function couldn't be used inside a `p` element, because sectioning elements aren't valid HTML inside `p`. To make the function more useful as a general utility, use only `span` and `button` elements to build the content, avoiding browser parser breaking behavior. Developed in WordPress/wordpress-develop#12592 Props joedolson, khokansardar. Fixes #65660. Built from https://develop.svn.wordpress.org/trunk@62800 git-svn-id: http://core.svn.wordpress.org/trunk@62080 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Problem
wp_get_tooltip_helper()(added in 7.1.0, poweringwp_get_tooltip()andwp_get_toggletip()) wraps its output in a<div>, and for toggletips uses a<dialog>element. Both are flow content, not phrasing content.When that markup is placed inside a
<p>— as it is for the "Remember Me" field on the login form (wp_get_toggletip()inside<p class="forgetmenot">) — the HTML parser applies its "close a p element" rule on the<div>/<dialog>start tag. This:<form>, and<p></p>behind (from the literal</p>in the source), whose default margins produce the extra gap reported under the Remember Me row.Before the toggletip feature landed the wrapper was a
<span>(valid phrasing content), so this is a 7.1-only regression.Reproduction
Load
wp-login.php. Inspect the DOM aroundp.forgetmenot: it contains only the checkbox + label, the.wp-tooltipelement is a direct child of<form>, and an empty<p></p>sits between it andp.submit, adding a visible gap before the Log In button.Fix
Build the markup from phrasing content only so it is valid wherever it's used, including inside a paragraph:
<div>wrapper →<span>for both tooltips and toggletips (the CSS is alreadydisplay: inline-flex).<dialog popover="auto" autofocus>→<span popover="auto" role="dialog" aria-label="…" tabindex="-1" autofocus>. The Popover API works on any element;role="dialog"+tabindex="-1"+autofocusreproduce the native dialog's accessible name and "focus moves into the popover on open" behavior. Escape / light-dismiss / the close button are all driven bypopover="auto"and are unchanged.Also updates the
wp-tooltip.jsJSDoc type (HTMLDivElement→HTMLSpanElement) to match the new wrapper.Testing
Verified on the local Docker environment (
wp-login.php):p.forgetmenotnow contains the toggletip; zero empty paragraphs; Remember Me and Log In align on one row.<dialog autofocus>.<dialog popover="auto">(differential check).Automated:
Tests_General_wpGetTooltip→ OK (9 tests, 27 assertions), including new@ticket 65660regression tests asserting the output contains no<div>/<dialog>and that the toggletip bubble usesrole="dialog"withtabindex="-1" autofocus.phpcs.xml.dist) → 0 errors on the changed files.Notes for reviewers
attributesdefault fromwp_get_tooltip_helper()(never read, undocumented, no caller passes it). It's isolated so it can be dropped independently if you'd prefer to keep this PR strictly scoped to the layout bug.Trac ticket: https://core.trac.wordpress.org/ticket/65660
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Generate test cases and all implementation and tests were reviewed and edited by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.