All Projects → jossmac → react-focus-marshal

jossmac / react-focus-marshal

Licence: MIT License
👮🏻 Traps focus within a DOM node

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-focus-marshal

focus-trap-vue
Vue component to trap the focus within a DOM element
Stars: ✭ 156 (+87.95%)
Mutual labels:  focus, trap
freefocus
"Visual", no-hassle navigation in HTML using IR remote / arrow keys
Stars: ✭ 18 (-78.31%)
Mutual labels:  focus
react-tv-navigation
React Navigation for TVs
Stars: ✭ 64 (-22.89%)
Mutual labels:  focus
snmp notifier
A webhook to relay Prometheus alerts as SNMP traps, because sometimes, you have to deal with legacy
Stars: ✭ 33 (-60.24%)
Mutual labels:  trap
focus-options-polyfill
JavaScript polyfill for the WHATWG spec of focusOptions, that enables a set of options to be passed to the focus method
Stars: ✭ 46 (-44.58%)
Mutual labels:  focus
introspected
Introspection for serializable arrays and JSON friendly objects.
Stars: ✭ 75 (-9.64%)
Mutual labels:  trap
Unity-2017.2-and-Vuforia-6.5---Camera-Auto-Focus
Unity 2017.2 and Vuforia 6.5 Augmented Reality (AR) Camera Auto Focus
Stars: ✭ 17 (-79.52%)
Mutual labels:  focus
one-goal
A macOS menu bar APP helps you stay focused
Stars: ✭ 66 (-20.48%)
Mutual labels:  focus
HeadsDown
Auto-enable "Do not disturb" while coding or designing.
Stars: ✭ 18 (-78.31%)
Mutual labels:  focus
reveal-code-focus
A Reveal.js plugin that allows focusing on specific lines of code blocks.
Stars: ✭ 108 (+30.12%)
Mutual labels:  focus
lrud
Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls
Stars: ✭ 31 (-62.65%)
Mutual labels:  focus
AppKitFocusOverlay
Add hotkey(s) to display the key focus path for any window in your AppKit application.
Stars: ✭ 42 (-49.4%)
Mutual labels:  focus
vue-focus-keyboard
A keyboard component for Vue. Start to write immediately. No input element definition. Plug and play!
Stars: ✭ 63 (-24.1%)
Mutual labels:  focus
rainmood
一个简单项目,只有一个页面。循环播放十首电影原声精选,背景乐为下雨声。
Stars: ✭ 12 (-85.54%)
Mutual labels:  focus
vim-iawriter
iAwriter's Focus mode for vim
Stars: ✭ 23 (-72.29%)
Mutual labels:  focus
vue-focus-loop
Vue component that helps you to to trap focus in an element.
Stars: ✭ 23 (-72.29%)
Mutual labels:  focus
focus-trap
A lightweight web component that traps focus within a DOM node
Stars: ✭ 44 (-46.99%)
Mutual labels:  focus
AnotherPomodoro
Modern and customizable productivity timer app that runs in your browser.
Stars: ✭ 126 (+51.81%)
Mutual labels:  focus
focus-svelte
focus lock for svelte
Stars: ✭ 18 (-78.31%)
Mutual labels:  focus
fokus
Mobile application that helps kids complete their daily tasks under parental control
Stars: ✭ 21 (-74.7%)
Mutual labels:  focus

Focus Marshal

Traps focus within a DOM node — subsequently mounted traps will take control of focus and pause others until unmounted.

Install

yarn add react-focus-manager

Use

You must wrap the applicable section of your app in the FocusMarshal, which provides context to the FocusTrap descendants.

import { FocusTrap, FocusMarshal } from 'react-focus-marshal';

const Modal = () => createPortal(
  <FocusTrap>
    <div>
      {/* modal content */}
    </div>
  </FocusTrap>,
  document.body
);

const App = () => (
  <FocusMarshal>
    {someCondition ? <Modal /> : null}
  </FocusMarshal>
);

FocusMarshal Props

Property Description
children Node All children are passed through.

FocusTrap Props

Property Description
children Element<HTMLElement | ComponentType> A single element to trap focus within. The underlying DOM node will be resolved on the component passed as children.
Options OptionsType The options object that is passed to createFocusTrap. See below for definition.

Acknowledgement

The FocusTrap component is a thin wrapper around David Clark's fantastic focus-trap library. Whilst react-focus-marshal attempts to maintain feature parity, there are some minor differences; see fallbackFocus property below.

OptionsType

For brevity:

  • FocusTarget is equal to HTMLElement | string | () => HTMLElement.
  • ActivationFn is equal to Ref => void.
Property Description
onActivate ActivationFn A function that will be called when the focus trap activates.
onDeactivate ActivationFn A function that will be called when the focus trap deactivates.
initialFocus FocusTarget Defaults to the first "tabbable" element -- a string value will be passed to document.querySelector().
fallbackFocus FocusTarget The required children element is used as a safe way to fulfill the contract with "focus-trap".
escapeDeactivates boolean Default: true. If false, the Escape key will not trigger deactivation of the focus trap.
clickOutsideDeactivates boolean Default: false. If true, a click outside the focus trap will deactivate the focus trap and allow the click event to do its thing.
returnFocusOnDeactivate boolean Default: true. If false, when the trap is deactivated, focus will not return to the element that had focus before activation.

Alternatives

This library may not meet your needs. Here are some alternative I came across whilst searching for this solution:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].