import React from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; import Box from '../../ui/box'; import { BorderColor, DISPLAY, FLEX_DIRECTION, } from '../../../helpers/constants/design-system'; import { ModalFocus } from './modal-focus'; import README from './README.mdx'; export default { title: 'Components/ComponentLibrary/ModalFocus', component: ModalFocus, parameters: { docs: { page: README, }, }, args: { children: ( <>

Modal focus children

Use the keyboard to try tabbing around you will notice that the focus is locked to the content within modal focus

), }, } as ComponentMeta; const Template: ComponentStory = (args) => { const [open, setOpen] = React.useState(false); return ( <> {open && ( {args.children} )} ); }; export const DefaultStory = Template.bind({}); DefaultStory.storyName = 'Default'; export const Children = Template.bind({}); Children.args = { children: ( <>

Modal focus children

), }; export const InitialFocusRef = (args) => { const ref = React.useRef(null); const [open, setOpen] = React.useState(false); return ( <> {open && ( {args.children} )} ); }; InitialFocusRef.args = { children:

Initial focus is on the close button

, }; export const FinalFocusRef = (args) => { const ref = React.useRef(null); const [open, setOpen] = React.useState(false); return ( <> {open && (

Focus will be returned to the input once closed

)} ); }; export const RestoreFocus = (args) => { const ref = React.useRef(null); const [open, setOpen] = React.useState(false); return ( <> {open && (

Focus will be restored to the open button once closed

)} ); }; export const AutoFocus = Template.bind({}); AutoFocus.args = { autoFocus: false, children:

auto focus set to false

, };