fix(tabs): move the indicator when the text direction changes - #223
Merged
Merged
Conversation
The sliding indicator was positioned from the active trigger's offset, and only recomputed when the value, orientation or items changed, or when the list resized. Flipping the page from ltr to rtl mirrors the triggers without any of those, so the indicator kept its old offset and sat under the wrong tab, with the active label rendered in the on indicator color over the plain background. The indicator is now recomputed when a dir attribute changes anywhere in the document. A direction set only through CSS is still not detected. Closes #216
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Tabspositions its sliding indicator from the active trigger's offset, and recomputed it only whenvalue,orientationoritemschanged, or when the list resized. Flipping the text direction at runtime, for example a language switch that turns the page fromltrtortl, mirrors the triggers without any of those, so the indicator kept its old offset and ended up under a different tab. The active label still rendered in the on-indicator color over the plain background, which made it look unreadable.The indicator is now recomputed whenever a
dirattribute changes in the document.Closes #216
Type of change
Changes
Tabsobservesdirattribute changes (attributeFilter: ['dir'],subtree: true, from the document element) and reuses the existing rAF-debounced update. Watching the whole document rather than the current[dir]ancestors also covers adiradded to an ancestor later.querySelector<HTMLElement>instead of a cast, and one cleanup instead of two.rtland back keeps the indicator'sleftandwidthon the active trigger. It fails ondev(indicator at 4px while the trigger moved to 852px).CHANGELOG.mdentry under[Unreleased].Checklist
Closes #…)pnpm checkpasses (0 errors, 0 warnings)pnpm lintpassespnpm testpassesCHANGELOG.mdunder[Unreleased]*.types.ts, Material 3 design tokens)Screenshots / notes
Verified in Chromium against
dev, with the first tab active and a three-tab list:dirtoggled on a wrapper element (the snippet from the issue): the active trigger moves from 4px to 459px. Ondevthe indicator stays at 4px; with the fix it follows to 459px and back.dirtoggled on thehtmlelement, as a language switch would: same result.Known limit: a direction set only through CSS, for example a class that applies
direction: rtl, is not detected, since there is no attribute change to observe. The issue notes the same limit.NavigationMenumeasures its highlight bar the same way, but it is not affected: its root carriesdir="ltr", so a wrapper flipping tortldoes not mirror it.Only verified in Chromium.