npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ca11y

v1.0.0

Published

A lightweight accessible datepicker

Downloads

61

Readme

ca11y Circle CI

NPM

Stories in Ready

An accessible, light-weight, vanilla date picker < 6kb gzipped. Bring your own styles, or play off the demo.

npm install ca11y --save

This is a work in progress. Accessibility testing thus far has been through basic keyboard usage and Apple VoiceOver on OS X Safari. We would love more testing and advice from the community!

Demo Gif

http://code.viget.com/ca11y

Feedback, pull requests, bug reports and ideas for improvement. Got some? Head on over to issues.

Usage

Multiple instances by css selector:
import Ca11y from 'ca11y'
Ca11y.init('.date-picker', options)
Single input element:
import Ca11y from 'ca11y'
const input = document.getElementById('#date-input')
const datePicker = new Ca11y(input, options)

Pass any of the options listed below to override the defaults.

Styling:

Ca11y just provides the markup and functionality. You're on the hook to provide css. Feel free to use the styles from the demo as a starting point. At the very least, you'll need to something like this to hide the date-picker when inactive:

.ca11y__picker[aria-hidden="true"] {
  display: none;
}

Options

Basic

options.container

const datePicker = new Ca11y(input, {
  container: input.parentElement // default
})

The HTML element where you want the datepicker to render.

options.toggle

const datePicker = new Ca11y(input, {
  toggle: this.ui.datePicker.querySelector('.ca11y__toggle') // default (dynaically created)
})

The HTML element that should toggle datepicker when clicked. Defaults to a dynamically created button.

options.format

const datePicker = new Ca11y(input, {
  format: ['mm', 'dd', 'yyyy'] // default
})

A an Array of date codes to specify your desired format. Joined with options.delimiter.

Available formats:

key | value -----------|--------- d | Day of the month as digits; no leading zero for single-digit days. dd | Day of the month as digits; leading zero for single-digit days. ddd | Day of the week as a three-letter abbreviation. dddd | Day of the week as its full name. m | Month as digits; no leading zero for single-digit months. mm | Month as digits; leading zero for single-digit months. mmm | Month as a three-letter abbreviation. mmmm | Month as its full name. yy | Year as last two digits; leading zero for years less than 10. yyyy | Year represented by four digits.

fullName and label values are read by screen readers. Provide transitionDuration if you are using the css transition property on the .ca11y__picker element to allow auto-focusing of the selected day on transition end.

options.delimiter

const datePicker = new Ca11y(input, {
  delimiter: "/" // default
})

The String used to join the date segments defined in the options.format Array.

options.transitionDuration

const datePicker = new Ca11y(input, {
  transitionDuration: 200 // default
})

If you are transitioning open and closing the calendar with CSS, specify the transitionDuration in milliseconds here.

options.autofill

const datePicker = new Ca11y(input, {
  autofill: false // default
})

Set to true if you want a blank input to be auto-filled with today's date.

options.onSelect

const datePicker = new Ca11y(input, {
  onSelect: onSelect(value, input, state, date) {
    input.value = value
  }  // default
})

The function that runs whenever a date is selected. By default, it sets the input value to the selected date, formatted as defined by format and delimiter.

Language

options.months

const datePicker = new Ca11y(input, {
  months: [
    { fullName: 'January', displayName: 'Jan', shortName: 'Jan' },
    ...
})

An Array of objects containing the fullName, displayName, and shortName of each month. fullName is what gets read by screen readers. displayName gets rendered to the calendar, and shortName is for usage with output formats. Override with other languages or desired text.

options.days

const datePicker = new Ca11y(input, {
  days: [
    { fullName: 'Sunday', displayName: 'S', shortName: 'Sun' } ,
    ...
})

Same format as `months`. Override with other languages or desired text.

#### `options.dayTitles`
```js
const datePicker = new Ca11y(input, {
dayTitles: [
  'First',
  'Second',
  ...
})

Read aloud by screen readers when a date receives focus. Override with other languages or desired text.

options.dayTitles

const datePicker = new Ca11y(input, {
dayTitles: [
  'First',
  'Second',
  ...
})

Read aloud by screen readers when a date receives focus. Override with other languages or desired text.

UI

options.toggleIcon

const datePicker = new Ca11y(input, {
  toggleIcon: "<svg>...</svg>" // defaults to Google material calendar icon
})

The icon to be rendered as the toggle button label. Defaults to svg iconography from https://design.google.com/icons/.

options.toggleAriaLabel

const datePicker = new Ca11y(input, {
  toggleAriaLabel: "Toggle the Datepicker" // default
})

The aria-label that should be read by a screen reader when the (default) toggle button is focused.

options.next

const datePicker = new Ca11y(input, {
  next: {
    html: '<button>Next</button>',
    label: 'Next Month'
  }
})

The html will be rendered as the next month button. The label is screen-reader only. Defaults to svg iconography from https://design.google.com/icons/.

prev

const datePicker = new Ca11y(input, {
  prev: {
    html: '<button>Prev</button>',
    label: 'Previous Month'
  }
})

The html will be rendered as the previous month button. The label is screen-reader only. Defaults to svg iconography from https://design.google.com/icons/.

Advanced

parser

See default.

formatter

See default.

HTML5 Date Inputs and Ca11y

Ca11y upgrades standard text inputs to date-pickers. If you're interested in using the native HTML5 date-picker via <input type="date">, consider loading Ca11y based on a feature test, like this one (pulled from Modernizr):

function isDateInputSupported() {
    var input = document.createElement('input')
    input.setAttribute('type', 'date')
    var isDate = input.type !== 'text' && 'style' in input
    var testValue = '1)'
    if (isDate) {
        input.value = testValue
        input.style.cssText = 'position:absolute;visibility:hidden;'
        isDate = input.value != testValue
    }
    return isDate
}

Demo Locally

npm install
npm start

Deploy to GitHub Pages

npm run deploy

--

Check out other open source work happening at Viget on code.viget.com