Eliminate layout shift in menu toggle arrow with CSS-only solution #1935
+25
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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