-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Tabs: Fix indicator misalignment when the browser width changes in RTL languages #64965
Conversation
@@ -24,7 +24,7 @@ export const TabListWrapper = styled.div` | |||
|
|||
@media not ( prefers-reduced-motion: reduce ) { | |||
&.is-animation-enabled::after { | |||
transition-property: left, top, width, height; | |||
transition-property: inset-inline-start, top, width, height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is necessary so that the indicator animations continue to work as before.
/** | ||
* The distance from the right edge of the offset parent to the right edge of | ||
* the element. | ||
*/ | ||
right: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, the right
value is calculated in the getElementOffsetRect()
function, but if the right
value is inappropriate for the getElementOffsetRect()
function itself, we can also calculate the right
value directly in the Tabs
component.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Thank you, @t-hamano ! @DaniGuardiola is already working on an iteration for this animation in #64926, so I'm not sure if it makes sense to keep this PR open. At the same time, some of the fixes that you're proposing may be useful for Dani, since his new implementation still doesn't support RTL writing direction. |
Thank you @t-hamano! Closing as per #64926 (comment), but bookmarking as the work will be helpful to me in the near future :) |
Part of #64963
What?
This PR fixes the tab indicator misalignment when the browser width changes in RTL languages.
Why?
The horizontal position of the indicator is determined by the CSS
left
. However, in RTL languages, the tab buttons are located on the right side.When we change the browser width, the left offset position of the button relative to the parent element will change, but the indicator position is fixed by the CSS
left
, so there is a misalignment between the button and the indicator.How?
I think in RTL languages we should determine the offset position via
right
instead ofleft
.First, to calculate the right offset position, I used the following logic:
offsetLeft
from this value. This is the basic right value for the indicator.1
to prevent unintended overflow. If the right value is negative, convert it to0
.Next, apply the calculated value as CSS.
We can also use the CSS
right
instead ofleft
in RTL languages. However, in this PR, I replaced the CSSleft
with inset-inline-start. Unlike the CSSleft
, this CSS applies a physical offset according to the document direction. This CSS is also supported by all browsers.Testing Instructions
Storybook
Before
storybook-before.mp4
After
storybook-after.mp4
Site Editor
The easiest way to confirm is to look at the Font Library modal.
Before
font-library-modal-before.mp4
After
font-library-modal-after.mp4