![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@daniel.husar/focus-trap
Advanced tools
Add focus traps around elements.
Adding a focus traps is important part of making your site accessible. The most common example where you want to set up a focus trap is a modal. While modal is open, the user shouldn't be able to tab outside of it, and focus should be locked within the modal elements. You have to remember to make sure there is always a way how to exit this focus trap. In modal example it's usually the escape key, or close button in the corner.
Using npm
npm install @daniel.husar/focus-trap
Using yarn
yarn add @daniel.husar/focus-trap
import FocusTrap from '@daniel.husar/focus-trap';
// Setup trap
const trap = new FocusTrap({ node: document.querySelector('#my-trap') });
// Release trap
trap.restore();
Constructor accept object with those properties:
new FocusTrap({
node: document.querySelector('#my-trap') }),
firstElement: () => document.querySelector('#first-element'),
lastElement: () => document.querySelector('#last-element'),
disableStartingTrap: () => false,
disableEndingTrap: () => false,
});
Type: DOM element
Default: none
Required: true
This is the DOM node you want to set-up focus trap around
Type: Function
Default: () => null
Required: none
Function that returns element that will replace first element when focus will jump back at the start. Usefull when you want to connect 2 focus traps together. Will fallback to firstElement in focus trap if function returns falsy value.
Type: Function
Default: () => null
Required: none
Function that returns element that will replace last element when focus will jump back at the end. Usefull when you want to connect 2 focus traps together. Will fallback to lastElement in focus trap if function returns falsy value.
Type: Function
Default: () => false
Required: none
Function that returns boolean if the starting trap should be disabled.
Type: Function
Default: () => false
Required: none
Function that can returns boolean if the ending trap should be disabled.
Type: Function
Recalculate focusable elements inside of your trap. Usefull if content of the node changes over time.
Type: Function
Remove the focus trap from element.
MIT © Daniel Husar
FAQs
Add focus traps to the elements
We found that @daniel.husar/focus-trap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.