-
Notifications
You must be signed in to change notification settings - Fork 170
fix: Implement TopNavigation breakpoints in CSS #3371
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?
fix: Implement TopNavigation breakpoints in CSS #3371
Conversation
Hello @TrevorBurnham, Thanks for contributing the fix! Our team is taking a look and running internal screenshot tests and manual tests. Could you please fix the failing unit tests? P.S. the "Measure bundle size" action is expected to fail, please ignore it. |
9c18810
to
51e8d78
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3371 +/- ##
==========================================
- Coverage 96.46% 96.46% -0.01%
==========================================
Files 805 805
Lines 23019 23004 -15
Branches 7963 7535 -428
==========================================
- Hits 22205 22190 -15
- Misses 760 807 +47
+ Partials 54 7 -47 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@TrevorBurnham, thanks for addressing the tests! Please also take a look at test coverage. Also, there is a small regression: the right hand size padding became smaller, see attachments: |
Thanks! Can you give me instructions for viewing the component before/after? What I've been doing is running |
The npm run build should be fine: you can build the mainline and then your commit, and compare the differences. The |
51e8d78
to
ef604a8
Compare
I've updated the PR branch to fix the visual inconsistencies and improve code coverage. One call-out: Previously |
@@ -101,10 +101,10 @@ export class TopNavigationMenuDropdownWrapper extends ButtonDropdownWrapper { | |||
} | |||
|
|||
findTitle(): ElementWrapper | null { | |||
return this.findByClassName(buttonDropdownStyles.title); | |||
return createWrapper().findComponent(`.${buttonDropdownStyles.title}`, ElementWrapper); |
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.
What is the reason of this change?
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.
Without this change, the test
TopNavigation Utility part › Menu dropdown › has a title in the dropdown
fails to find the title element, due to the menu dropdown having expandToViewport
.
@@ -40,20 +40,30 @@ export default class ButtonDropdownWrapper extends ComponentWrapper { | |||
* Finds an item in the open dropdown by item id. Returns null if there is no open dropdown. | |||
* | |||
* This utility does not open the dropdown. To find dropdown items, call `openDropdown()` first. | |||
* |
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.
There are many button dropdown tests that use expandToViewport (see example: https://github.com/cloudscape-design/components/blob/main/src/button-dropdown/__tests__/button-dropdown-highlighted.test.tsx#L24), but the expandToViewport option wasn't needed. I think that is because the findOpenDropdown()
method searches from the root, not component root - assuming there is at most one open dropdown. Why do we need the expandToViewport option now?
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.
Good call-out. This change wasn't needed.
@@ -39,3 +51,27 @@ $_largest_breakpoint: $breakpoint-x-large; | |||
@content; | |||
} | |||
} | |||
|
|||
// Container query for widths greater than the given breakpoint. |
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.
Nice 👍
This commit switches from JavaScript-based breakpoints to CSS container queries for TopNavigation, making its appearance consistent when rendered with SSR. To support container queries, we need `container-type: inline-size;` on the TopNavigation root element. This causes overflowing content to get clipped (at least in Safari), so I've enabled `expandToViewport` to render utility dropdowns in a portal. Note that OverflowMenu doesn't need this treatment because it expands the height of TopNavigation rather than overflowing. Fixes cloudscape-design#3337
ef604a8
to
0da8645
Compare
I've rebased this branch and made the following changes:
|
Description
This PR switches from JavaScript-based breakpoints to CSS container queries for TopNavigation, making its appearance consistent when rendered with SSR. I've added Sass mixins for this purpose that can be reused across other components to replace the
useBreakpoints
hook.I've opted to use container queries rather than media queries for backward compatibility's sake, since
useBreakpoints
checks container size rather than viewport size. However, this introduces a complication: To use container queries, we need to addcontainer-type: inline-size
to the TopNavigation element's styles.I noticed that adding
container-type: inline-size
causes overflowing content to get clipped in Safari due to a longstanding bug in that browser. [Update 4/5: After updating to Safari 18.4 on my Mac, I no longer see the bug, so it looks like Apple just fixed this.] To address that, I've enabledexpandToViewport
to render utility dropdowns in a portal. I've also addedposition: relative
andz-index: 1
to theTopNavigation
styles to give it a stacking context, which appears to help with the issue. However, there is still a possibility that users who are rendering their own dropdowns in theTopNavigation
(e.g. by using anAutosuggest
searchbox) withoutexpandToViewport
may see issues in older versions of Safari where the dropdown is rendered behind other content with a higherz-index
. I would suggest calling this out in the release notes and recommending the use ofexpandToViewport
for dropdowns inTopNavigation
.Once this change is merged, I'd love to start applying this same change to other components that use
useBreakpoints
. Container queries are supported in all modern browsers.Fixes #3337
How has this been tested?
I've run this change locally, eyeballed it at different breakpoints, and clicked various controls to ensure that they're visible. I'm open to ideas for testing the breakpoint behavior more thoroughly.
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md
.CONTRIBUTING.md
.Security
checkSafeUrl
function.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.