@esri/calcite-components 1.0.0-next.423 → 1.0.0-next.424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hydrate/index.js CHANGED
@@ -17373,20 +17373,23 @@ class DatePickerMonthHeader {
17373
17373
  * Increment year on UP/DOWN keys
17374
17374
  */
17375
17375
  this.onYearKey = (e) => {
17376
- const year = e.target.value;
17376
+ const localizedYear = e.target.value;
17377
17377
  switch (e.key) {
17378
17378
  case "ArrowDown":
17379
17379
  e.preventDefault();
17380
- this.setYear(year, -1);
17380
+ this.setYear({ localizedYear, offset: -1 });
17381
17381
  break;
17382
17382
  case "ArrowUp":
17383
17383
  e.preventDefault();
17384
- this.setYear(year, 1);
17384
+ this.setYear({ localizedYear, offset: 1 });
17385
17385
  break;
17386
17386
  }
17387
17387
  };
17388
- this.yearChanged = (event) => {
17389
- this.setYear(event.target.value);
17388
+ this.onYearChange = (event) => {
17389
+ this.setYear({ localizedYear: event.target.value });
17390
+ };
17391
+ this.onYearInput = (event) => {
17392
+ this.setYear({ localizedYear: event.target.value, commit: false });
17390
17393
  };
17391
17394
  this.prevMonthClick = (e) => {
17392
17395
  this.handleArrowClick(e, this.prevMonthDate);
@@ -17442,7 +17445,7 @@ class DatePickerMonthHeader {
17442
17445
  return (hAsync(Fragment, null, hAsync("a", { "aria-disabled": (this.prevMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlPrevMonth, class: "chevron", href: "#", onClick: this.prevMonthClick, onKeyDown: this.prevMonthKeydown, role: "button", tabindex: this.prevMonthDate.getMonth() === activeMonth ? -1 : 0 }, hAsync("calcite-icon", { "flip-rtl": true, icon: "chevron-left", scale: iconScale })), hAsync("div", { class: { text: true, "text--reverse": reverse } }, hAsync(Heading, { class: "month", level: this.headingLevel }, localizedMonth), hAsync("span", { class: "year-wrap" }, hAsync("input", { "aria-label": this.intlYear, class: {
17443
17446
  year: true,
17444
17447
  "year--suffix": !!suffix
17445
- }, inputmode: "numeric", maxlength: "4", minlength: "1", onInput: this.yearChanged, onKeyDown: this.onYearKey, pattern: "\\d*", ref: (el) => (this.yearInput = el), type: "text", value: localizedYear }), suffix && (hAsync("span", { class: "suffix" }, hAsync("span", { "aria-hidden": "true", class: "suffix__invisible" }, localizedYear), " " + suffix)))), hAsync("a", { "aria-disabled": (this.nextMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlNextMonth, class: "chevron", href: "#", onClick: this.nextMonthClick, onKeyDown: this.nextMonthKeydown, role: "button", tabindex: this.nextMonthDate.getMonth() === activeMonth ? -1 : 0 }, hAsync("calcite-icon", { "flip-rtl": true, icon: "chevron-right", scale: iconScale }))));
17448
+ }, inputmode: "numeric", maxlength: "4", minlength: "1", onChange: this.onYearChange, onInput: this.onYearInput, onKeyDown: this.onYearKey, pattern: "\\d*", ref: (el) => (this.yearInput = el), type: "text", value: localizedYear }), suffix && (hAsync("span", { class: "suffix" }, hAsync("span", { "aria-hidden": "true", class: "suffix__invisible" }, localizedYear), " " + suffix)))), hAsync("a", { "aria-disabled": (this.nextMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlNextMonth, class: "chevron", href: "#", onClick: this.nextMonthClick, onKeyDown: this.nextMonthKeydown, role: "button", tabindex: this.nextMonthDate.getMonth() === activeMonth ? -1 : 0 }, hAsync("calcite-icon", { "flip-rtl": true, icon: "chevron-right", scale: iconScale }))));
17446
17449
  }
17447
17450
  setNextPrevMonthDates() {
17448
17451
  if (!this.activeDate) {
@@ -17451,27 +17454,32 @@ class DatePickerMonthHeader {
17451
17454
  this.nextMonthDate = dateFromRange(nextMonth(this.activeDate), this.min, this.max);
17452
17455
  this.prevMonthDate = dateFromRange(prevMonth(this.activeDate), this.min, this.max);
17453
17456
  }
17454
- /**
17455
- * Parse localized year string from input,
17456
- * set to active if in range
17457
- */
17458
- setYear(localizedYear, increment = 0) {
17459
- const { min, max, activeDate, localeData, yearInput } = this;
17457
+ getInRangeDate({ localizedYear, offset = 0 }) {
17458
+ const { min, max, activeDate, localeData } = this;
17460
17459
  const parsedYear = parseNumber(localizedYear, localeData);
17461
17460
  const length = parsedYear.toString().length;
17462
- const year = isNaN(parsedYear) ? false : parsedYear + increment;
17461
+ const year = isNaN(parsedYear) ? false : parsedYear + offset;
17463
17462
  const inRange = year && (!min || min.getFullYear() <= year) && (!max || max.getFullYear() >= year);
17464
- // if you've supplied a year and it's in range, update active date
17463
+ // if you've supplied a year and it's in range
17465
17464
  if (year && inRange && length === localizedYear.length) {
17466
17465
  const nextDate = new Date(activeDate);
17467
17466
  nextDate.setFullYear(year);
17468
- const inRangeDate = dateFromRange(nextDate, min, max);
17467
+ return dateFromRange(nextDate, min, max);
17468
+ }
17469
+ }
17470
+ /**
17471
+ * Parse localized year string from input,
17472
+ * set to active if in range
17473
+ */
17474
+ setYear({ localizedYear, commit = true, offset = 0 }) {
17475
+ const { yearInput, activeDate, localeData } = this;
17476
+ const inRangeDate = this.getInRangeDate({ localizedYear, offset });
17477
+ // if you've supplied a year and it's in range, update active date
17478
+ if (inRangeDate) {
17469
17479
  this.calciteDatePickerSelect.emit(inRangeDate);
17470
- yearInput.value = localizeNumber(inRangeDate.getFullYear(), localeData);
17471
17480
  }
17472
- else {
17473
- // leave the current active date and clean up garbage input
17474
- yearInput.value = localizeNumber(activeDate.getFullYear(), localeData);
17481
+ if (commit) {
17482
+ yearInput.value = localizeNumber((inRangeDate || activeDate).getFullYear(), localeData);
17475
17483
  }
17476
17484
  }
17477
17485
  get el() { return getElement(this); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/calcite-components",
3
- "version": "1.0.0-next.423",
3
+ "version": "1.0.0-next.424",
4
4
  "description": "Web Components for Esri's Calcite Design System.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",