GithubHelp home page GithubHelp logo

moxystudio / js-keyboard-only-outlines Goto Github PK

View Code? Open in Web Editor NEW
11.0 9.0 2.0 1.39 MB

Disable outlines caused by navigation methods other than keyboard

License: MIT License

JavaScript 100.00%
outline focus keyboard tab click accessibility

js-keyboard-only-outlines's Introduction

keyboard-only-outlines

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

Disable outlines displayed when using navigation methods other than keyboard navigation (e.g.: tab).

By default, some browsers, such as Firefox and Edge, set input borders on focus according to the host Operating System theme. This package does not disable borders, as it may interfere with the user's own styles. This is only apparent when users don't explicitly define a border for their inputs.

You can see it working in the demo page.

Installation

$ npm install @moxy/keyboard-only-outlines

This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.

Usage

import keyboardOnlyOutlines from '@moxy/keyboard-only-outlines'

const dispose = keyboardOnlyOutlines()
// dispose will be a function which deactivates this behaviour and can be called at any time

The function may also be invoked with the following options:

keyboardOnlyOutlines({ styles: ..., stylesheetTarget: ... })

Where styles represents the styles to apply when a focus event is caused by mouse navigation, and stylesheetTarget is the node which will receive the aforementioned style. The latter option is particularly useful when dealing with ShadowDOMs.

These options have the following default values:

const defaultOptions = {
    styles: `
*:focus {
    outline: none !important;
}
*::-moz-focus-inner {
    border: none !important;
}`,
    stylesheetTarget: document.head,
};

Tests

$ npm test
$ npm test -- --watch # during development

License

Released under the MIT License.

js-keyboard-only-outlines's People

Contributors

areadrill avatar dependabot[bot] avatar greenkeeper[bot] avatar pedromiguelss avatar satazor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-keyboard-only-outlines's Issues

Take care of special FF styles?

FF applies some weird styles on buttons and inputs:

::-moz-focus-inner  /* Weird dashed outline on the text inside the button */
:moz-focusring /* Blue thingy around the element, but it's not an outline.. it's actually a border */

Fixing ::-moz-focus-inner seems easy by setting border-style: none; in the styles. Fixing :moz-focusring is difficult because it uses border, which we can't set to none because it will remove all the borders. Note that this only happens if the user hasn't defined a border themselves. Perhaps, we shouldn't do nothing regarding this pseudostate but instead simply document it (and change our demo to have set the inputs border explicitly).

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.