React Focus Trap Component API
Focus Trap API
Explore the API reference for the React Focus Trap component and discover how to effectively utilize its props for accessibility compliance.
CFocusTrap#
import { CFocusTrap } from '@coreui/react'// orimport CFocusTrap from '@coreui/react/src/components/focus-trap/CFocusTrap'
Property | Default | Type |
---|---|---|
active# | true | boolean |
Controls whether the focus trap is active or inactive. When | ||
additionalContainer# | - | RefObject<HTMLElement> |
Additional container elements to include in the focus trap. Useful for floating elements like tooltips or popovers that are rendered outside the main container but should be part of the trap. | ||
children# | - | ReactElement |
Single React element that renders a DOM node and forwards refs properly. The focus trap will be applied to this element and all its focusable descendants.
| ||
focusFirstElement# | false | boolean |
Controls whether to focus the first selectable element or the container itself. When | ||
onActivate# | - | () => void |
Callback function invoked when the focus trap becomes active. Useful for triggering additional accessibility announcements or analytics. | ||
onDeactivate# | - | () => void |
Callback function invoked when the focus trap is deactivated. Can be used for cleanup, analytics, or triggering state changes. | ||
restoreFocus# | true | boolean |
Automatically restores focus to the previously focused element when the trap is deactivated. This is crucial for accessibility as it maintains the user's place in the document when returning from modal dialogs or overlay components. |