Skip to content
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: Empty notifications height #2810

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app-layout/visual-refresh-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useEffect, useImperativeHandle, useState } from 'react';
import ScreenreaderOnly from '../../internal/components/screenreader-only';
import { SplitPanelSideToggleProps } from '../../internal/context/split-panel-context';
import { fireNonCancelableEvent } from '../../internal/events';
import * as tokens from '../../internal/generated/styles/tokens';
import { useControllable } from '../../internal/hooks/use-controllable';
import { useMobile } from '../../internal/hooks/use-mobile';
import { useUniqueId } from '../../internal/hooks/use-unique-id';
Expand Down Expand Up @@ -326,6 +327,7 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
setToolbarState,
verticalOffsets,
drawersOpenQueue,
notificationsHeight,
setToolbarHeight,
setNotificationsHeight,
onSplitPanelToggle: onSplitPanelToggleHandler,
Expand Down Expand Up @@ -377,7 +379,7 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
{!hasToolbar && breadcrumbs ? <ScreenreaderOnly>{breadcrumbs}</ScreenreaderOnly> : null}
<SkeletonLayout
style={{
[globalVars.stickyVerticalTopOffset]: `${verticalOffsets.header}px`,
[globalVars.stickyVerticalTopOffset]: `${verticalOffsets.header}px + ${resolvedStickyNotifications && notificationsHeight > 0 ? tokens.spaceXs : '0px'}`,
Copy link
Contributor Author

@georgylobko georgylobko Oct 7, 2024

Choose a reason for hiding this comment

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

You may ask why this space is calculated here, not in the computeVerticalLayout or not just calculate it as part of notifications height.

There are 2 reasons:

  1. Since now notifications height includes only actual content size, not the wrapper size, we need to take this space somewhere
  2. It's not feasible to include this to computeVerticalLayout, because tokens.spaceXs is not a number, but css token (string)

If you have a suggestion how to implement it better, let's discuss it in this thread

[globalVars.stickyVerticalBottomOffset]: `${placement.insetBlockEnd}px`,
paddingBlockEnd: splitPanelOpen && splitPanelPosition === 'bottom' ? splitPanelReportedSize : '',
}}
Expand Down
1 change: 1 addition & 0 deletions src/app-layout/visual-refresh-toolbar/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export interface AppLayoutInternals {
onActiveGlobalDrawersChange: (newDrawerId: string) => void;
toolsOpen: boolean;
onToolsToggle: (value: boolean) => void;
notificationsHeight: number;
}
14 changes: 9 additions & 5 deletions src/app-layout/visual-refresh-toolbar/notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export function AppLayoutNotificationsImplementation({
appLayoutInternals,
children,
}: AppLayoutNotificationsImplementationProps) {
const { ariaLabels, stickyNotifications, setNotificationsHeight, verticalOffsets } = appLayoutInternals;
const ref = useRef<HTMLElement>(null);
const { ariaLabels, stickyNotifications, setNotificationsHeight, verticalOffsets, notificationsHeight } =
appLayoutInternals;
const ref = useRef<HTMLDivElement>(null);
const hasNotificationsContent = notificationsHeight > 0;
useResizeObserver(ref, entry => setNotificationsHeight(entry.borderBoxHeight));
useEffect(() => {
return () => {
Expand All @@ -33,13 +35,15 @@ export function AppLayoutNotificationsImplementation({
}, []);
return (
<NotificationsSlot
ref={ref}
className={clsx(stickyNotifications && styles['sticky-notifications'])}
className={clsx(
stickyNotifications && styles['sticky-notifications'],
hasNotificationsContent && styles['has-notifications-content']
)}
style={{
insetBlockStart: stickyNotifications ? verticalOffsets.notifications : undefined,
}}
>
<div className={testutilStyles.notifications} role="region" aria-label={ariaLabels?.notifications}>
<div ref={ref} className={testutilStyles.notifications} role="region" aria-label={ariaLabels?.notifications}>
{children}
</div>
</NotificationsSlot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
@use '../../../internal/styles/tokens' as awsui;

.sticky-notifications {
position: sticky;
z-index: 850;
}

.has-notifications-content {
padding-block-start: awsui.$space-scaled-xs;
just-boris marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 0 additions & 3 deletions src/app-layout/visual-refresh-toolbar/skeleton/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@

.notifications-container {
grid-area: notifications;
&:not(:empty) {
padding-block-start: awsui.$space-scaled-xs;
}
}

.main-landmark {
Expand Down
Loading