All Projects → andreasbm → focus-trap

andreasbm / focus-trap

Licence: MIT license
A lightweight web component that traps focus within a DOM node

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to focus-trap

element
Fast and simple custom elements.
Stars: ✭ 65 (+47.73%)
Mutual labels:  web-components, custom-elements, shadow-dom
Remount
Mount React components to the DOM using custom elements
Stars: ✭ 522 (+1086.36%)
Mutual labels:  web-components, custom-elements, shadow-dom
svelte-webcomponents
A ready-to-use project template to build custom elements (web components) with Svelte 3 with support and examples for web components, jest, sass, nested components with props, eslinting, stylelinting, Github actions, propagating custom events from shadow-DOM to real-DOM etc.
Stars: ✭ 22 (-50%)
Mutual labels:  web-components, custom-elements, shadow-dom
Custom Elements Ts
Create native custom elements using Typescript
Stars: ✭ 52 (+18.18%)
Mutual labels:  web-components, custom-elements, shadow-dom
grid-container
A grid for the future, CSS Grid Layout + Web Components (Custom Elements v1 + Shadow DOM v1)
Stars: ✭ 51 (+15.91%)
Mutual labels:  web-components, custom-elements, shadow-dom
Nutmeg
Build, test, and publish vanilla Web Components with a little spice
Stars: ✭ 111 (+152.27%)
Mutual labels:  web-components, custom-elements, shadow-dom
Xy Ui
🎨面向未来的原生 web components UI组件库
Stars: ✭ 603 (+1270.45%)
Mutual labels:  web-components, custom-elements, shadow-dom
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+27520.45%)
Mutual labels:  web-components, custom-elements, shadow-dom
Shadow Dom In Depth
Everything you need to know about Shadow DOM
Stars: ✭ 191 (+334.09%)
Mutual labels:  web-components, custom-elements, shadow-dom
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (+56.82%)
Mutual labels:  web-components, custom-elements
lwc-test
LWC plugins and utilities for testing
Stars: ✭ 39 (-11.36%)
Mutual labels:  web-components, shadow-dom
file-attachment-element
Attach files via drag and drop or file input.
Stars: ✭ 97 (+120.45%)
Mutual labels:  web-components, custom-elements
CalDOM
An agnostic, reactive & minimalist (3kb) JavaScript UI library with direct access to native DOM.
Stars: ✭ 176 (+300%)
Mutual labels:  web-components, custom-elements
helium-animated-pages
A light spiritual succesor to neon-animated-pages using only css animations
Stars: ✭ 17 (-61.36%)
Mutual labels:  web-components, shadow-dom
smart-webcomponents-community
Material & Bootstrap Web Components built with Smart
Stars: ✭ 30 (-31.82%)
Mutual labels:  web-components, custom-elements
vue-focus-loop
Vue component that helps you to to trap focus in an element.
Stars: ✭ 23 (-47.73%)
Mutual labels:  focus, focus-trap
Shadow-DOM-inject-styles
🎉 A helper function to easily modify Shadow DOM CSS.
Stars: ✭ 47 (+6.82%)
Mutual labels:  web-components, shadow-dom
material-webcomponents
Material Design implemented in Web Components (Custom Elements v1)
Stars: ✭ 110 (+150%)
Mutual labels:  custom-elements, shadow-dom
web-components
A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
Stars: ✭ 322 (+631.82%)
Mutual labels:  web-components, custom-elements
page-title
A Polymer element for easily updating a webpage's title, such as in a SPA.
Stars: ✭ 13 (-70.45%)
Mutual labels:  web-components, custom-elements

@a11y/focus-trap

Downloads per month NPM Version Dependencies Contributors Published on webcomponents.org

A lightweight web component that traps focus within a DOM node
A focus trap ensures that tab and shift + tab keys will cycle through the focus trap's tabbable elements but not leave the focus trap. This is great for making accessible modals. Go here to see a demo https://appnest-demo.firebaseapp.com/focus-trap/.


  • Does one things very very well - it traps the focus!
  • Pierces through the shadow roots when looking for focusable elements.
  • Works right out of the box (just add it to your markup)
  • Created using only vanilla js - no dependencies and framework agnostic!

-----------------------------------------------------

➤ Installation

npm i @a11y/focus-trap

-----------------------------------------------------

➤ Usage

Import @a11y/focus-trap somewhere in your code and you're ready to go! Simply add the focus trap to your html and it'll be working without any more effort from your part.

<focus-trap>
  <button>Focus 1</button>
  <button>Focus 2</button>
  <button>Focus 3</button>
  <button>Focus 4</button>
  <button>Focus 5</button>
</focus-trap>

-----------------------------------------------------

➤ API

The focus-trap element implements the following interface.

interface IFocusTrap {
  // Returns whether or not the focus trap is inactive.
  inactive: boolean;

  // Returns whether the focus trap currently has focus.
  readonly focused: boolean;

  // Focuses the first focusable element in the focus trap.
  focusFirstElement: (() => void);

  // Focuses the last focusable element in the focus trap.
  focusLastElement: (() => void);

  // Returns a list of the focusable children found within the element.
  getFocusableElements: (() => HTMLElement[]);
}

-----------------------------------------------------

➤ License

Licensed under MIT.

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].