Skip to content

Commit 4808877

Browse files
Move notification banner header bar to main component
1 parent 5c38de7 commit 4808877

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/components/content-presentation/notification-banner/NotificationBanner.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const NotificationBannerComponent = forwardRef<HTMLDivElement, NotificationBanne
4040
const items = Children.toArray(children);
4141
const titleElement = items.find((child) =>
4242
childIsOfComponentType(child, NotificationBannerTitle),
43-
) || <NotificationBannerTitle success={success}>{title}</NotificationBannerTitle>;
43+
);
4444
const nonTitleItems = items.filter(
4545
(child) => !childIsOfComponentType(child, NotificationBannerTitle),
4646
);
@@ -57,13 +57,19 @@ const NotificationBannerComponent = forwardRef<HTMLDivElement, NotificationBanne
5757
{ 'nhsuk-notification-banner--success': success },
5858
className,
5959
)}
60-
aria-labelledby={titleElement.props.id || 'nhsuk-notification-banner-title'}
60+
aria-labelledby={titleElement?.props.id || 'nhsuk-notification-banner-title'}
6161
data-module="nhsuk-notification-banner"
6262
data-disable-auto-focus={disableAutoFocus}
6363
ref={moduleRef}
6464
role={role || (success ? 'alert' : 'region')}
6565
>
66-
{titleElement}
66+
<div className="nhsuk-notification-banner__header">
67+
{titleElement ? (
68+
<>{titleElement}</>
69+
) : (
70+
<NotificationBannerTitle success={success}>{title}</NotificationBannerTitle>
71+
)}
72+
</div>
6773
<div className={'nhsuk-notification-banner__content'} {...rest}>
6874
{headerElement}
6975
{bodyItems}

src/components/content-presentation/notification-banner/components/NotificationBannerTitle.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ export const NotificationBannerTitle: FC<NotificationBannerTitleProps> = ({
1212
success,
1313
...rest
1414
}) => (
15-
<div className="nhsuk-notification-banner__header">
16-
<HeadingLevel
17-
className="nhsuk-notification-banner__title"
18-
headingLevel={headingLevel}
19-
id={id}
20-
{...rest}
21-
>
22-
{children || (success ? 'Success' : 'Important')}
23-
</HeadingLevel>
24-
</div>
15+
<HeadingLevel
16+
className="nhsuk-notification-banner__title"
17+
headingLevel={headingLevel}
18+
id={id}
19+
{...rest}
20+
>
21+
{children || (success ? 'Success' : 'Important')}
22+
</HeadingLevel>
2523
);
2624

2725
NotificationBannerTitle.displayName = 'NotificationBanner.Title';

0 commit comments

Comments
 (0)