Git Product home page Git Product logo

duetds / date-picker Goto Github PK

View Code? Open in Web Editor NEW
1.7K 20.0 69.0 2.41 MB

Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Try live example at https://duetds.github.io/date-picker/

Home Page: https://www.duetds.com

License: MIT License

JavaScript 1.99% TypeScript 71.86% CSS 0.80% HTML 16.02% SCSS 9.33%
javascript javascript-library web-component webcomponent date-picker datepicker calendar-component calendar-widget datepicker-component stenciljs

date-picker's Introduction

CI Status NPM Version MIT License code style: prettier

Duet Date Picker

Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Duet Date Picker can be implemented and used across any JavaScript framework or no framework at all. We accomplish this by using standardized web platform APIs and Web Components.

Why yet another date picker? Our team working on Duet Design System couldn’t find an existing date picker that would’ve ticked all the requirements we had for accessibility (supporting WCAG 2.1 as well as we can), so we decided to build one and open source it so that others could benefit from this work as well.

Duet Date Picker comes with built-in functionality that allows you to set a minimum and a maximum allowed date. These settings can be combined or used alone, depending on the need. Please note that the date values must be passed in IS0-8601 format: YYYY-MM-DD.

Read getting started instructions ›
Learn more about Duet ›

Duet Date Picker

Live demo

Features

  • Can be used with any JavaScript framework.
  • No external dependencies.
  • Weighs only ~10kb minified and Gzip’ed (this includes all styles and icons).
  • Built with accessibility in mind.
  • Supports all modern browsers and screen readers.
  • Additionally, limited support offered for IE11 and Edge 17+.
  • Allows theming using CSS Custom Properties.
  • Support for localization.
  • Customizable date parsing and formatting.
  • Support for changing the first day of the week.
  • Comes with modified interface for mobile devices to provide better user experience.
  • Supports touch gestures for changing months and closing the picker.
  • Built using Stencil.js and Web Components.
  • Free to use under the MIT license.

Browser support

  • Google Chrome 61+
  • Apple Safari 10+
  • Firefox 63+
  • Microsoft Edge 17+
  • Opera 63+
  • Samsung Browser 8.2+
  • Internet Explorer 11

Screen Reader support

We offer support for the following screen readers. For more information about the level of support and possible issues with the implementation, please refer to the included accessibility audit.

  • VoiceOver on macOS and iOS
  • TalkBack on Android
  • NVDA on Windows
  • Jaws on Windows

Keyboard support

Duet Date Picker’s keyboard support is built to closely follow W3C Date Picker Dialog example with some small exceptions to e.g. better support iOS VoiceOver and Android TalkBack.

Choose date button

  • Space, Enter: Opens the date picker dialog and moves focus to the first select menu in the dialog.

Date picker dialog

  • Esc: Closes the date picker dialog and moves focus back to the “choose date” button.
  • Tab: Moves focus to the next element in the dialog. Please note since the calendar uses role="grid", only one button in the calendar grid is in the tab sequence. Additionally, if focus is on the last focusable element, focus is next moved back to the first focusable element inside the date picker dialog.
  • Shift + Tab: Same as above, but in reverse order.

Date picker dialog: Month/year buttons

  • Space, Enter: Changes the month and/or year displayed.

Date picker dialog: Date grid

  • Space, Enter: Selects a date, closes the dialog, and moves focus back to the “Choose Date” button. Additionally updates the value of the Duet Date Picker input with the selected date, and adds selected date to “Choose Date” button label.
  • Arrow up: Moves focus to the same day of the previous week.
  • Arrow down: Moves focus to the same day of the next week.
  • Arrow right: Moves focus to the next day.
  • Arrow left: Moves focus to the previous day.
  • Home: Moves focus to the first day (e.g Monday) of the current week.
  • End: Moves focus to the last day (e.g. Sunday) of the current week.
  • Page Up: Changes the grid of dates to the previous month and sets focus on the same day of the same week.
  • Shift + Page Up: Changes the grid of dates to the previous year and sets focus on the same day of the same week.
  • Page Down: Changes the grid of dates to the next month and sets focus on the same day of the same week.
  • Shift + Page Down: Changes the grid of dates to the next year and sets focus on the same day of the same week.

Date picker dialog: Close button

  • Space, Enter: Closes the dialog, moves focus to “choose date” button, but does not update the date in input.

Getting started

Integrating Duet Date Picker to a project without a JavaScript framework is very straight forward. If you’re working on a simple HTML page, you can start using Duet Date Picker immediately by adding these tags to the <head>:

<script type="module" src="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/duet.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/duet.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/themes/default.css" />

Once included, Duet Date Picker can be used in your markup like any other regular HTML element:

<label for="date">Choose a date</label>
<duet-date-picker identifier="date"></duet-date-picker>

Please note: Importing the CSS file is optional and only needed if you’re planning on using the default theme. See theming section for more information. Additionally, while the above method is the easiest and fastest way to get started, you can also install Duet Date Picker via NPM. Scroll down for the installation instructions.

Properties

Property Attribute Description Type Default
dateAdapter -- Date adapter, for custom parsing/formatting. Must be object with a parse function which accepts a string and returns a Date, and a format function which accepts a Date and returns a string. Default is IS0-8601 parsing and formatting. DuetDateAdapter isoAdapter
direction direction Forces the opening direction of the calendar modal to be always left or right. This setting can be useful when the input is smaller than the opening date picker would be as by default the picker always opens towards right. "left" | "right" "right"
disabled disabled Makes the date picker input component disabled. This prevents users from being able to interact with the input, and conveys its inactive state to assistive technologies. boolean false
firstDayOfWeek first-day-of-week Which day is considered first day of the week? 0 for Sunday, 1 for Monday, etc. Default is Monday. DaysOfWeek.Friday | DaysOfWeek.Monday | DaysOfWeek.Saturday | DaysOfWeek.Sunday | DaysOfWeek.Thursday | DaysOfWeek.Tuesday | DaysOfWeek.Wednesday DaysOfWeek.Monday
identifier identifier Adds a unique identifier for the date picker input. Use this instead of html id attribute. string ""
localization -- Button labels, day names, month names, etc, used for localization. Default is English. { buttonLabel: string; placeholder: string; selectedDateMessage: string; prevMonthLabel: string; nextMonthLabel: string; monthSelectLabel: string; yearSelectLabel: string; closeLabel: string; calendarHeading: string; dayNames: DayNames; monthNames: MonthsNames; monthNamesShort: MonthsNames; } defaultLocalization
max max Maximum date allowed to be picked. Must be in IS0-8601 format: YYYY-MM-DD. This setting can be used alone or together with the min property. string ""
min min Minimum date allowed to be picked. Must be in IS0-8601 format: YYYY-MM-DD. This setting can be used alone or together with the max property. string ""
name name Name of the date picker input. string "date"
role role Defines a specific role attribute for the date picker input. string undefined
required required Should the input be marked as required? boolean false
value value Date value. Must be in IS0-8601 format: YYYY-MM-DD. string ""

Events

Event Description Type
duetBlur Event emitted the date picker input is blurred. CustomEvent<{ component: "duet-date-picker"; }>
duetChange Event emitted when a date is selected. CustomEvent<{ component: "duet-date-picker"; valueAsDate: Date; value: string; }>
duetFocus Event emitted the date picker input is focused. CustomEvent<{ component: "duet-date-picker"; }>
duetOpen Event emitted when the date picker modal is opened. CustomEvent<{ component: "duet-date-picker"; }>
duetClose Event emitted the date picker modal is closed. CustomEvent<{ component: "duet-date-picker"; }>

Methods

hide(moveFocusToButton?: boolean) => Promise<void>

Hide the calendar modal. Set moveFocusToButton to false to prevent focus returning to the date picker's button. Default is true.

Returns

Type: Promise<void>

setFocus() => Promise<void>

Sets focus on the date picker's input. Use this method instead of the global focus().

Returns

Type: Promise<void>

show() => Promise<void>

Show the calendar modal, moving focus to the calendar inside.

Returns

Type: Promise<void>

Installation

Before moving further, please make sure you have Node.js installed on your machine. You can install the latest version through their website. If you’re planning on using Duet Date Picker in a project that doesn’t yet use Node Package Manager, you’ll have to first create a package.json file. To do so, run npm init and follow the steps provided.

Once finished, you can install Duet Date Picker by running:

# WEB COMPONENT for HTML, Ember, Vue.js, React, Angular and Vanilla JS:
npm install @duetds/date-picker

Usage with basic HTML

Please note: We recommend the usage of CDN like JSDelivr over the below approach if you’re not server side rendering Duet Date Picker. See getting started section to find the correct script tags.

Once you’ve installed @duetds/date-picker package into your project, it’s recommended to create a copy task that copies Duet Date Picker component from node_modules to a location you’ve specified. One such tool that can do this is NCP. You can install ncp by running:

npm install ncp --save-dev

Once installed, add a script to your package.json that copies the component library from Duet’s package into a location you’ve specified:

"scripts": {
  "copy:duet-date-picker": "ncp node_modules/@duetds/date-picker/dist src/SPECIFY_PATH"
}

You can call this script while starting up your app to make sure you’ve always got the latest code copied over. If you’re using an UNIX-like environment, you can use & as the separator:

"start": "copy:duet-date-picker & dev"

Otherwise, if you need a cross-platform solution, use npm-run-all module:

"start": "npm-run-all copy:duet-date-picker dev"

Once you have a copy task in place and have copied Duet Date Picker over, you can put tags similar to these in the <head> of your index.html (importing the CSS file is optional and only needed if you’re planning on using the default theme. See theming section for more information):

<script type="module" src="SPECIFY_YOUR_PATH/duet.esm.js"></script>
<script nomodule src="SPECIFY_YOUR_PATH/duet.js"></script>
<link rel="stylesheet" href="SPECIFY_YOUR_PATH/duet.css" />

Once included, Duet Date Picker can be used in your basic HTML markup as in the following example:

<label for="date">Choose a date</label>
<duet-date-picker identifier="date"></duet-date-picker>

To know when this tag name becomes defined, you can use window.customElements.whenDefined(). It returns a Promise that resolves when the element becomes defined:

customElements.whenDefined("duet-date-picker").then(() => {
  document.querySelector("duet-date-picker").show()
});

Usage with Angular

Before you can use Duet Date Picker in Angular, you must import and add Angular’s CUSTOM_ELEMENTS_SCHEMA. This allows the use of Web Components in HTML markup, without the compiler producing errors. The CUSTOM_ELEMENTS_SCHEMA needs to be included in any module that uses custom elements. Typically, this can be added to AppModule:

// ...
// Import custom elements schema
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";

@NgModule({
  // ...
  // Add custom elements schema to NgModule
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }

The final step is to load and register Duet Date Picker in the browser. @duetds/date-picker includes a main function that handles this. That function is called defineCustomElements() and it needs to be called once during the bootstrapping of your application. One convenient place to do this is in main.ts as such:

// Import Duet Date Picker
import { defineCustomElements } from "@duetds/date-picker/dist/loader";
// ...
// Register Duet Date Picker
defineCustomElements(window);

Once included, Duet Date Picker can be used in your HTML markup as in the following example:

<label for="date">Choose a date</label>
<duet-date-picker identifier="date"></duet-date-picker>

Please note that you need to also import duet.css separately if you want to use the default theme. See theming section for more information.

Accessing using ViewChild and ViewChildren

Once included, components could also be referenced in your code using ViewChild and ViewChildren as shown in the Stencil.js documentation.

Usage with Vue.js

To integrate @duetds/date-picker into a Vue.js application, edit src/main.js to include:

// Import Duet Date Picker
import { defineCustomElements } from "@duetds/date-picker/dist/loader";

// ...
// configure Vue.js to ignore Duet Date Picker
Vue.config.ignoredElements = [/duet-\w*/];

// Register Duet Date Picker
defineCustomElements(window);

new Vue({
    render: h => h(App)
}).$mount("#app");

Once included, Duet Date Picker can be used in your HTML markup as in the following example:

<template>
  <label for="date">Choose a date</label>
  <duet-date-picker
    identifier="date"
    :localization.prop="localisation_uk">
  </duet-date-picker>
</template>

<script>
  const localisation_uk = {
    buttonLabel: 'Choose date',
    placeholder: 'DD/MM/YYYY',
    selectedDateMessage: 'Selected date is',
    prevMonthLabel: 'Previous month',
    nextMonthLabel: 'Next month',
    monthSelectLabel: 'Month',
    yearSelectLabel: 'Year',
    closeLabel: 'Close window',
    calendarHeading: 'Choose a date',
    dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  }
</script>

Please note that you need to also import duet.css separately if you want to use the default theme. See theming section for more information.

Please also note that in order to use duet-date-picker's own custom properties (as seen on the properties section), vue must recognise that such options are being passed down as properties rather than attributes, hence the .prop at the end.

Usage with React

With an application built using the create-react-app script the easiest way to include Duet Date Picker is to call defineCustomElements(window) from the index.js file:

// Import Duet Date Picker
import { defineCustomElements } from "@duetds/date-picker/dist/loader";

// ...
// Register Duet Date Picker
defineCustomElements(window);

Then you can create a thin React wrapper component to handle listening for events, cleanup, passing properties etc:

import React, { useEffect, useRef } from "react";

function useListener(ref, eventName, handler) {
  useEffect(() => {
    if (ref.current) {
      const element = ref.current;
      element.addEventListener(eventName, handler)
      return () => element.removeEventListener(eventName, handler)
    }
  }, [eventName, handler, ref])
}

export function DatePicker({
  onChange,
  onFocus,
  onBlur,
  onOpen,
  onClose,
  dateAdapter,
  localization,
  ...props
}) {
  const ref = useRef(null)

  useListener(ref, "duetChange", onChange)
  useListener(ref, "duetFocus", onFocus)
  useListener(ref, "duetBlur", onBlur)
  useListener(ref, "duetOpen", onOpen)
  useListener(ref, "duetClose", onClose)

  useEffect(() => {
    ref.current.localization = localization
    ref.current.dateAdapter = dateAdapter
  }, [localization, dateAdapter])

  return <duet-date-picker ref={ref} {...props}></duet-date-picker>
}

Then the wrapper can be used like any other React component:

<DatePicker
  value="2020-08-24"
  onChange={e => console.log(e.detail)}
/>

Please note that you need to also import duet.css separately if you want to use the default theme. See theming section for more information.

Usage with Ember

Duet Date Picker can be easily integrated into Ember thanks to the ember-cli-stencil addon that handles:

  • Importing the required files into your vendor.js
  • Copying the component definitions into your assets directory
  • Optionally generating a wrapper component for improved compatibility with older Ember versions

Start by installing the Ember addon:

ember install ember-cli-stencil ember-auto-import

When you build your application, Stencil collections in your dependencies will be automatically discovered and pulled into your application. You might get a Can't resolve error when building. The easiest way to resolve that issue is by adding an alias to your ember-cli-build.js file.

	autoImport: {
		alias: {
			'@duetds/date-picker/loader':  '@duetds/date-picker/dist/loader/index.cjs',
		},
	},

For more information, see ember-cli-stencil documentation.

Ember octane example:

<label  for="date">Choose a date.</label>
<duet-date-picker identifier="date" {{prop localization=this.localization}} ></duet-date-picker>
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";

export default class ExampleController extends Controller {
  @tracked localization = {
    buttonLabel: "Choose date",
    placeholder: "mm/dd/yyyy",
    selectedDateMessage: "Selected date is",
    prevMonthLabel: "Previous month",
    nextMonthLabel: "Next month",
    monthSelectLabel: "Month",
    yearSelectLabel: "Year",
    closeLabel: "Close window",
    calendarHeading: "Choose a date",
    dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
    monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
    monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  };
}

IE11 and Edge 17/18 polyfills

If you want the Duet Date Picker custom element to work on older browser, you need to add the applyPolyfills() that surround the defineCustomElements() function:

import { applyPolyfills, defineCustomElements } from "@duetds/date-picker/lib/loader";
// ...
applyPolyfills().then(() => {
  defineCustomElements(window)
})

Using events

We encourage the use of DOM events, but additionally provide custom events to make handling of certain event types easier. All custom events are documented in this same readme under the “Events” heading.

Duet Date Picker provides e.g. a custom event called duetChange. This custom event includes an object called detail which includes for example the selected date:

// Select the date picker component
const date = document.querySelector("duet-date-picker")

// Listen for when date is selected
date.addEventListener("duetChange", function(e) {
  console.log("selected date", e.detail.valueAsDate)
})

The console output for the above code looks like this:

selected date Sat Aug 15 2020 00:00:00 GMT+0300 (Eastern European Summer Time)

Theming

Duet Date Picker uses CSS Custom Properties to make it easy to theme the picker. The component ships with a default theme that you can import either from the NPM package or directly from a CDN like JSDelivr:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/themes/default.css" />

The above CSS file provides the following Custom Properties that you can override with your own properties:

:root {
  --duet-color-primary: #005fcc;
  --duet-color-text: #333;
  --duet-color-text-active: #fff;
  --duet-color-placeholder: #666;
  --duet-color-button: #f5f5f5;
  --duet-color-surface: #fff;
  --duet-color-overlay: rgba(0, 0, 0, 0.8);
  --duet-color-border: #333;

  --duet-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --duet-font-normal: 400;
  --duet-font-bold: 600;

  --duet-radius: 4px;
  --duet-z-index: 600;
}

If you wish to customize any of the default properties shown above, we recommend to NOT import or link to the provided CSS, but instead copying the above code into your own stylesheet and replacing the values used there.

Additionally, you’re able to override Duet Date Picker’s default styles by using e.g. .duet-date__input selector in your own stylesheet. This allows you to give the form input and e.g. date picker toggle button a visual look that matches the rest of your website.

Localization

Duet Date Picker offers full support for localization. This includes the text labels and date formats used. Below is an example of a date picker that is using Finnish date format and localization.

<label for="date">Valitse päivämäärä</label>
<duet-date-picker identifier="date"></duet-date-picker>

<script>
  const picker = document.querySelector("duet-date-picker")
  const DATE_FORMAT = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/

  picker.dateAdapter = {
    parse(value = "", createDate) {
      const matches = value.match(DATE_FORMAT)

      if (matches) {
        return createDate(matches[3], matches[2], matches[1])
      }
    },
    format(date) {
      return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`
    },
  }

  picker.localization = {
    buttonLabel: "Valitse päivämäärä",
    placeholder: "pp.kk.vvvv",
    selectedDateMessage: "Valittu päivämäärä on",
    prevMonthLabel: "Edellinen kuukausi",
    nextMonthLabel: "Seuraava kuukausi",
    monthSelectLabel: "Kuukausi",
    yearSelectLabel: "Vuosi",
    closeLabel: "Sulje ikkuna",
    calendarHeading: "Valitse päivämäärä",
    dayNames: [
      "Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko",
      "Torstai", "Perjantai", "Lauantai"
    ],
    monthNames: [
      "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu",
      "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu",
      "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu"
    ],
    monthNamesShort: [
      "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä",
      "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu"
    ],
    locale: "fi-FI",
  }
</script>

Please note that you must provide the entirety of the localization properties in the object when overriding with your custom localization.

Control which days are selectable

Duet Date Picker allows you to disable the selection of specific days. Below is an example of a date picker that is disabling weekends.

Be aware, this only disables selection of dates in the popup calendar. You must still handle the case where a user manually enters a disallowed date into the input.

<label for="date">Choose a date</label>
<duet-date-picker identifier="date"></duet-date-picker>

<script>
  function isWeekend(date) {
    return date.getDay() === 0 || date.getDay() === 6
  }

  const pickerDisableWeekend = document.querySelector("duet-date-picker")
  pickerDisableWeekend.isDateDisabled = isWeekend

  pickerDisableWeekend.addEventListener("duetChange", function(e) {
    if (isWeekend(e.detail.valueAsDate)) {
      alert("Please select a weekday")
    }
  })
</script>

Server side rendering

Duet Date Picker package includes a hydrate app that is a bundle of the same components, but compiled so that they can be hydrated on a NodeJS server and generate static HTML and CSS. To get started, import the hydrate app into your server’s code like so:

import hydrate from "@duetds/date-picker/hydrate"

If you are using for example Eleventy, you could now add a transform into .eleventy.js configuration file that takes content as an input and processes it using Duet’s hydrate app:

eleventyConfig.addTransform("hydrate", async(content, outputPath) => {
  if (process.env.ELEVENTY_ENV == "production") {
    if (outputPath.endsWith(".html")) {
      try {
        const results = await hydrate.renderToString(content, {
          clientHydrateAnnotations: true,
          removeScripts: false,
          removeUnusedStyles: false
        })
        return results.html
      } catch (error) {
        return error
      }
    }
  }
  return content
})

The above transform gives you server side rendered components that function without JavaScript. Please note that you need to separately pre-render the content for each theme you want to support.

Single file bundle

Duet Date Picker also offers a single file bundle without the polyfills and other additional functionality included in the default output. To import that instead of the default output, use:

import { DuetDatePicker } from "@duetds/date-picker/custom-element";

customElements.define("duet-date-picker", DuetDatePicker);

Please note that this custom-element output does not automatically define the custom elements or apply any polyfills which is why we’re defining the custom element above ourselves.

For more details, please see Stencil.js documentation.

Optimizing CDN performance

If you wish to make sure Duet Date Picker shows up as quickly as possible when loading the scripts from JSDelivr CDN, you can preload the key parts using link rel="preload". To do this, add these tags in the <head> of your webpage before any other <script> or <link> tags:

<link rel="preload" href="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/duet.esm.js" as="script" crossorigin="anonymous" />
<link rel="preload" href="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/duet-date-picker.entry.js" as="script" crossorigin="anonymous" />

In case you’re also using one of the included themes, you can preload them the same way using the below tag:

<link rel="preload" href="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/themes/default.css" as="style" />

Contributing

Development server

  • Clone the repository by running git clone [email protected]:duetds/duet-date-picker.git.
  • Once cloned, open the directory and run npm install.
  • Run npm start to get the development server and watch tasks up and running. This will also automatically open a new browser window with an example page.
  • To edit the example page’s source, see ./src/index.html.

Testing and building

  • To run the unit, end-to-end and visual diff tests use npm run test.
  • To build the project use npm run build.

Publishing the package

NOTE: this section is for maintainers and can be ignored by contributors.

The process for publishing a stable or a beta release differs.

To publish a new stable release, use the npm version command. The npm docs for the version command explains in detail how this command works.

E.g. to publish a new minor version:

npm version minor

This will run tests, build the project, bump the minor version in package.json, commit and tag the changes, publish to npm, and finally push any commits to github.

To publish a new beta release, do the following:

  1. Bump version in package.json and elsewhere.
  2. Commit your changes.
  3. Tag new release by running git tag -a 1.2.0-beta.0 -m "1.2.0-beta.0".
  4. Push your changes to Git and then run npm publish --tag beta.
  5. Push to git: git push --tags --no-verify.

Changelog

  • 1.4.0:
    • Add support for disabling arbitrary dates in the calendar via isDateDisabled prop (#52 and #80).
    • Disable month options in dropdown that would fall outside of min/max (#82).
    • Drop keyboardInstruction text - it is redundant since we now use a standard <table> element. (#87).
  • 1.3.0:
    • Add new theme variable --duet-border-color for customising the input's border color. Falls back to previous value --duet-color-text if not set (#70).
    • Improve handling of disallowed characters so that cursor position is maintained.
    • Add new duetOpen and duetClose events to correspond with opening and closing the calendar (#73).
    • Fix click outside logic so that it works when nested in a shadow DOM (#65).
  • 1.2.0:
    • Improvements to screen reader accessibility.
      • Ensure table can be navigated with table navigation commands.
      • Ensure column headers are announced out when navigating table columns.
      • Ensure month/year is announced whenever it changes.
      • Improve how dates are presented to screen readers. Use formats like "17 November 2020" instead of "2020-11-17".
    • Year dropdown now shows every year that satisfies min/max range.
  • 1.1.0: Adds support for required attribute. Ensures date is always submitted in ISO format. Updates @stencil/core to 2.3.0.
  • 1.0.4: Improves stability for NVDA + Chrome on Windows. Also fixes an issue which caused build attempts to fail due to snapshot mismatch.
  • 1.0.2: Documentation improvements.
  • 1.0.1: Hitting arrow keys on year select on Windows without first opening the dropdown previously causes odd results. This is now fixed.
  • 1.0.0: Initial release.

Roadmap

  • Better examples on how to do date ranges, handle validation and so on.
  • Better theming and basic code examples.
  • Making it possible to pass in your own input component.

License

Copyright © 2020 LocalTapiola Services Ltd / Duet Design System.

Licensed under the MIT license.

date-picker's People

Contributors

aatauil avatar arielsalminen avatar bseber avatar chardin1 avatar dmitriid avatar dsappet avatar duetbot avatar jonnystening avatar klh avatar richiemccoll avatar timgates42 avatar wickynilliams avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

date-picker's Issues

Windows: hitting arrow keys on year select without first opening dropdown causes odd results

Describe the bug
On windows, if you do not open the year dropdown but use arrows keys, the selected year jumps around by more than one year at a time.

To Reproduce
Steps to reproduce the behavior:

  1. open calendar
  2. tab to year dropdown
  3. hit up/down keys
  4. observe undesirable behaviour:
Start -> 2020
Down -> 2021 (+1)
Down -> 2023 (+2)
Down -> 2026 (+3)
Up -> 2028 (+2)
Up -> 2029 (+1)
Up -> 2029 (+0)
Up -> 2028 (-1)
Up -> 2026 (-2)
Down -> 2025 (-1)

Expected behavior
Years increment/decrement one year at a time

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Edge
  • Version: 85.0.564.51

ESM build is empty

Describe the bug

@duetds/date-picker’s ESM build is currently broken.

To Reproduce

If you inspect the package.json, the "module" entrypoint is set to ./dist/index.js. This is its contents:

export * from './esm-es5/index.js';

If you navigate to ./esm-es5/index.js, though, it is blank. As a result, the ESM build of @duetds/date-picker is empty.

I made a reproduction using Snowpack, an ESM installer.

Expected behavior
The "module" entrypoint of the package should export the expected code.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Any
  • Browser: Any
  • Version: Any

Smartphone (please complete the following information):

  • Device: Any
  • OS: Any
  • Browser: Any
  • Version: Any

Additional context

Not a part of this issue at all, but it’d also be great if @duetds/date-picker could add an export map as part of its package contents. This would help the ESM be further-optimized.

Screen Reader Table Navigation Broken

Describe the bug
The calendar grid identifies as a table/grid to my screen reader, but drops me into a mode where arrow keys choose between dates instead of letting me move word-by-word or character-by-character. If I use table navigation (Ctrl + Alt + arrow keys in JAWS), every cell reports as the end of the row or column.

If I back out of the grid and press T to access it as a table, I can at least navigate the header row (the days of the week) with table navigation, but I cannot get into the grid of dates.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the grid,
  2. Use Ctrl + Alt + arrow keys to move within the grid,
  3. Observe it says "end of row" or "bottom of column" or similar;
  4. Press Shift + Tab to back out of the grid,
  5. Press T to move to the table,
  6. Use Ctrl + Alt + down arrow to move into days,
  7. Observe it says "bottom of column".

Expected behavior
I should be able to navigate the entire calendar grid using my screen reader's table navigation controls.

Screenshots
I made a video, but GitHub does not allow me to embed it.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 85
  • JAWS 2020

Additional context
Using first example at https://duetds.github.io/date-picker/

Day of week should be announced to screen readers when navigating the calendar

Is your feature request related to a problem? Please describe.
Currently the days of the week aren't announced by a screen reader when navigating the calendar. The <table> structure is correct, so presumably this is due to the use of grid + gridcell roles. Whatever the cause, the result is that screen reader users don't know what day of the week their currently-focused date is.

Describe the solution you'd like
Simplest solution would be to append or prepend the day of the week to the hidden text in each button, i.e.:

<span class="duet-date__vhidden">Thursday, 2020-09-24</span>

This could be done with Date.toLocaleDateString() to support internationalization.

Describe alternatives you've considered
The only alternative I can think of would be to drop the use of grid and just use a plain table, but this doesn't seem like a good solution—it would mean sighted keyboard users would be forced to TAB through the calendar instead of using arrow keys.

Additional context
Tested with JAWS, NVDA and MacOS Voiceover.

input control's value never gets updated unless 10 or 0 characters long

Describe the bug
Hi, I'm noticing that the input control never registers the value has been changed unless the input value is 0 or 10 characters (e.g. a date 2002-02-02) in length.

If it's 2002-02-0 it will not update the value.

But if you change 2002-02-0 to 2002-02-02 it will update the value, or if you change "2" to "".

To Reproduce
Steps to reproduce the behavior:

  1. Go to date control

  2. input 2002-02-02

  3. change it to 2002-02-0

  4. look for the form value to change, doesn't change

  5. Go to date control

  6. input 2002-00

  7. change it to 2002-02-02

  8. look for the form value to change, it will only change when you enter 2002-02-02

Expected behavior
Every time you change the value the input control's value should change.

Screenshots
Screen Shot 2020-12-03 at 3 07 04 PM
Screen Shot 2020-12-03 at 3 14 13 PM

editing in the middle of the text moves cursor to end (in Safari)

Describe the bug

When the cursor is in the middle of the text, and you type, the cursor jumps to the end. This is likely because of setting the value without changing the "selection"

To Reproduce
Steps to reproduce the behavior:

  1. type part of a date
  2. move your cursor to somewhere inside the text
  3. type something
  4. see cursor jump to the end

Expected behavior

cursor stays where you enter text

Screenshots

2020-09-18 14-07-12 2020-09-18 14_08_12

Desktop (please complete the following information):

  • OS: macOS 10.14
  • Browser: Safari Tech Preview
  • Version: Release 113 (Safari 14.0.1, WebKit 15610.2.3.1)

Additional context

I've seen this problem before, in e.g.:

Expand CSS variables

Is your feature request related to a problem? Please describe.

Some of the colors are re-used and may/will lead to difficulties when customising inputs. Specifically, borders:

.duet-date__input {
    border: 1px solid var(--duet-color-text);
    border-radius: var(--duet-radius);
    color: var(--duet-color-text);
}

Describe the solution you'd like

Add a new variable, --duet-color-border. To maintain backards compatibility, it can fall back:

border: 1px solid var(--duet-color-border, var(--duet-border-text))

Additional context

See why here (duetds among material ui fields)

Screenshot 2020-10-30 at 14 43 22


By the way, the picker is amazing 🎉

Live Region Not Announced

Describe the bug
I discovered a live region in the code:

<div class="duet-date__vhidden duet-date__instructions" aria-live="polite">You can use arrow keys to navigate dates</div>

However when I access the control I do not hear the live region announced.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the grid,
  2. Interact with it (typing a date, opening the calendar, navigation it, choosing one, etc),
  3. Observe the screen reader does not announce the content from the live region.

Expected behavior
I expect to hear the live region.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 85
  • JAWS 2020

Additional context
Using first example at https://duetds.github.io/date-picker/

can we have a custom mobile view threshold?

The default screen width threshold that puts the calendar in mobile view is currently 39rem. My website has different mobile threshold. Can we make the calendar go into mobile view at a custom screen width?

Provide a way to disable days per week or dates.

Is your feature request related to a problem? Please describe.
Using our current date picker doesn't offer a fully disabled state, which makes this one attractive, but we need to be able to disable specific days per week and dates as well.

Describe the solution you'd like
It'd be helpful to be able to select specific days of the week to disable, as well as pass in an array of dates to disable.

Describe alternatives you've considered
N/A

Additional context
The calendar we're currently using is flatpickr, which allows us to disable entire days from each week (i.e.: Mondays, Wednesdays, Fridays) and specific dates (i.e.: Dates that have already been booked, or closed holidays)

NVDA reads the placeholder letter by letter

Describe the bug

NVDA reads the placeholder as "Y Y Y Y M M D D".
It is not pleasant or helpful for the user.
Please put the format in the label along with a more clear readout.

By the way:
Why is there a placeholder?
I mean, it's the date picker's job to populate with the correct format when we choose date from the date picker.
Right?

Desktop (please complete the following information):

  • OS: Win10
  • Chrome with NVDA

Working without JS

Is your feature request related to a problem? Please describe.
When JS is disabled, it doesn't work

Describe the solution you'd like
This should be a native datePicker, till it can be enhanced by JS.

Navigating the dates with arrow keys

Describe the bug
I expected to be able to use all arrow keys to navigate within the dates.
Only up key and down key work fine.
The left key and right key will read out a digit, one digit at a time.
This is confusing for the user.

Using Win 10 with NVDA.

localized date incorrectly submitted as part of <form>

I am trying to use duet-date-picker with Thymeleaf (server-side rendering). It works as long as I don't use the localization support.

I added this in a <script> tag in my page:

    const picker = document.querySelector('duet-date-picker');
    const DATE_FORMAT = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/;

    if (picker) {
        picker.dateAdapter = {
            parse(value = '', createDate) {
                try {
                    console.log('parsing' + value);
                    const matches = value.match(DATE_FORMAT);

                    if (matches) {
                        return createDate(matches[3], matches[2], matches[1]);
                    }
                } catch (err) {
                    console.log(err);
                }
            },
            format(date) {
                console.log('formatting: ' + date);
                return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
            },
        };
    }

I see lot's of formatting... statements, but never parsing... and also no error in the console.

When I check with dev tools, I see updates to the value attribute of <duet-date-picker>, but the value of the actual <input> is not updated. Due to this, my server-side thinks that nothing was selected. For some reason, that does not seem to be an issue when not using the localization support. Am I doing something wrong?

Interactions do not work within a shadow DOM

Describe the bug
When placing the component within a shadow DOM, the calendar month and year controls immediately close the calendar popup. Specifically, the month forward/back buttons as well as selecting a value in the month or year menus cause this unexpected closing.

To Reproduce
Steps to reproduce the behavior:
I've created an example codepen. It creates a very simple web component with shadow dom and places a plain date picker within

  1. Go to https://codepen.io/geekify/pen/QWKerQG
  2. Click on the icon to bring up the calendar
  3. Notice, clicking on a date on the calendar will work, however ...
  4. Clicking on the forward or back button, or selecting a value in any dropdown closes the calendar popup and does nothing

Expected behavior
The calendar popup should NOT collapse when interacting with month and year controls

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac OS
  • Browser: Firefox, Safari, Chrome. (Safari - the menus work but not the forward / back)

Additional context
I originally noticed this issue in StencilJS, I narrowed down a few things and found that it was shadow dom related so the sample codepen should be the simplest example.

Enhance year display when min and max are used

Hello!

Thanks for this project, the picker is really great.

I would like to propose an enhancement to it regarding the display of the year list when range values are used.

The use case is as follows:

  • using the picker to pick a birth date within a range of acceptable values (say 1920-2020).
  • year list only display 20 entries at a time. To display more I need to select the first one, close the list and then open it again. So the user could easily do this multiple times if she is born in 1954 for example. Which is not quite straightforward and a bit tedious for some users.

To enhance this behaviour, the picker could display all the years within the range only when range values are set (either min, max or both).

Thanks again for this great project!

Formatting date value as entered

Hi, is it possible to format the date when entering it in the text box or should you be only changing the date via the control?

date not showing with these examples

Hi, any idea why the date control is not showing a value with these dates:

2019-11-14T00:55:31.820Z
2020-11-25T15:18:15Z
2020-11-25T15:18:15+00:00
2002-02-02T00:00:00.000Z

Here's how I've added the control,

      <duet-date-picker
        :id="inputId"
        type="text"
        :value="value"
        v-on="maskedInputEvents()"
        :localization.prop="localization()"
      />

here's the localization & maskedInputEvents function

  public localization(): any {
    return {
      buttonLabel: "Choose date",
      placeholder: "YYYY-MM-DD",
      selectedDateMessage: "Selected date is",
      prevMonthLabel: "Previous month",
      nextMonthLabel: "Next month",
      monthSelectLabel: "Month",
      yearSelectLabel: "Year",
      closeLabel: "Close window",
      keyboardInstruction: "You can use arrow keys to navigate dates",
      calendarHeading: "Choose a date",
      dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
      monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
      monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
    };
  }

  public maskedInputEvents(): any {
    const _vm = this as DateInput;
    return Object.assign({},
      // parent listeners
      this.$listeners,
      {
        // custom listeners
        input(event: any) {
          // Emit updated value
          _vm.$emit('input', event.target.value);
        },
        duetBlur(event: any) {
          const value = _vm.value;
          const matches = value ? value.match(/^(\d{0,4})(\d{0,2})(\d{0,2})$/) : value;
          if (value && matches) {
            _vm.$emit('input', `${matches[1]}-${matches[2]}-${matches[3]}`);
          } else {
            _vm.$emit('input', value);  
          }
        },
        duetChange(event: any) {
          // Emit updated value
          _vm.$emit('input', event.detail.value.length > 0 ? event.detail.value : undefined);
        }
      }
    );
  }

Screen Shot 2020-11-25 at 10 35 16 AM

It does work with 2019-11-14

Any ideas what could be wrong here?

Allow customization of valid characters when typing

Using the localization support, you can write a custom parse and format function. However, when the format you want to use has a space, the user cannot type that space in the input field.

For example, when using Luxon, one of the default formats is 1 okt. 2020.

Also, suppose the format is dd.mm.yyyy, then maybe you don't want to allow users to type / or - which are currently possible.

Is there maybe a workaround I can use for now to be able to allow the user to use spaces?

Add support for week numbers

Is your feature request related to a problem? Please describe.
In Denmark (and supposedly other countries as well) many people plan using week numbers (say fx. wednesday in week 33). It is stupid, I know, but it is an everyday occurence in Denmark. Everybody plans vacation in Denmark using week numbers fx.

Describe the solution you'd like
I would like the ability to enable weeknumbers as an extra column to the left of each week. Is must support the different weeknumbering systems there are in different countries. (1st week is 1st monday, 1st week is 1st week with thursday etc.)

Highlight the specific dates

Is your feature request related to a problem? Please describe.
In case of using it in diary application for example, I'd like to highlight the specific dates I wrote the diary. But I couldn't find the feature about it.

Describe the solution you'd like
a selected property can be populated with an array of dates to highlight.

Describe alternatives you've considered
N/A

Additional context
N/A

Safari on iOS trigger unnecessary month picker comes up

Describe the bug
When I click the calendar button in Safari or React Native Webview on iOS, the native month picker comes up and hide duetds.

To Reproduce
Steps to reproduce the behavior:

  1. connect to the page in Safari or React Native Webview on iOS
  2. click the calendar button
  3. native month picker comes up after the duetds shows up

Expected behavior
The native month picker wouldn't show up.

Screenshots
image

Smartphone (please complete the following information):

  • Device: iPhone11
  • OS: iOS 14, iPhone11
  • Browser: safari
  • Version: "@duetds/date-picker": "^1.0.1"

Arrow key navigation fails when min or max date limit reached

Describe the bug
If a min or max date is set and the arrow keys are used to attempt to navigate beyond the date the arrow key navigation stops updating correctly leaving the focus'd date the date closest to the limit. If tab/shift-tab is used it can kick the picker into updating the focus state to where it should have been.

To Reproduce
Steps to reproduce the behaviour:

  1. Open a picker with a max date set
  2. Use right or down arrow key to navigate to the end date and use keys to attempt to navigate beyond the max date
  3. Use up or left arrow keys to try and navigate back within range
  4. Focus'd date never updates although month may change

Expected behaviour
When trying to navigate beyond a min or max date focus should remain on the min/max date allowed. When navigating back within range the focus should update immediately

Desktop (please complete the following information):

  • OS: Windows 10, OSX 10.15
  • Browser: Firefox 84, Chrome 87, Trident Edge

Additional context
Add any other context about the problem here.

onClose Event

Is your feature request related to a problem? Please describe.
It would be very useful to have a duetClose event we can listen to. This would allow us to know when the modal is closed via keyboard "close" button.

Describe alternatives you've considered
I've tried to use the duetBlur event but that seems to be fired when the modal opens so it's not a good flag for when it has been closed.

Handling date picker properties in Vue JS

Describe the bug
Thank you very much for all your hard work, this date picker is incredibly neat!

I've been trying to implement this date picker into a Vue JS project. I'm a bit new and as I understand from your documentation, in order to use the properties of duet date picker (e.g. Localization, dateAdapter, direction, etc.) I need to override their defaults. I've been trying to add them as props to my component but so far no luck. Is this a bug or just a gap on my own understanding?

To Reproduce
Steps to reproduce the behavior:

  1. Create a Vue component that uses duet date picker
  2. Pass localization object as a prop

Expected behavior
I expect the placeholder to change it's label from "YYYY-MM-DD" to "DD/MM/YYYY"

Desktop (please complete the following information):

  • OS: Catalina 10.5.15
  • Browser: [Chrome, FF, IE11, Safari]
  • Version: Duet date-picker version 1.0.1

Additional context
Component in case:

  <duet-date-picker 
    ref="date-picker"
    identifier="date"
    direction="left"
    :value="enteredDate"
    v-bind:class="{'has-error': hasErrors}"
    v-bind:required="isRequired"
    :name="name"
    :localization="{placeholder: 'DD/MM/YYYY'}"
    :dateAdapter="format_date()"
    @duetChange="dateChanged"
  />

Plan to support time as well?

Describe the solution you'd like
Hey, is there a plan to support datetime and time formats as well and show a picker for hourse and minutes, seconds (optionally)? If not, feel free to close the issue…

Optional dual month view

Is your feature request related to a problem? Please describe.
Ability to display a dual month view when screen space allows

Describe the solution you'd like
Ability to request dual month view above a specified screen size similar to what can be seen on https://www.airbnb.co.uk/
Also option to disable skipping years and months using the dropdowns ie. only able to use the next previous arrows.

Support custom icon in toggle button

It would be great to be able to apply a custom SVG icon to the toggle button. Is there any possibility that this might be on a future feature list?

Unable to get applyPolyfills && defineCustomElements to import / work properly

I'm looking for some advice on where i'm possibly going wrong when trying to apply the polyfills to get the duet date picker working in IE11 using basic HTML.

I think i am either trying to import it wrong or misunderstanding how i'm supposed to bundle the loader and import it into html.

This is how i am pulling the dependancies into the html head and my initial attempt at getting the polyfill working.

<script type="module" src="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/duet.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/@duetds/[email protected]/dist/duet/duet.js"></script>

<script>
  // applyPolyfills & defineCustomElements are both undefined
  applyPolyfills().then(function () {
    defineCustomElements(window);
  })
</script>

I have additionally tried to use browserfy to bundle the dependencies into a single standalone UMD js file and import that instead.

var loader = require("@duetds/date-picker/dist/loader");

module.exports = {
  applyPolyfills: loader.applyPolyfills,
  defineCustomElements: loader.defineCustomElements,
};
browserify --standalone duetLoader -r ./assets/javascript/duet-non-bundled.js -o assets/javascript/duet-bundled.js
<script type="text/javascript" src="/assets/javascript/duet-bundled.js"></script>
<script>
  var applyPolyfills = duetLoader.applyPolyfills;
  var defineCustomElements = duetLoader.defineCustomElements;
  applyPolyfills().then(function () {
     defineCustomElements(window);
  })
</script>

The above approach resolves the issue with the methods being undefined but i get the following stack trace on runtime when the <duet-date-picker> tags are rendered and the date picker becomes unusable / non responsive to on click events.

duet-bundled.js:1422 Error: Cannot find module './duet-date-picker.cjs.entry.js'
    at o (duet-bundled.js:1)
    at duet-bundled.js:1
    at duet-bundled.js:1432
    at async initializeComponent (duet-bundled.js:1163) undefined

Prior to trying to get the poly fills to work i have encountered no issues with the date picker.

Any advice or a point in the right direction would be much appreciated. If it's something missing in the docs that could be improved i'd be happy to contribute to improving them once i've managed to find a solution.

P.S this is a great date picker in terms of UI and accessibility, I look forward to seeing it develop further.

Default date is strange for future months

Describe the bug
When I navigate with keyboard, I open the date picker.
I go from date to year to next/prev month buttons.

When I leave the next/prev month buttons:
If it's the current month: the default focus is today's date (Sep 17th) - Correct
If it's any month in the future: the default focus is still today's date (= Oct 17th, Nov 17th etc) - Seems strange
I think it would be better if the focus goes to the 1st.

Bundling `@duetds/date-picker` with Rollup doesn't work

Describe the bug
Currently @duetds/date-picker does not work with Rollup (or I didn't get it to).
The problem appears to be a dynamic import statement with a template string:

return import(`./${bundleId}.entry.js${""}`);

Rollup seems to ignore these imports: "Dynamic imports on runtime are ignored by Rollup #2463"

To Reproduce
Clone this repository https://github.com/sto3psl/rollup-duet-date-picker and follow the steps to create a bundle.

Expected behavior
<duet-date-picker></duet-date-picker> should render in the browser with no errors.

Desktop (please complete the following information):

  • OS: macOS 10.15.6
  • Browser: all of them

I'm not sure if this problem comes through duetds/date-picker or Stencil.js or the way everything is published.

[Bug] Date Picker doesn't update value after an invalid date was typed into the input

Describe the bug
The value of <duet-date-picker> is not updated when a valid date is changed to an invalid one. This can cause a form to submit with the former valid date instead of erroring or submitting the actually entered invalid date.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/silly-sunset-cvxkq
  2. Enter a valid date into the date picker input (eg. 2020-11-12)
  3. Submit the form
  4. See that submitted value and actual value are the same.

image

  1. Change date picker input to an invalid date (eg. 2020-11-121244345)
  2. Submit the form
  3. See that submitted value is still the old one and not the one entered.

image

Expected behavior
I'm not sure what the expected behavior is. Maybe an empty string or something like INVALID DATE should get submitted. That way my submit handler can validate against bad inputs.

Additional context
Version @duetds/[email protected]

I think the problem is that the hidden input with name=date is only updated when a correct date was entered. Then changing to an invalid date will not trigger an update which causes the hidden input to keep its former valid date, which gets submitted. As described above, my suggestion is to update the hidden input with some kind of invalid date value.

Datepicker [demo] cannot be used with keyboard + WHC

[Edit: In the demo] users of Windows High Contrast who rely on keyboard cannot see what is being focused, neither the button which opens the datepicker, nor anything inside once it is opened.

To Reproduce
Steps to reproduce the behavior:

  1. Open demo datepicker in a Windows browser which supports WHC (Firefox, Edge. IE if you're brave)
  2. Press Alt+Shift+PrtScn to activate Windows High Contrast. It shouldn't matter which theme is running
  3. Attempt to use the datepicker with keyboard. Focus is visible when the input receives focus, but not the calendar-activation button nor anything inside.

Expected behavior
A focus ring is always available.

Additional context
I will attempt a PR this weekend, although I didn't find the focus styles when looking through the code via Github. [Edit: only the demo has styles]

The solution is simple though: change the outline: 0 on the focus states to outline: 3px dotted transparent. This gives WHC users a visible outline while no other users will see an outline.

Edit: Ideally the demo shows this so developers see examples of code for all users :D

Add "Usage with Svelte" to documentation

Is your feature request related to a problem? Please describe.
I am working on a client project with Svelte and this date picker would be a great replacement for the current one that I am using.

Describe the solution you'd like
Add instructions of how to get Duet Date Picker up and running with Svelte.

Cannot increase the year limit

Hi, i'm using the control with Vue and I'm trying to increase the options available in the year picker.

Currently it's only showing ranges from 2020 to 2010.

I tried using the properties min="1990-06-10" and max="2020-07-18" but this had no effect.

Any ideas how to solve this?

Screen Shot 2020-11-19 at 12 08 29 PM

Ability to highlight dates within a date range

Is your feature request related to a problem? Please describe.
When using the date-picker for a date range it would be useful if the range of dates that has/is being selected could be highlighted visually, providing the user feedback as to the range they have selected.

Describe the solution you'd like
Additional class added to dates within a set range to enable highlighting of the dates within the range that has been selected by the user.
Similar to https://pikaday.com/examples/date-range.html

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

List of requirements?

Our team working on Duet Design System couldn’t find an existing date picker that would’ve ticked all the requirements we had for accessibility (supporting WCAG 2.1 as well as we can)

Do you have a list of what those requirements are?

Abstract the picker component from the input?

Is your feature request related to a problem? Please describe.
The component isn't really a 'date-picker' per se. It's a form field with a date-picker.

In my company we already have a set of full featured, styled form components. So I don't really want to re-style the duet date field, esp as the api of the field is slightly different from the rest of our fields. Ideally, I'd like to just be able to use the 'picker'. This would then allow me to do pre-sets of company preferred settings e.g. date-format or split fields into multiple if I wish e.g. [dd] [mm] [yyyy]

Describe the solution you'd like
An abstraction of 2 components. The input and the picker.

Describe alternatives you've considered
Adding the git repo as a dependency and re-creating the picker from there.

Build attempt fails due to snapshot mismatch

Describe the bug
Running npm install fails when automated testing detects unacceptable differences in the image snapshot diffs.

To Reproduce

  1. Clone the project
  2. Run npm install
  3. Wait while install process runs
  4. See error

Expected behavior
I expected the installation not to fail, and to complete successfully.

Screenshots
Console output:
image

Images found in \date-picker\src\components\duet-date-picker\__image_snapshots__\__diff_output__:
duet-date-picker-e-2-e-ts-duet-date-picker-min-max-support-supports-a-max-date-1-diff
duet-date-picker-e-2-e-ts-duet-date-picker-min-max-support-supports-a-min-date-1-diff
duet-date-picker-e-2-e-ts-duet-date-picker-min-max-support-supports-min-and-max-dates-1-diff

Desktop (please complete the following information):

  • OS: Windows 10 Enterprise Version 10.0.17763 Build 17763
  • Browser: n/a
  • Version: Node.js v12.18.3, npm 6.14.6

Clicking on calendar icon fires 'duetFocus' event on Safari, doesn't on Chrome

Describe the bug
On Safari, clicking on the calendar icon emits the 'duetFocus' event. I think it happens because the focus goes to the input element.

Expected behavior
On Chrome, clicking on the calendar icon doesn't emit the 'duetFocus' event, because focus is given to the calendar overlay as stated on the docs on the "show" method:
https://github.com/duetds/date-picker#show--promisevoid

I think datePicker's behavior in Chrome is more suit, because the behavior on Safari is what makes Safari's month selector to show up below the calendar overlay, as described on the folowing closed bug, which doesn't work well along with our date-picker:
#23 (comment)

Desktop (please complete the following information):

  • OS: Macos
  • Browser: Safari
  • Version 13.1.1

Smartphone (please complete the following information):

  • Device: iPhone Xr
  • OS: IOS 13.5.1
  • Browser Safari

Column Headers Not Announced

Describe the bug
When navigating the calendar grid (<table>) in JAWS, the column headers are not announced. All I hear is "two zero two zero dash zero four dash zero two" (or whatever is the date in this number format).

To Reproduce
Steps to reproduce the behavior:

  1. Go to the grid,
  2. Navigate between days within a week,
  3. Observe the screen reader does not announce the day of the week.

Expected behavior
As I navigate from column to column, I should hear the column header. Specifically I should hear the day of week as I move through a week.

Screenshots
I made a video, but GitHub does not allow me to embed it.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 85
  • JAWS 2020

Additional context
Using first example at https://duetds.github.io/date-picker/

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.