Skip to content

Commit c8c15fb

Browse files
committed
Allow flyout size to be undefined, default to ‘m’
1 parent faf365c commit c8c15fb

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

packages/eui/src/components/flyout/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The managed flyout wrapper that integrates with the flyout manager system, handl
5454

5555
### `src/components/flyout/manager/flyout_validation.ts`
5656
Validation utilities for managed flyout props:
57-
- **Named Size Validation**: Managed flyouts must use named sizes (s, m, l)
57+
- **Named Size Validation**: Managed flyouts must use named sizes (s, m, l). If not provided, defaults to 'm'.
5858
- **Size Combination Rules**: Parent and child can't both be 'm', parent can't be 'l' with child
5959
- **Title**: Must be provided either through `flyoutMenuProps` or `aria-label`
6060
- **Error Handling**: Comprehensive error messages for invalid configurations

packages/eui/src/components/flyout/manager/flyout_managed.test.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,49 @@ describe('EuiManagedFlyout', () => {
281281
});
282282
});
283283

284+
describe('size handling', () => {
285+
it('defaults size to "m" when no size is provided', () => {
286+
// Import the real validation function to test the actual behavior
287+
const { validateManagedFlyoutSize } = jest.requireActual('./validation');
288+
289+
// Temporarily restore the real validation function for this test
290+
const originalMock = require('./validation').validateManagedFlyoutSize;
291+
require('./validation').validateManagedFlyoutSize =
292+
validateManagedFlyoutSize;
293+
294+
const { getByTestSubject } = renderInProvider(
295+
<EuiManagedFlyout
296+
id="default-size-test"
297+
level={LEVEL_MAIN}
298+
onClose={() => {}}
299+
flyoutMenuProps={{ title: 'Test Flyout' }}
300+
// Explicitly not providing size prop
301+
/>
302+
);
303+
304+
// The flyout should render successfully, indicating the default size worked
305+
expect(getByTestSubject('managed-flyout')).toBeInTheDocument();
306+
307+
// Restore the mock
308+
require('./validation').validateManagedFlyoutSize = originalMock;
309+
});
310+
311+
it('uses provided size when size is explicitly set', () => {
312+
const { getByTestSubject } = renderInProvider(
313+
<EuiManagedFlyout
314+
id="explicit-size-test"
315+
level={LEVEL_MAIN}
316+
size="s"
317+
onClose={() => {}}
318+
flyoutMenuProps={{ title: 'Test Flyout' }}
319+
/>
320+
);
321+
322+
// The flyout should render successfully with explicit size
323+
expect(getByTestSubject('managed-flyout')).toBeInTheDocument();
324+
});
325+
});
326+
284327
describe('onClose callback behavior', () => {
285328
it('does not call onClose callback during component cleanup/unmount', () => {
286329
const onClose = jest.fn();

packages/eui/src/components/flyout/manager/flyout_managed.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export const EuiManagedFlyout = ({
8989
const layoutMode = useFlyoutLayoutMode();
9090
const styles = useEuiMemoizedStyles(euiManagedFlyoutStyles);
9191

92+
// Default the size to 'm' if not provided
93+
if (!size) {
94+
size = 'm';
95+
}
96+
9297
// Validate size
9398
const sizeTypeError = validateManagedFlyoutSize(size, flyoutId, level);
9499
if (sizeTypeError) {

packages/eui/src/components/flyout/manager/flyout_sessions.stories.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default meta;
3535

3636
interface FlyoutSessionProps {
3737
title: string;
38-
mainSize: 's' | 'm' | 'l' | 'fill';
38+
mainSize: 's' | 'm' | 'l' | 'fill' | undefined;
3939
mainMaxWidth?: number;
4040
childSize?: 's' | 'm' | 'fill';
4141
childMaxWidth?: number;
@@ -118,7 +118,10 @@ const FlyoutSession: React.FC<FlyoutSessionProps> = React.memo((props) => {
118118
type="column"
119119
listItems={[
120120
{ title: 'Flyout type', description: flyoutType },
121-
{ title: 'Main flyout size', description: mainSize },
121+
{
122+
title: 'Main flyout size',
123+
description: mainSize ?? 'undefined (`m` by default)',
124+
},
122125
{
123126
title: 'Main flyout maxWidth',
124127
description: mainMaxWidth ?? 'N/A',
@@ -245,12 +248,13 @@ const ExampleComponent = () => {
245248
),
246249
},
247250
{
248-
title: 'Session F: main size = s, child size = fill (maxWidth 1000px)',
251+
title:
252+
'Session F: main size = undefined, child size = fill (maxWidth 1000px)',
249253
description: (
250254
<FlyoutSession
251255
flyoutType={flyoutType}
252256
title="Session F"
253-
mainSize="s"
257+
mainSize={undefined}
254258
childSize="fill"
255259
childMaxWidth={1000}
256260
/>

0 commit comments

Comments
 (0)