Skip to content

fix: point the fold chevron down in RTL books - #3190

Merged
GuillaumeGomez merged 1 commit into
rust-lang:masterfrom
VXNCXNX:fix/rtl-fold-chevron
Aug 18, 2026
Merged

fix: point the fold chevron down in RTL books#3190
GuillaumeGomez merged 1 commit into
rust-lang:masterfrom
VXNCXNX:fix/rtl-fold-chevron

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #2894.

Cause

The expanded chevron is rotated 90°:

.chapter li.expanded > span > .chapter-fold-toggle div { transform: rotate(90deg); }

In an RTL document the browser has already bidi-mirrored the glyph, so it points left before any rotation. Rotating that by +90° points it up, which is the "^" in your report.

Collapsed is fine as-is — the mirroring alone is exactly what's wanted there.

Fix

One rule, mirroring the existing one:

[dir=rtl] .chapter li.expanded > span > .chapter-fold-toggle div { transform: rotate(-90deg); }

Computed transform on an expanded toggle in an RTL book goes from matrix(0, 1, -1, 0, 0, 0) to matrix(0, -1, 1, 0, 0, 0). LTR is untouched — I captured every toggle's computed transform with and without the change and diffed: byte-identical.

Checked rather than assumed

  • Specificity: the new rule is (0,3,4) against the LTR rule's (0,2,4), and it also comes later in the file, so it wins on both counts.
  • The JS-built header toggles are covered too. toc.js.hbs appends them into the same span.chapter-link-wrapper inside .chapter, so the selector matches. I built a book with sidebar_header_nav and h3/h4/h5 nesting and confirmed the computed transform on a header toggle.
  • The bidi-mirroring claim was verified by pixels, not by reasoning about it: I screenshotted the collapsed glyph at 4× DPR and computed its ink centroid — 0.508 in LTR (pointing right) versus 0.471 in RTL (pointing left), with identical ink mass. Held for both a Latin title and an Arabic title inside the RTL document, so the surrounding-context worry didn't materialise.

Test

tests/gui/rtl-fold.goml with a small RTL fixture book. GUI tests run here (npm install + npx puppeteer browsers install chrome):

cargo test --test gui   24 succeeded, 0 failed
npm run lint            clean

Load-bearing — stashing only the CSS change:

[ERROR] line 11: expected `matrix(0, -1, 1, 0, 0, 0)`, found `matrix(0, 1, -1, 0, 0, 0)`
<= doc-ui tests done: 0 succeeded, 1 failed

One gap worth naming: the fixture has no h3+ headings, so the test doesn't cover the JS header toggles, even though the fix applies to them. Happy to extend it if you'd like that pinned too.

No CHANGELOG entry, since CONTRIBUTING says those are generated at release time.

the expanded chevron is rotated 90 degrees, which points it up once the browser has already mirrored the glyph for a right-to-left document. Rotate the other way there. Fixes rust-lang#2894.
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Aug 14, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

Please share screenshots of the bug and with your fix applied.

@GuillaumeGomez GuillaumeGomez added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Aug 17, 2026
@VXNCXNX

VXNCXNX commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Here they are, from the tests/gui/books/rtl-fold book in this PR. Same viewport, same zoom, same crop, so the two in each pair line up.

Expanded (the bug). The chapter is open, so the chevron should point down:

before after
before, expanded after, expanded

Computed transform on the toggle goes from matrix(0, 1, -1, 0, 0, 0) to matrix(0, -1, 1, 0, 0, 0).

Collapsed, to show this state is untouched:

before after
before, collapsed after, collapsed

Those two PNGs are byte-identical, and the computed transform is none on both.

@VXNCXNX

VXNCXNX commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Here you go. Same RTL book built twice, the two builds differ by exactly the 6 CSS lines in this PR (verified with diff on the generated chrome-*.css).

Before, the chevron points up:

before

After, it points down:

after

The computed transform is rotate(90deg) before and rotate(-90deg) after. In RTL the glyph is already bidi-mirrored to point left, so the existing 90deg rotation lands it pointing up instead of down.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Thanks!

@GuillaumeGomez
GuillaumeGomez added this pull request to the merge queue Aug 18, 2026
Merged via the queue into rust-lang:master with commit 03018be Aug 18, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Folding interacts poorly with RTL

3 participants