fix: keep Font Awesome icons centered in a menu with a title - #803
Conversation
The documented recipe for giving a menu a title is a :before pseudo element on the menu plus a top margin on its first child, to make room for that title. A Font Awesome icon is rendered as an <i> element inside the menu item, so it is the first child of its own <li>. The descendant :first-child selector in that recipe therefore matched every icon too and pushed them all down by the title's height, leaving the icons hanging below their label. The same applied to the <label> of an input item. The <i>/<svg> element is created and positioned by this plugin, so its box is now pinned down completely instead of relying on whatever the icon library or the surrounding page leaves it at. Resetting margin keeps page level rules from displacing it, and height/line-height plus a negative top margin against top: 50% center the icon for any item padding or font size, matching how the built-in icon font is centered. Centering via margin rather than transform leaves Font Awesome's own fa-rotate-* and fa-flip-* helpers working. The title recipe in the menu-title demo is updated to use a child combinator, since the top margin is only ever meant for the first menu item, and a new demo combines a menu title with Font Awesome icons. Closes #738
The fixture pages load the plugin's CSS and JS from dist/, which is only rebuilt at release time and is therefore usually behind src/ on a pull request. The acceptance job copied that stale bundle in, so any change made in src/sass or src/jquery.contextMenu.js was invisible to the Playwright suite, and a regression test written against it failed on CI while passing locally.
|
Heads up on the CI failure on the first push: it was not the fix, it was the fixture pipeline. The acceptance job copies the committed Added Happy to split that into its own PR if you would rather keep this one to the fix. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f43e935c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // The title recipe as it was documented before #738: a descendant | ||
| // selector rather than a child combinator. Plenty of pages in the wild | ||
| // still use it, so the plugin's own icon styling has to win. | ||
| await page.addStyleTag({ content: '.menu-title-fa :first-child { margin-top: 20px; }' }); |
There was a problem hiding this comment.
Compile the changed Sass before exercising this fixture
In every acceptance job, npm run test:fixtures generates pages whose stylesheet link points to the checked-in dist/jquery.contextMenu.css, and the workflow proceeds directly to Playwright without running npm run build. Because this commit changes only the Sass source, the loaded CSS still has top: 0.3em and no margin reset; therefore this injected descendant rule gives each icon a 20px top margin and the subsequent centering assertion fails across the acceptance matrix. Update the tracked distribution CSS or make the fixture/workflow compile and load the changed stylesheet.
Useful? React with 👍 / 👎.
|
Thanks, that P1 is correct and it is the same thing the first CI run tripped on. It was already addressed in de850fc, pushed before the review landed (Codex reviewed 4f43e93). The acceptance job now runs Nothing else from the review to address. |
|
👍 |
Closes #738
Problem
The documented recipe for giving a menu a title (see the menu title demo) is a
:beforepseudo element on the menu plus a top margin on its first child, to make room for that title:A Font Awesome icon is rendered as an
<i>element inside the menu item, so it is the first child of its own<li>. That descendant:first-childselector matched every icon as well and pushed them all down by the title's height, leaving the icons hanging below their label. The<label>of an input item hit the same thing.Measured on master, with a title the icon's center sat 20.6px below its item's center. Without a title it was 0.6px.
Fix
The
<i>/<svg>element is created and positioned by this plugin, so its box is now pinned down completely instead of relying on whatever the icon library or the surrounding page leaves it at:margin: -0.5em 0 0resets the margin, so page level rules such as the title recipe can no longer displace the icon. The plugin's selector is more specific than the recipe's, so pages already using the old descendant selector are fixed without touching their CSS.height: 1em+line-height: 1+top: 50%center the icon in its item for any item padding or font size, replacing the fixedtop: 0.3emthat only happened to be near center at the default sizes. This matches how the built-in icon font is already centered.marginrather thantransformleaves Font Awesome's ownfa-rotate-*andfa-flip-*helpers working.Documentation wise, the recipe in the menu title demo now uses a child combinator (
> :first-child), since that top margin is only ever meant for the first menu item, with a note explaining why.Tests
New Playwright spec
test/specs/menu-title-icon-alignment.jsplus a new demo fixturedocumentation/demo/menu-title-fontawesome.mdcombining a menu title with Font Awesome icons. It asserts the icon's vertical center is within 1.5px of its item's vertical center for::first-childrule injected, so the plugin CSS itself stays robust for pages in the wildThe three Font Awesome cases fail on master and pass with this change. The built-in icon cases pass either way and are there so the Font Awesome fix cannot be made at their expense.
dist/is intentionally not committed.