Repository navigation
fix(popover): respect rtl for start and end alignment #31775
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
base: main
Are you sure you want to change the base?
Changes from all commits
23e0a05
178ef5e
31c325c
868ce54
a11959b
8abab91
fdd77ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
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. Can you update The |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -671,7 +671,14 @@ export const getPopoverPosition = ( | |
| * would allow the popover content | ||
| * to have the correct alignment. | ||
| */ | ||
| const alignedCoordinates = calculatePopoverAlign(align, side, referenceCoordinates, contentWidth, contentHeight); | ||
| const alignedCoordinates = calculatePopoverAlignedCoordinates( | ||
| align, | ||
| side, | ||
| referenceCoordinates, | ||
| contentWidth, | ||
| contentHeight, | ||
| isRTL | ||
| ); | ||
|
|
||
| const top = coordinates.top + alignedCoordinates.top; | ||
| const left = coordinates.left + alignedCoordinates.left; | ||
|
|
@@ -702,9 +709,9 @@ export const getPopoverPosition = ( | |
| const calculatePopoverOrigin = (side: PositionSide, align: PositionAlign, isRTL: boolean) => { | ||
| switch (side) { | ||
| case 'top': | ||
| return { originX: getOriginXAlignment(align), originY: 'bottom' }; | ||
| return { originX: getOriginXAlignment(align, isRTL), originY: 'bottom' }; | ||
| case 'bottom': | ||
| return { originX: getOriginXAlignment(align), originY: 'top' }; | ||
| return { originX: getOriginXAlignment(align, isRTL), originY: 'top' }; | ||
| case 'left': | ||
| return { originX: 'right', originY: getOriginYAlignment(align) }; | ||
| case 'right': | ||
|
|
@@ -716,14 +723,14 @@ const calculatePopoverOrigin = (side: PositionSide, align: PositionAlign, isRTL: | |
| } | ||
| }; | ||
|
|
||
| const getOriginXAlignment = (align: PositionAlign) => { | ||
| const getOriginXAlignment = (align: PositionAlign, isRTL: boolean) => { | ||
| switch (align) { | ||
| case 'start': | ||
| return 'left'; | ||
| return isRTL ? 'right' : 'left'; | ||
| case 'center': | ||
| return 'center'; | ||
| case 'end': | ||
| return 'right'; | ||
| return isRTL ? 'left' : 'right'; | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -839,89 +846,52 @@ const calculatePopoverSide = ( | |
| * correct alignment regardless while taking | ||
| * into account the side the popover is on. | ||
| */ | ||
| const calculatePopoverAlign = ( | ||
| const calculatePopoverAlignedCoordinates = ( | ||
| align: PositionAlign, | ||
| side: PositionSide, | ||
| triggerBoundingBox: ReferenceCoordinates, | ||
| contentWidth: number, | ||
| contentHeight: number | ||
| ) => { | ||
| switch (align) { | ||
| case 'center': | ||
| return calculatePopoverCenterAlign(side, triggerBoundingBox, contentWidth, contentHeight); | ||
| case 'end': | ||
| return calculatePopoverEndAlign(side, triggerBoundingBox, contentWidth, contentHeight); | ||
| case 'start': | ||
| default: | ||
| return { top: 0, left: 0 }; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Calculate the end alignment for | ||
| * the popover. If side is on the x-axis | ||
| * then the align values refer to the top | ||
| * and bottom margins of the content. | ||
| * If side is on the y-axis then the | ||
| * align values refer to the left and right | ||
| * margins of the content. | ||
| */ | ||
| const calculatePopoverEndAlign = ( | ||
| side: PositionSide, | ||
| triggerBoundingBox: ReferenceCoordinates, | ||
| contentWidth: number, | ||
| contentHeight: number | ||
| ) => { | ||
| switch (side) { | ||
| case 'start': | ||
| case 'end': | ||
| case 'left': | ||
| case 'right': | ||
| return { | ||
| top: -(contentHeight - triggerBoundingBox.height), | ||
| left: 0, | ||
| }; | ||
| case 'top': | ||
| case 'bottom': | ||
| default: | ||
| return { | ||
| top: 0, | ||
| left: -(contentWidth - triggerBoundingBox.width), | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Calculate the center alignment for | ||
| * the popover. If side is on the x-axis | ||
| * then the align values refer to the top | ||
| * and bottom margins of the content. | ||
| * If side is on the y-axis then the | ||
| * align values refer to the left and right | ||
| * margins of the content. | ||
| */ | ||
| const calculatePopoverCenterAlign = ( | ||
| side: PositionSide, | ||
| triggerBoundingBox: ReferenceCoordinates, | ||
| contentWidth: number, | ||
| contentHeight: number | ||
| contentHeight: number, | ||
| isRTL: boolean | ||
| ) => { | ||
| switch (side) { | ||
| case 'start': | ||
| case 'end': | ||
| case 'left': | ||
| case 'right': | ||
| return { | ||
| top: -(contentHeight / 2 - triggerBoundingBox.height / 2), | ||
| left: 0, | ||
| }; | ||
| case 'right': { | ||
| /** | ||
| * If side is on the x-axis | ||
| * then the align values refer to the top | ||
| * and bottom margins of the content. | ||
| */ | ||
| switch (align) { | ||
| case 'end': | ||
| return { top: -(contentHeight - triggerBoundingBox.height), left: 0 }; | ||
| case 'center': | ||
| return { top: -(contentHeight / 2 - triggerBoundingBox.height / 2), left: 0 }; | ||
| case 'start': | ||
| default: | ||
| return { top: 0, left: 0 }; | ||
| } | ||
| } | ||
| case 'top': | ||
| case 'bottom': | ||
| default: | ||
| return { | ||
| top: 0, | ||
| left: -(contentWidth / 2 - triggerBoundingBox.width / 2), | ||
| }; | ||
| default: { | ||
| /** | ||
| * If side is on the y-axis then the | ||
| * align values refer to the left and right | ||
| * margins of the content. | ||
| */ | ||
| switch (align) { | ||
| case 'end': | ||
| return { top: 0, left: isRTL ? 0 : -(contentWidth - triggerBoundingBox.width) }; | ||
| case 'center': | ||
| return { top: 0, left: -(contentWidth / 2 - triggerBoundingBox.width / 2) }; | ||
| case 'start': | ||
| default: | ||
| return { top: 0, left: isRTL ? -(contentWidth - triggerBoundingBox.width) : 0 }; | ||
| } | ||
|
Comment on lines
+867
to
+893
Member
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. Neither inner The old code had Can we add a |
||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.