File tree Expand file tree Collapse file tree
packages/eui/src/components/flyout Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 * Side Public License, v 1.
77 */
88
9- import React , { useState } from 'react' ;
9+ import React , { useRef , useState } from 'react' ;
1010import type { Meta , StoryObj } from '@storybook/react' ;
1111import { action } from '@storybook/addon-actions' ;
1212
@@ -56,10 +56,17 @@ const onClose = action('onClose');
5656
5757const StatefulFlyout = ( props : Partial < EuiFlyoutProps > ) => {
5858 const [ isOpen , setIsOpen ] = useState ( true ) ;
59+ const manualTriggerRef = useRef < HTMLButtonElement > ( null ) ;
60+
5961 return (
6062 < >
61- < EuiButton size = "s" onClick = { ( ) => setIsOpen ( ! isOpen ) } >
62- Toggle flyout
63+ { ! isOpen && (
64+ < EuiButton size = "s" onClick = { ( ) => setIsOpen ( ! isOpen ) } >
65+ Toggle flyout
66+ </ EuiButton >
67+ ) }
68+ < EuiButton size = "s" id = "foobar" buttonRef = { manualTriggerRef } >
69+ Another button
6370 </ EuiButton >
6471 { isOpen && (
6572 < EuiFlyout
@@ -68,6 +75,16 @@ const StatefulFlyout = (props: Partial<EuiFlyoutProps>) => {
6875 setIsOpen ( false ) ;
6976 onClose ( ...args ) ;
7077 } }
78+ focusTrapProps = { {
79+ returnFocus : ( triggerElement : Element ) => {
80+ if ( ! triggerElement || triggerElement === document . body ) {
81+ manualTriggerRef . current ?. focus ( ) ;
82+ return false ;
83+ }
84+
85+ return true ;
86+ } ,
87+ } }
7188 />
7289 ) }
7390 </ >
You can’t perform that action at this time.
0 commit comments