All Projects → vue-a11y → vue-focus-loop

vue-a11y / vue-focus-loop

Licence: MIT license
Vue component that helps you to to trap focus in an element.

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to vue-focus-loop

focus-svelte
focus lock for svelte
Stars: ✭ 18 (-21.74%)
Mutual labels:  accessibility, focus, focus-trap
Focusoverlay
Library for creating animated overlays on focused elements
Stars: ✭ 167 (+626.09%)
Mutual labels:  accessibility, a11y, focus
enabler
✋ Accessibility analyzer for your frontend.
Stars: ✭ 19 (-17.39%)
Mutual labels:  accessibility, a11y, vue-a11y
Ally.js
JavaScript library to help modern web applications with accessibility concerns
Stars: ✭ 1,447 (+6191.3%)
Mutual labels:  accessibility, a11y, focus
Houdini
A simple, accessible show-and-hide/accordion script.
Stars: ✭ 148 (+543.48%)
Mutual labels:  accessibility, a11y
Accessibilitysnapshot
Easy regression testing for iOS accessibility
Stars: ✭ 236 (+926.09%)
Mutual labels:  accessibility, a11y
Visible
🦉 Accessibility testing framework at the next level
Stars: ✭ 164 (+613.04%)
Mutual labels:  accessibility, a11y
Empathy Prompts
💡 Ideas to help consider Inclusive Design principles when making things for others to use.
Stars: ✭ 173 (+652.17%)
Mutual labels:  accessibility, a11y
Vue Announcer
A simple way with Vue to announce any useful information for screen readers.
Stars: ✭ 185 (+704.35%)
Mutual labels:  accessibility, a11y
Creatability Components
Web components for making creative tools more accessible.
Stars: ✭ 248 (+978.26%)
Mutual labels:  accessibility, a11y
A11y Css Reset
A small set of global rules to make things accessible and reset default styling
Stars: ✭ 250 (+986.96%)
Mutual labels:  accessibility, a11y
Accessibility interview questions
A starting point for questions to ask someone that wants you to give them a job
Stars: ✭ 236 (+926.09%)
Mutual labels:  accessibility, a11y
Ebayui Core
Collection of Marko widgets; considered to be the core building blocks for all eBay components, pages & apps
Stars: ✭ 134 (+482.61%)
Mutual labels:  accessibility, a11y
Wai Tutorials
W3C WAI’s Web Accessibility Tutorials
Stars: ✭ 229 (+895.65%)
Mutual labels:  accessibility, a11y
Parvus
An accessible, open-source image lightbox with no dependencies.
Stars: ✭ 124 (+439.13%)
Mutual labels:  accessibility, a11y
A11y Dialog
A very lightweight and flexible accessible modal dialog script.
Stars: ✭ 1,768 (+7586.96%)
Mutual labels:  accessibility, a11y
Capable
Keep track of accessibility settings, leverage high contrast colors, and use scalable fonts to enable users with disabilities to use your app.
Stars: ✭ 189 (+721.74%)
Mutual labels:  accessibility, a11y
accessibility-resources
A curated list of accessibility resources
Stars: ✭ 66 (+186.96%)
Mutual labels:  accessibility, a11y
Eslint Plugin Jsx A11y
Static AST checker for a11y rules on JSX elements.
Stars: ✭ 2,609 (+11243.48%)
Mutual labels:  accessibility, a11y
Skin
Pure CSS framework designed & developed by eBay for a branded, e-commerce marketplace.
Stars: ✭ 126 (+447.83%)
Mutual labels:  accessibility, a11y

@vue-a11y/focus-loop


🔥 HEADS UP! You are in the Vue 2 compatible branch, check the "next" branch for Vue3 support.


Introduction

Vue component that helps you to to trap focus in an element.

When developing accessible components, in certain behaviors it is important to trap focus on the element.

For example, when opening a modal, it is recommended that the focus is only on the tabbable elements of that modal and only release the focus, when the modal is closed.

  • Focus is trapped: Tab and Shift+Tab will cycle through the focusable nodes within <FocusLoop> without returning to the main document below;
  • Automatic focus on the first focusable element, with the option to disable;
  • Restoring focus to the last activeElement;
  • Hides the document from screen readers when <focusLoop> is visible and enabled.

Installation

Add @vue-a11y/focus-loop in your Vue project.

npm install -S @vue-a11y/focus-loop
# or
yarn add @vue-a11y/focus-loop

Or via CDN

<script src="http://unpkg.com/@vue-a11y/focus-loop"></script>

Usage

You can use it globally in your main.js.

import Vue from 'vue'
import VueFocusLoop from '@vue-a11y/focus-loop'

Vue.use(VueFocusLoop)

Or you can import into your component.

import { FocusLoop } from '@vue-a11y/focus-loop'

export default {
  components: {
    FocusLoop
  }
}

Example of use on your single file component.

<template>
  <div>
    <b-button v-b-modal.modal-1>Launch demo modal</b-button>

    <b-modal id="modal-1" title="BootstrapVue">
      <FocusLoop :is-visible="isOpen">
        <b-form @submit="onSubmit" @reset="onReset" v-if="show">
          <b-form-group id="input-group-2" label="Your Name:" label-for="input-1">
            <b-form-input
              id="input-1"
              v-model="form.name"
              required
              placeholder="Enter name"
            ></b-form-input>
          </b-form-group>

          <b-form-group id="input-group-2" label="Your Email:" label-for="input-2">
            <b-form-input
              id="input-2"
              type="email"
              v-model="form.email"
              required
              placeholder="Enter email" 
            ></b-form-input>
          </b-form-group>

          <b-button type="submit" variant="primary">Submit</b-button>
          <b-button type="reset" variant="danger">Reset</b-button>
        </b-form>
      </FocusLoop>
    </b-modal>
  </div>
</template>

Make the focus-loop container visible and rendered

prop type default
isVisible Boolean false
<FocusLoop :is-visible="isOpen">
  <!-- your elements here -->
</FocusLoop>

Disable loop

You can disable the focus trap and activate it only when you really need it.

prop type default
disabled Boolean false

For example:

<FocusLoop :is-visible="isOpen" disabled>
  <!-- your elements here -->
</FocusLoop>

Disable autofocus on the first element

When activating the <FocusLoop>, the first element receives the focus automatically, however, if you want to disable this behavior, just disable it through the autoFocus prop.

prop type default
autoFocus Boolean true

For example:

<FocusLoop :is-visible="isOpen" :auto-focus="false">
  <!-- your elements here -->
</FocusLoop>

Keyboard support

Keyboard users will use Tab and Shift + Tab to navigate tabbable elements.

According to the Modal Dialog Example in WAI-ARIA Authoring Practices specification, when the focus is on the last focusable element, you must move the focus to the first element and vice versa.

Key Function
Tab ▸ Moves focus to next focusable element inside the dialog.
▸ When focus is on the last focusable element in the dialog, moves focus to the first focusable element in the dialog.
Shift + Tab ▸ Moves focus to previous focusable element inside the dialog.
▸ When focus is on the first focusable element in the dialog, moves focus to the last focusable element in the dialog.

Links

Articles that served as inspiration:

Other options

Contributing

  • From typos in documentation to coding new features;
  • Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found;
  • Fork repository, make changes and send a pull request;

Follow us on Twitter @vue_a11y

Thank you

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