Giter VIP home page Giter VIP logo

focusableelement's Introduction

FocusableElement

A JavaScript class that defines what's a focusable element. This program aims to simplify the rules of the digital accessibility recommendations about the keyboard navigation.

This is an independent project whose sources are my own personal knowledge and tests, at least for the moment. Therefore, if you think you can improve the project, then don't hesitate! For that, add an issue or fork.

What is a focusable element

We consider a focusable element as an interactive element which can get focus with the Tab key & be clickable with a key like Enter or Space.

The default focusable elements

The default focusable elements of HTML are:

  • <a>
  • <button>
  • <input>
  • <textarea>
  • <select>
  • <summary>

Every clickable HTML element should be one of this tag in order to simplify the keyboard navigation.

Indeed, if you use a <div> instead of a <button> in which you attach an onclick event, then this event won't be triggered with the Enter key, contrary to a <button>.

Each tag is there for a specific purpose, and should be used correctly.

However, it's possible to give the focus to any other HTML element with an attribute: tabindex.

tabindex

This attribute allows normal HTML elements to be focusable (or not). Nevertheless, this should not be used in parallel with a click event.

<div tabindex="0">
    This div is focusable.
</div>

Do not use a positive number

Also, for an element to lose the ability to get the focus, do:

<button tabindex="-1">
    I'm not focusable
</button>

... but it's still clickable, so not the best thing. For a button, use disabled to deactivate its normal behavior.

Unfocusable elements

An element is unfocusable if it has:

  • the attribute tabindex='-1'
  • the attribute disabled
  • the attribute hidden
  • the attribute type='hidden' (only for <input>)
  • the CSS property display: none;
  • the CSS property visibility: hidden;

License

MIT License.

focusableelement's People

Contributors

thomasgysemans avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.