Skip to content

Eliminate layout shift in menu toggle arrow with CSS-only solution #1935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025

Conversation

ShubhamOulkar
Copy link
Member

@ShubhamOulkar ShubhamOulkar commented May 31, 2025

Problem

Previously, the menu toggle arrow in the Table of Contents was implemented by updating the button’s inner HTML with different Unicode arrow entities (e.g., ► for closed and ▼ for open) via JavaScript. This approach caused a layout shift when toggling the menu, because the two Unicode arrow characters have different widths and font rendering. As a result, the button size and surrounding layout would visibly jump when the menu was opened or closed, negatively impacting user experience and visual stability.

Solution

This PR refactors the arrow indicator to use a CSS-only solution. The arrow is now rendered using a CSS ::after pseudo-element on the toggle button, with its direction controlled by toggling a class and applying a transform: rotate() property. This ensures the arrow always occupies the same space, eliminating layout shifts and providing a smoother, more consistent UI. The button’s HTML remains static, and all visual changes are handled via CSS transitions.

Mobile screens specific issue

before after
Edited_20250531_175842 Edited_20250531_183603

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@ShubhamOulkar ShubhamOulkar requested review from a team as code owners May 31, 2025 12:58
Copy link

netlify bot commented May 31, 2025

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit b895b37
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/683afcfac7e8a000089730a0
😎 Deploy Preview https://deploy-preview-1935--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member

@bjohansebas bjohansebas left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member Author

@ShubhamOulkar ShubhamOulkar left a comment

Choose a reason for hiding this comment

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

lgtm

@bjohansebas bjohansebas merged commit 30c053b into expressjs:gh-pages Jun 6, 2025
9 checks passed
@ShubhamOulkar ShubhamOulkar deleted the refactor branch June 6, 2025 03:42
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.

None yet

2 participants