-
Notifications
You must be signed in to change notification settings - Fork 155
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
fix: Refactor and fix AppLayout and side navigation panel state and behaviour #1434
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1434 +/- ##
=======================================
Coverage 93.78% 93.79%
=======================================
Files 639 639
Lines 17228 17231 +3
Branches 5665 5667 +2
=======================================
+ Hits 16158 16161 +3
Misses 997 997
Partials 73 73
☔ View full report in Codecov by Sentry. |
cf9007a
to
b9eb880
Compare
src/app-layout/index.tsx
Outdated
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isMobile]); |
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.
As opposed to adding more eslint-disable-next-line
exceptions, I suggest converting const onNavigationToggle = useCallback(() => {}, [])
to const onNavigationToggle = useStableCallback(() => {})
. This value will be safe to put into effects
src/side-navigation/internal.tsx
Outdated
@@ -412,6 +412,7 @@ function ExpandableLinkGroup({ definition, fireFollow, fireChange, activeHref, v | |||
variant="navigation" | |||
expanded={userExpanded ?? expanded} | |||
onChange={onExpandedChange} | |||
__disableExpandChangeOnHeaderTextClick={disableExpandChangeOnHeaderTextClick} |
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.
Can we do this without an internal prop?
For example, what if we baked this behavior into the navigation
variant of expandable section?
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.
I've changed from using an internal prop (for detecting the desired behaviour of the trigger to expand the section) into the "navigation"
variant of the expandable section.
navigation
- Use this variant in the navigation panel with anchors and custom styled content. It doesn't have any default styles.
This is a more impactful change, but between a successful dry-run (ID: 6564992503) and our current guidelines (above), I'm confident this is the best approach.
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.
Let's do it!
src/app-layout/__tests__/utils.tsx
Outdated
@@ -87,7 +87,7 @@ export function describeEachAppLayout(callback: () => void) { | |||
(useMobile as jest.Mock).mockReset(); | |||
(useVisualRefresh as jest.Mock).mockReset(); | |||
}); | |||
callback(); | |||
callback(size as 'desktop' | 'mobile'); |
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.
minor: Instead of casting the value of the variable (technically not safe), it would be better to cast the array that you iterate over (const size of ['desktop', 'mobile'] as const
)
@@ -95,14 +95,15 @@ const ExpandableNavigationHeader = ({ | |||
icon, | |||
}: ExpandableNavigationHeaderProps) => { | |||
return ( |
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.
<ExpandableNavigationHeader />
is rendered conditionally only for the navigation
variant, so the change below is only applied to this variant.
components/src/expandable-section/expandable-section-header.tsx
Lines 255 to 265 in 4c020a8
if (variant === 'navigation') { | |
return ( | |
<ExpandableNavigationHeader | |
className={clsx(className, wrapperClassName)} | |
ariaLabelledBy={ariaLabelledBy} | |
{...defaultHeaderProps} | |
> | |
{headerText ?? header} | |
</ExpandableNavigationHeader> | |
); | |
} |
Description
When clicking a navigation link in mobile AppLayout side navigation, the panel should close automatically. Furthermore, on mobile viewports, the side navigation should also be closed by default.
This used to be handled in our code, but has regressed:
This behavior is supposed to be handled by the AppLayout.
However, our side navigation was blocking this code. I've split the event listener to be applied to both the header text and trigger button for the expandable section, so we don't need the
stopPropagation
.There was also a unit test for it, but very artificial and this is why the regression was not caught:
components/src/app-layout/__tests__/mobile.test.tsx
Line 85 in 715264b
Related links: AWSUI-21892
How has this been tested?
Existing tests, updated some "artificial ones" and added new ones to cover the expected behaviour.
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.