Skip to content

Administration: Fix tooltip/toggletip nesting inside paragraphs#12592

Closed
itzmekhokan wants to merge 4 commits into
WordPress:trunkfrom
itzmekhokan:fix/65660
Closed

Administration: Fix tooltip/toggletip nesting inside paragraphs#12592
itzmekhokan wants to merge 4 commits into
WordPress:trunkfrom
itzmekhokan:fix/65660

Conversation

@itzmekhokan

Copy link
Copy Markdown

Problem

wp_get_tooltip_helper() (added in 7.1.0, powering wp_get_tooltip() and wp_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:

  1. Auto-closes the paragraph, moving the tooltip out to become a sibling of the <form>, and
  2. Leaves a stray empty <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 around p.forgetmenot: it contains only the checkbox + label, the .wp-tooltip element is a direct child of <form>, and an empty <p></p> sits between it and p.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 already display: inline-flex).
  • Toggletip <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" + autofocus reproduce the native dialog's accessible name and "focus moves into the popover on open" behavior. Escape / light-dismiss / the close button are all driven by popover="auto" and are unchanged.

Also updates the wp-tooltip.js JSDoc type (HTMLDivElementHTMLSpanElement) to match the new wrapper.

Testing

Verified on the local Docker environment (wp-login.php):

  • p.forgetmenot now contains the toggletip; zero empty paragraphs; Remember Me and Log In align on one row.
  • Toggletip opens, is anchored above its toggle with the arrow, shows the close button, and dismisses correctly.
  • On open, focus moves onto the bubble — identical to the previous native <dialog autofocus>.
  • Escape/light-dismiss behavior confirmed equivalent to a native <dialog popover="auto"> (differential check).

Automated:

  • Tests_General_wpGetTooltipOK (9 tests, 27 assertions), including new @ticket 65660 regression tests asserting the output contains no <div>/<dialog> and that the toggletip bubble uses role="dialog" with tabindex="-1" autofocus.
  • PHPCS (phpcs.xml.dist) → 0 errors on the changed files.

Notes for reviewers

  • The second commit removes an unused attributes default from wp_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.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props khokansardar, joedolson.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

`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 joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I made a minor improvements to one of the supporting comments, but otherwise I think this is good to go.

pento pushed a commit that referenced this pull request Jul 19, 2026
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
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62800
GitHub commit: 9ace411

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 19, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jul 19, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants