Skip to content
F

focus-trap-react

A React component that traps focus

by davidtheclarkFree

#71in UI Libraries
0In stores

Description

focus-trap-react is a React component that traps keyboard focus inside one of its children, which is useful for an accessible modal. It is a…

Highlights

  • Traps focus inside a React child element
  • Activates on mount and releases on unmount
  • Props to pause and unpause the trap
  • Requires React 18 or later

Ratings & Reviews

No ratings yet

Be the first to rate focus-trap-react.

People also visit

R

react-aria-modal

A fully accessible

UI Libraries
Launch
R

react-modal

Accessible modal dialog component for React

UI Libraries
Launch
R

react-hotkeys

A declarative library for handling hotkeys and focus within a React application

UI Libraries
Launch
R

react-keyboard

A declarative library for handling hotkeys and focus within a React application

UI Libraries
Launch
R

@rc-component/portal

React Portal Component

UI Libraries
Launch
R

react-bootstrap-modal

React Bootstrap Modal ===================================

UI Libraries
Launch

focus-trap-react FAQ

What does focus-trap-react do?

It keeps keyboard focus inside a React element, such as a modal, until the trap is deactivated.

What React version does it need?

React 18.0.0 or later, according to the README.

Can the child be a fragment?

No. The child must be a single element, because the component needs a reference to the underlying DOM element.

Which browsers are supported?

Desktop Chrome, Edge, Firefox, Safari and Opera, and not Internet Explorer. Mobile browsers are not officially tested.

Does it use propTypes?

No. The README says propTypes and defaultProps are no longer assigned, and suggests TypeScript or a runtime validation library.

What are the best focus-trap-react alternatives?

Popular alternatives to focus-trap-react include react-aria-modal, react-modal and react-hotkeys. See all focus-trap-react alternatives

Developer Stuff

Badges