Skip to content

fix: popover alignment for rtl / useLogicalProperties#3326

Open
dreamwasp wants to merge 2 commits intocass-gmt-1601from
cass-gmt-1601-tooltip-bug
Open

fix: popover alignment for rtl / useLogicalProperties#3326
dreamwasp wants to merge 2 commits intocass-gmt-1601from
cass-gmt-1601-tooltip-bug

Conversation

@dreamwasp
Copy link
Copy Markdown
Contributor

@dreamwasp dreamwasp commented Apr 15, 2026

Overview

fixes Popover alignment when dir is rtl.

PR Checklist

  • Related to designs:
  • Related to JIRA ticket: GMT-1601
  • Version plan added/updated (or not needed)
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

Don't make me tap the sign.

  1. Go to Popover story
  2. Turn on useLogicalProperties and make dir rtl
  3. See the Popover is now properly aligned

PR Links and Envs

Repository PR Link
Monolith Monolith PR
Mono Mono PR

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 15, 2026

View your CI Pipeline Execution ↗ for commit f8e549e


☁️ Nx Cloud last updated this comment at 2026-04-16 20:35:27 UTC

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (cass-gmt-1601@6efbb0b). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ages/gamut/src/Tip/shared/popoverAlignmentUtils.ts 96.42% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##             cass-gmt-1601    #3326   +/-   ##
================================================
  Coverage                 ?   89.23%           
================================================
  Files                    ?      251           
  Lines                    ?     4711           
  Branches                 ?     1597           
================================================
  Hits                     ?     4204           
  Misses                   ?      499           
  Partials                 ?        8           
Flag Coverage Δ
pull-request 89.23% <97.50%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dreamwasp dreamwasp changed the title fix: popover, need to test invertAxis fix: popover Apr 16, 2026
@codecademydev
Copy link
Copy Markdown
Collaborator

📬 Published Alpha Packages:

Package Version npm Diff
@codecademy/gamut 68.2.3-alpha.d44ad5.0 npm diff
@codecademy/gamut-icons 9.57.3-alpha.d44ad5.0 npm diff
@codecademy/gamut-illustrations 0.58.10-alpha.d44ad5.0 npm diff
@codecademy/gamut-kit 0.6.593-alpha.d44ad5.0 npm diff
@codecademy/gamut-patterns 0.10.29-alpha.d44ad5.0 npm diff
@codecademy/gamut-styles 17.13.2-alpha.d44ad5.0 npm diff
@codecademy/gamut-tests 5.3.4-alpha.d44ad5.0 npm diff
@codecademy/variance 0.26.2-alpha.d44ad5.0 npm diff
eslint-plugin-gamut 2.4.4-alpha.d44ad5.0 npm diff

@github-actions
Copy link
Copy Markdown
Contributor

@dreamwasp dreamwasp marked this pull request as ready for review April 16, 2026 21:00
@dreamwasp dreamwasp requested a review from a team as a code owner April 16, 2026 21:00
@dreamwasp dreamwasp changed the title fix: popover fix: popover alignment for rtl / useLogicalProperties Apr 16, 2026
@dreamwasp dreamwasp requested a review from LinKCoding April 16, 2026 21:00
Copy link
Copy Markdown
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hovering on approving, but had some questions

The biggest one that gives me pause is how the horizontal alignment example's beaks seem to be inverted when the FlexBox has a set dir.

- **`align="center"`:** not mirrored as left/right; it stays centered on the anchor for that `position`.
- **`beak`:** for `above` / `below`, a **corner** beak follows **`align`**. Use **`beak="center"`** for a triangle centered on that edge.

To preview in Storybook, wrap the trigger (or an ancestor) with **`dir="rtl"`**, or rely on your app’s locale if it sets `dir` on `document.documentElement`. See <LinkTo id="Meta/Logical and physical CSS properties">Logical and physical CSS properties</LinkTo> for `useElementDir`, the imperative `elementDir` helper, and logical vs physical CSS in Gamut. Lower-level positioning without `Popover` is documented on <LinkTo id="Atoms/PopoverContainer">PopoverContainer</LinkTo>.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the wrapping of the trigger necessary?
Shouldn't the LTR/RTL button do this? i.e. change the document's dir?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah this is wrong, i'll edit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in: #3330

Comment on lines +149 to +150
paddingInlineStart: containerOffsetVertical,
insetInlineStart: '100%',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this and the other alignment styles be conditionally set based on useLogicalProperties?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will change!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coming back to this after spending more time on it, and it seems like there is a non-trivial amount of work needed to perform this swapping for physical properties that render correctly for RTL (and LTR)

we can't just use a hook in this, and since this function is being used to generate variants (and not a component), I think the most gamut way to implement this is to create a function that gets the value of useLogicalProperties that then returns the correct CSS for popover alignment, and then some logic for the beak alignment.

But in the process of doing this, I don't know if that's worth the effort (that might need to be refactored later anyway).

I'm going to rescind my comment before, and say that this works well and renders as intended. (After the horizontalBeakRtlInline is added back)


export const InteractiveElement: Story = {
render: () => (
<FlexBox center m={32}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding some spacing or justify-* here would be good since all the buttons are smooshed together

Image

placement="floating"
>
<FillButton aria-describedby="floating-ex-lc" icon={StudyBookIcon}>
lert center
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lert => left

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in: #3330


export const HorizontalAlignmentsRtl: Story = {
render: () => (
<FlexBox dir="rtl" justifyContent="space-around" m={24} width="95%">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

It's weird b.c. this happens only when the dir is added the FlexBox. And happens regardless of physical/logical or LTR/RTL button config in the toolbar.
Maybe there's some confusion about what dir to actually use? i.e. the parent or the document's?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: was this just for testing purposes? i.e. cleaned up after? or should it also on the mdx?

I think it's a good example for showcasing floating tooltips :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah weird, i'll look into it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this was happening cos i (robot) accidentally refactored the physical properties to logical, i'm reverting that! i was just using it for testing but i'll put it int the proper mdx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the horizontalCenterBeakRtlInline function that was removed before works well here.

Curious why it was removed?
I added it back in #3330
and it seems to do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants