-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,11 @@ export type ElementOffsetRect = { | |
* the element. | ||
*/ | ||
left: number; | ||
/** | ||
* The distance from the right edge of the offset parent to the right edge of | ||
* the element. | ||
*/ | ||
right: number; | ||
Comment on lines
+128
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this PR, the |
||
/** | ||
* The distance from the top edge of the offset parent to the top edge of | ||
* the element. | ||
|
@@ -145,6 +150,7 @@ export type ElementOffsetRect = { | |
*/ | ||
export const NULL_ELEMENT_OFFSET_RECT = { | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
width: 0, | ||
height: 0, | ||
|
@@ -163,17 +169,31 @@ export const NULL_ELEMENT_OFFSET_RECT = { | |
export function getElementOffsetRect( | ||
element: HTMLElement | ||
): ElementOffsetRect { | ||
// This is a workaround to obtain these values with a sub-pixel precision, | ||
// since `offsetWidth` and `offsetHeight` are rounded to the nearest pixel. | ||
const width = parseFloat( getComputedStyle( element ).width ); | ||
const height = parseFloat( getComputedStyle( element ).height ); | ||
const parentElementWidth = element?.parentElement | ||
? parseFloat( getComputedStyle( element.parentElement ).width ) | ||
: 0; | ||
|
||
// The adjustments mentioned in the documentation above are necessary | ||
// because `offsetLeft` and `offsetTop` are rounded to the nearest pixel, | ||
// which can result in a position mismatch that causes unwanted overflow. | ||
// For context, see: https://github.com/WordPress/gutenberg/pull/61979 | ||
const left = Math.max( element.offsetLeft - 1, 0 ); | ||
const top = Math.max( element.offsetTop - 1, 0 ); | ||
const right = Math.max( | ||
Math.round( parentElementWidth - width ) - element.offsetLeft - 1, | ||
0 | ||
); | ||
|
||
return { | ||
// The adjustments mentioned in the documentation above are necessary | ||
// because `offsetLeft` and `offsetTop` are rounded to the nearest pixel, | ||
// which can result in a position mismatch that causes unwanted overflow. | ||
// For context, see: https://github.com/WordPress/gutenberg/pull/61979 | ||
left: Math.max( element.offsetLeft - 1, 0 ), | ||
top: Math.max( element.offsetTop - 1, 0 ), | ||
// This is a workaround to obtain these values with a sub-pixel precision, | ||
// since `offsetWidth` and `offsetHeight` are rounded to the nearest pixel. | ||
width: parseFloat( getComputedStyle( element ).width ), | ||
height: parseFloat( getComputedStyle( element ).height ), | ||
left, | ||
top, | ||
right, | ||
width, | ||
height, | ||
}; | ||
} | ||
|
||
|
Oops, something went wrong.
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.
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.