FocusLock
FocusLock
is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range.
const { open, onToggle } = useDisclosure()
return (
<VStack align="flex-start" gap="0">
<Button onClick={onToggle}>Please Click</Button>
<Collapse open={open}>
<FocusLock>
<VStack mt="lg" bg="bg.panel" p="lg" rounded="l2">
<Input placeholder="This is Input" bg="bg" />
<Button alignSelf="flex-end">Button</Button>
</VStack>
</FocusLock>
</Collapse>
</VStack>
)
"use client"
to the top of the file.Usage
import { FocusLock } from "@yamada-ui/react"
import { FocusLock } from "@/components/ui"
import { FocusLock } from "@workspaces/ui"
<FocusLock />