Skip to content

Commit 90731e5

Browse files
tsullivantkajtoch
andauthored
[EuiFlyoutMenu] add hideTitle prop for “main” flyouts in a session (#9150)
Co-authored-by: Tomasz Kajtoch <tomek@kajto.ch>
1 parent e9787a9 commit 90731e5

12 files changed

Lines changed: 518 additions & 78 deletions

packages/eui/src/components/flyout/flyout.component.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,15 @@ export const EuiFlyoutComponent = forwardRef(
611611
return _titleId || generatedMenuId;
612612
}, [hasMenu, _titleId, generatedMenuId]);
613613

614+
// If the flyout level is LEVEL_MAIN, the title should be hidden by default
615+
const flyoutMenuHideTitle = useMemo(() => {
616+
if (!hasMenu) return undefined;
617+
if (_flyoutMenuProps?.hideTitle !== undefined) {
618+
return _flyoutMenuProps.hideTitle;
619+
}
620+
return currentSession?.mainFlyoutId === flyoutId;
621+
}, [hasMenu, _flyoutMenuProps, currentSession, flyoutId]);
622+
614623
const ariaLabelledBy = useMemo(() => {
615624
if (flyoutMenuId) {
616625
return classnames(flyoutMenuId, _ariaLabelledBy);
@@ -700,7 +709,11 @@ export const EuiFlyoutComponent = forwardRef(
700709
/>
701710
)}
702711
{_flyoutMenuProps && (
703-
<EuiFlyoutMenu {...flyoutMenuProps} titleId={flyoutMenuId} />
712+
<EuiFlyoutMenu
713+
{...flyoutMenuProps}
714+
hideTitle={flyoutMenuHideTitle}
715+
titleId={flyoutMenuId}
716+
/>
704717
)}
705718
{resizable && (
706719
<EuiFlyoutResizeButton

packages/eui/src/components/flyout/flyout_menu.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { EuiText } from '../text';
1616
import { EuiFlyout } from './flyout';
1717
import { EuiFlyoutBody } from './flyout_body';
1818
import { EuiFlyoutMenu, EuiFlyoutMenuProps } from './flyout_menu';
19+
import { EuiFlyoutHeader } from './flyout_header';
1920

2021
interface Args extends EuiFlyoutMenuProps {
2122
showCustomActions: boolean;
@@ -26,6 +27,7 @@ const meta: Meta<Args> = {
2627
title: 'Layout/EuiFlyout/EuiFlyoutMenu',
2728
component: EuiFlyoutMenu,
2829
argTypes: {
30+
hideTitle: { control: 'boolean' },
2931
showBackButton: { control: 'boolean' },
3032
showCustomActions: { control: 'boolean' },
3133
'aria-label': { table: { disable: true } },
@@ -38,13 +40,15 @@ const meta: Meta<Args> = {
3840
showBackButton: true,
3941
showCustomActions: true,
4042
showHistoryItems: true,
43+
hideTitle: true,
4144
},
4245
};
4346

4447
export default meta;
4548

4649
const MenuBarFlyout = (args: Args) => {
4750
const {
51+
hideTitle,
4852
hideCloseButton,
4953
showBackButton,
5054
showCustomActions,
@@ -80,6 +84,8 @@ const MenuBarFlyout = (args: Args) => {
8084
'aria-label': `${iconType} action`,
8185
}));
8286

87+
const titleId = 'menu-bar-example-main-title';
88+
8389
return (
8490
<>
8591
<EuiButton onClick={openFlyout} disabled={isFlyoutOpen}>
@@ -94,15 +100,25 @@ const MenuBarFlyout = (args: Args) => {
94100
type="overlay"
95101
outsideClickCloses={false}
96102
ownFocus
103+
aria-labelledby={titleId}
97104
flyoutMenuProps={{
98105
title: 'Flyout title',
106+
titleId,
107+
hideTitle,
99108
hideCloseButton,
100109
showBackButton,
101110
backButtonProps,
102111
historyItems,
103112
customActions: showCustomActions ? customActions : undefined,
104113
}}
105114
>
115+
{hideTitle && (
116+
<EuiFlyoutHeader hasBorder>
117+
<EuiText>
118+
<h2 id={titleId}>Simple flyout header</h2>
119+
</EuiText>
120+
</EuiFlyoutHeader>
121+
)}
106122
<EuiFlyoutBody>
107123
<EuiText>
108124
<p>Simple flyout content.</p>

packages/eui/src/components/flyout/flyout_menu.styles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { css } from '@emotion/react';
1010
import { UseEuiTheme } from '../../services';
11+
import { euiScreenReaderOnly } from '../accessibility';
1112

1213
export const euiFlyoutMenuStyles = (euiThemeContext: UseEuiTheme) => {
1314
const { euiTheme } = euiThemeContext;
@@ -31,5 +32,8 @@ export const euiFlyoutMenuStyles = (euiThemeContext: UseEuiTheme) => {
3132
euiFlyoutMenu__actions: css`
3233
block-size: calc(${euiTheme.size.m} * 1.8);
3334
`,
35+
euiFlyoutMenu__hiddenTitle: css`
36+
${euiScreenReaderOnly()}
37+
`,
3438
};
3539
};

0 commit comments

Comments
 (0)