Skip to content

Commit 92f2336

Browse files
committed
Make split panel header text optional
1 parent 6edaee1 commit 92f2336

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/split-panel/__tests__/header.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ import { describeEachAppLayout } from '../../app-layout/__tests__/utils';
66
import { renderSplitPanel } from './common';
77

88
describe('Split panel: Header slots', () => {
9+
test('warns when neither header nor headerBefore are provided', () => {
10+
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
11+
try {
12+
renderSplitPanel({ props: { header: undefined } });
13+
expect(consoleWarnSpy).toHaveBeenCalledWith(
14+
'[AwsUi] [SplitPanel] You must provide either `header` or `headerBefore`.'
15+
);
16+
} finally {
17+
consoleWarnSpy.mockRestore();
18+
}
19+
});
20+
921
describeEachAppLayout({ sizes: ['desktop', 'mobile'] }, () => {
1022
test('renders headerActions', () => {
1123
const { wrapper } = renderSplitPanel({

src/split-panel/implementation.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
44
import clsx from 'clsx';
55

6-
import { useMergeRefs, useUniqueId } from '@cloudscape-design/component-toolkit/internal';
6+
import { useMergeRefs, useUniqueId, warnOnce } from '@cloudscape-design/component-toolkit/internal';
77

88
import { useAppLayoutToolbarDesignEnabled } from '../app-layout/utils/feature-flags';
99
import { SizeControlProps } from '../app-layout/utils/interfaces';
@@ -46,6 +46,10 @@ export function SplitPanelImplementation({
4646
const isRefresh = useVisualRefresh();
4747
const isToolbar = useAppLayoutToolbarDesignEnabled();
4848

49+
if (!header && !headerBefore) {
50+
warnOnce('SplitPanel', 'You must provide either `header` or `headerBefore`.');
51+
}
52+
4953
const {
5054
position,
5155
topOffset,

src/split-panel/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface SplitPanelProps extends BaseComponentProps {
88
/**
99
* Header text of the split panel.
1010
*/
11-
header: string;
11+
header?: string;
1212
children: React.ReactNode;
1313
/**
1414
* Determines whether the split panel collapses or hides completely when closed.

0 commit comments

Comments
 (0)