Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/eui/changelogs/upcoming/9373.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added optional `scrollContainerRef` prop to `EuiFlyoutBody` for accessing the flyout's internal scroll container.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`EuiCollapsibleNavBody renders 1`] = `
>
<div
class="euiFlyoutBody__overflow emotion-euiFlyoutBody__overflow-noBanner"
data-test-subj="euiFlyoutBodyOverflow"
tabindex="-1"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`EuiFlyoutBody is rendered 1`] = `
>
<div
class="euiFlyoutBody__overflow emotion-euiFlyoutBody__overflow-noBanner"
data-test-subj="euiFlyoutBodyOverflow"
tabindex="0"
>
<div
Expand Down
3 changes: 3 additions & 0 deletions packages/eui/src/components/flyout/flyout_body.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { EuiCallOut } from '../call_out';
import { EuiFlyout } from './flyout';
import { EuiFlyoutBody, EuiFlyoutBodyProps } from './flyout_body';
import { LOKI_SELECTORS } from '../../../.storybook/loki';
import { disableStorybookControls } from '../../../.storybook/utils';

const meta: Meta<EuiFlyoutBodyProps> = {
title: 'Layout/EuiFlyout/EuiFlyoutBody',
Expand All @@ -32,6 +33,8 @@ const meta: Meta<EuiFlyoutBodyProps> = {
},
};

disableStorybookControls(meta, ['scrollContainerRef']);

export default meta;
type Story = StoryObj<EuiFlyoutBodyProps>;

Expand Down
12 changes: 12 additions & 0 deletions packages/eui/src/components/flyout/flyout_body.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ describe('EuiFlyoutBody', () => {
'-1'
);
});

test('scrollContainerRef', () => {
const scrollContainerRef = React.createRef<HTMLDivElement>();

render(<EuiFlyoutBody scrollContainerRef={scrollContainerRef} />);

expect(scrollContainerRef.current).toBeInstanceOf(HTMLDivElement);
expect(scrollContainerRef.current).toHaveAttribute(
'data-test-subj',
'euiFlyoutBodyOverflow'
);
});
});
14 changes: 13 additions & 1 deletion packages/eui/src/components/flyout/flyout_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
* Side Public License, v 1.
*/

import React, { FunctionComponent, HTMLAttributes, ReactNode } from 'react';
import React, {
FunctionComponent,
HTMLAttributes,
ReactNode,
Ref,
} from 'react';
import classNames from 'classnames';
import { CommonProps } from '../common';
import { useEuiMemoizedStyles } from '../../services';
Expand All @@ -29,6 +34,10 @@ export type EuiFlyoutBodyProps = FunctionComponent<
* to override this default.
*/
scrollableTabIndex?: number;
/**
* Use to access the flyout's internal scrollable container.
*/
scrollContainerRef?: Ref<HTMLDivElement>;
}
>;

Expand All @@ -37,6 +46,7 @@ export const EuiFlyoutBody: EuiFlyoutBodyProps = ({
className,
banner,
scrollableTabIndex = 0,
scrollContainerRef,
...rest
}) => {
const classes = classNames('euiFlyoutBody', className);
Expand All @@ -53,6 +63,8 @@ export const EuiFlyoutBody: EuiFlyoutBodyProps = ({
tabIndex={scrollableTabIndex}
className="euiFlyoutBody__overflow"
css={overflowCssStyles}
ref={scrollContainerRef}
data-test-subj="euiFlyoutBodyOverflow"
>
{banner && (
<div
Expand Down