Repository navigation
fix(popover): respect rtl for start and end alignment - #31775
OS-jacobbell wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
brandyscarney
left a comment
There was a problem hiding this comment.
The fix looks good! Just a few small requests!
| switch (align) { | ||
| case 'start': | ||
| return { top: 0, left: 0 }; | ||
| case 'end': | ||
| return { top: -(contentHeight - triggerBoundingBox.height), left: 0 }; | ||
| case 'center': | ||
| return { top: -(contentHeight / 2 - triggerBoundingBox.height / 2), 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 'start': | ||
| return { top: 0, left: isRTL ? -(contentWidth - triggerBoundingBox.width) : 0 }; | ||
| case 'end': | ||
| return { top: 0, left: isRTL ? 0 : -(contentWidth - triggerBoundingBox.width) }; | ||
| case 'center': | ||
| return { top: 0, left: -(contentWidth / 2 - triggerBoundingBox.width / 2) }; | ||
| } |
There was a problem hiding this comment.
Neither inner switch (align) has a default case. If align is anything but start/center/end, the x-axis block falls through to the y-axis block, which also returns nothing, so the function returns undefined. Then alignedCoordinates.top throws in getPopoverPosition and the popover never opens.
The old code had case 'start': default: returning { top: 0, left: 0 }. That covered a bad alignment attribute from plain HTML, and alignment set back to undefined after load (the prop is mutable, and the mode-based default is only applied in componentWillLoad).
Can we add a default to both inner switches so they fall back to start like before? An explicit return at the end of the x-axis block would also stop it falling into the y-axis case by accident.
There was a problem hiding this comment.
Can you update popover.tsx line 219-222:
The side JSDoc right above says which values are RTL-aware, but alignment doesn't. Now that start/end flip in RTL when side is top or bottom, should we say that here too?
There was a problem hiding this comment.
This changes where every md popover appears in RTL.
It's a bug fix, so it's not breaking, but could you mention in "What is the new behavior?" that default-alignment md popovers in RTL now open from the right? That way RTL users aren't surprised.
| const popoverBox = (await page.locator(`.${id}-popover`).locator('.popover-content').boundingBox())!; | ||
|
|
||
| return { | ||
| trigger: { left: buttonBox.x, right: buttonBox.x + buttonBox.width, center: buttonBox.x + buttonBox.width / 2 }, |
There was a problem hiding this comment.
center is computed for both trigger and popover but no test reads it. Can we drop it, or add a center alignment test that uses it?
Issue number: resolves internal
What is the current behavior?
When popover side is
toporbottom,startandendalignment does not respect RTL.What is the new behavior?
toporbottom,startalignment appears on the right in RTL mode, andendalignment appears on the left.Does this introduce a breaking change?
Other information