Giter Site home page Giter Site logo

rikschennink / short-and-sweet Goto Github PK

View Code? Open in Web Editor NEW
277.0 5.0 10.0 272 KB

๐Ÿ“Ÿ Accessible character counter for input elements

License: MIT License

JavaScript 100.00%
character-counter textarea input accessible screenreader javascript

short-and-sweet's Introduction

Short and Sweet, Accessible Character Counter

License: MIT npm version

Tested with VoiceOver (Safari 11) & NVDA (FF 60)

  • Tells user the amount of space left when the field is focussed
  • Updates the user periodically while typing

Play around with the demo:

https://codepen.io/rikschennink/pen/LmoJYY

View a video of Short and Sweet with VoiceOver:

http://www.youtube.com/watch?v=3NDCEvHHaCY (sound is off)


Buy me a Coffee / Dev updates on Twitter


Features

  • No dependencies
  • Easy setup
  • Accessible

Installation

Install from npm:

npm install short-and-sweet --save

Or download dist/short-and-sweet.min.js and include the script on your page like shown below.

Usage

Run short-and-sweet like shown below and pass an element reference or a querySelector. For best performance include the script just before the closing </body> element.

<textarea maxlength="200"></textarea>

<script src="short-and-sweet.min.js"></script>
<script>
    shortAndSweet('textarea', {
        counterClassName: 'my-short-and-sweet-counter',
    });
</script>

The following options are available to pass to the shortAndSweet method.

Option Default Description
counterClassName 'short-and-sweet-counter' The classname of the counter element
counterLabel '{remaining} characters left' The text shown in the counter element, placeholders available are {remaining}, {maxlength}, {length}
assistDelay 2000 The time in milliseconds the assist waits before updating the user with the screenreader user with the current count
append (el, counter) => { el.parentNode.appendChild(counter); } The method used to append the element to the DOM

Tested

  • Modern browsers
  • VoiceOver + Safari
  • NVDA + Firefox
  • IE 10+

Versioning

Versioning follows Semver.

License

MIT

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.