@nectary/components 5.60.0 → 5.62.0

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/bundle.js CHANGED
@@ -5979,6 +5979,20 @@ const areDatesEqual = (a, b) => {
5979
5979
  const cloneDate = (date) => {
5980
5980
  return new Date(date.getTime());
5981
5981
  };
5982
+ const addUtcDays = (date, days) => {
5983
+ const next = new Date(date.getTime());
5984
+ next.setUTCDate(next.getUTCDate() + days);
5985
+ return next;
5986
+ };
5987
+ const formatAccessibleDate = (locale, date) => {
5988
+ return new Intl.DateTimeFormat(locale, {
5989
+ weekday: "long",
5990
+ year: "numeric",
5991
+ month: "long",
5992
+ day: "numeric",
5993
+ timeZone: "UTC"
5994
+ }).format(date);
5995
+ };
5982
5996
  const sortDates = (dateTuple) => {
5983
5997
  if (compareDates(dateTuple[0], dateTuple[1]) > 0) {
5984
5998
  return [dateTuple[1], dateTuple[0]];
@@ -5993,15 +6007,17 @@ const isDateOnScreen = (uiDate, date) => {
5993
6007
  const lastDateOfMonth = new Date(Date.UTC(uiDate.getUTCFullYear(), uiDate.getUTCMonth() + 1, 0));
5994
6008
  return isDateBetween(date, firstDateOfMonth, lastDateOfMonth);
5995
6009
  };
5996
- const templateHTML$V = '<style>:host{display:block;outline:0}#content{width:fit-content;box-sizing:border-box;padding:16px;display:flex;flex-direction:column;gap:8px}#month{display:flex;flex-direction:column;row-gap:8px}.week{display:flex;flex-direction:row;column-gap:8px}.week.empty{display:none}.day{all:initial;font:var(--sinch-comp-date-picker-font-day);width:24px;height:24px;line-height:22px;color:var(--sinch-comp-date-picker-day-color-default-text-initial);background-color:var(--sinch-comp-date-picker-day-color-default-background-initial);border:1px solid var(--sinch-comp-date-picker-day-color-default-border-initial);border-radius:var(--sinch-comp-date-picker-day-shape-radius);text-align:center;box-sizing:border-box;user-select:none;cursor:pointer}.day:focus-visible{outline:1px solid var(--sinch-comp-date-picker-day-color-default-outline-focus);outline-offset:1px}.day:disabled{cursor:initial;color:var(--sinch-comp-date-picker-day-color-disabled-text-initial)}.day:enabled:hover{background-color:var(--sinch-comp-date-picker-day-color-default-background-hover)}.day:enabled.range{background-color:var(--sinch-comp-date-picker-day-color-default-range-background)}.day:enabled.selected{color:var(--sinch-comp-date-picker-day-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-day-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-day-color-checked-border-initial)}.day.today{font:var(--sinch-comp-date-picker-font-today);color:var(--sinch-comp-date-picker-today-color-default-text-initial);background-color:var(--sinch-comp-date-picker-today-color-default-background-initial);border-color:var(--sinch-comp-date-picker-today-color-default-border-initial)}.day.today:hover{background-color:var(--sinch-comp-date-picker-today-color-default-background-hover)}.day.today:disabled{color:var(--sinch-comp-date-picker-today-color-disabled-text-initial);border-color:var(--sinch-comp-date-picker-today-color-disabled-border-initial)}.day.today.selected{color:var(--sinch-comp-date-picker-today-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-today-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-today-color-checked-border-initial)}#week-day-names{display:flex;flex-direction:row;gap:8px;height:24px}.week-day-name{font:var(--sinch-comp-date-picker-font-weekday);color:var(--sinch-comp-date-picker-weekday-color-default-text-initial);text-align:center;width:24px;height:24px;line-height:24px;user-select:none;text-transform:uppercase}#content-header{display:flex;flex-direction:row;height:32px;align-items:center}#date{flex:1;text-align:center;text-transform:capitalize;--sinch-com-text-font:var(--sinch-comp-date-picker-font-header);--sinch-global-color-text:var(--sinch-comp-date-picker-header-color-default-text-initial)}#prev-year{margin-left:-4px}#next-year{margin-right:-4px}</style><div id="content"><div id="content-header"><sinch-button id="prev-year" size="s"><sinch-icon icons-version="2" name="fa-angles-left" id="icon-prev-year" slot="icon"></sinch-icon></sinch-button><sinch-button id="prev-month" size="s"><sinch-icon icons-version="2" name="fa-angle-left" id="icon-prev-month" slot="icon"></sinch-icon></sinch-button><sinch-text id="date" type="m" emphasized aria-live="polite"></sinch-text><sinch-button id="next-month" size="s"><sinch-icon icons-version="2" name="fa-angle-right" id="icon-next-month" slot="icon"></sinch-icon></sinch-button><sinch-button id="next-year" size="s"><sinch-icon icons-version="2" name="fa-angles-right" id="icon-next-year" slot="icon"></sinch-icon></sinch-button></div><div id="week-day-names"><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div></div><div id="month"><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div></div></div>';
6010
+ const templateHTML$V = '<style>:host{display:block;outline:0}#content{width:fit-content;box-sizing:border-box;padding:16px;display:flex;flex-direction:column;gap:8px}#calendar{display:flex;flex-direction:column;row-gap:8px}#month{display:flex;flex-direction:column;row-gap:8px}.week{display:flex;flex-direction:row;column-gap:8px}.week.empty{display:none}.day{all:initial;font:var(--sinch-comp-date-picker-font-day);width:24px;height:24px;line-height:22px;color:var(--sinch-comp-date-picker-day-color-default-text-initial);background-color:var(--sinch-comp-date-picker-day-color-default-background-initial);border:1px solid var(--sinch-comp-date-picker-day-color-default-border-initial);border-radius:var(--sinch-comp-date-picker-day-shape-radius);text-align:center;box-sizing:border-box;user-select:none;cursor:pointer}.day:focus-visible{outline:1px solid var(--sinch-comp-date-picker-day-color-default-outline-focus);outline-offset:1px}.day:disabled{cursor:initial;color:var(--sinch-comp-date-picker-day-color-disabled-text-initial)}.day:enabled:hover{background-color:var(--sinch-comp-date-picker-day-color-default-background-hover)}.day:enabled.range{background-color:var(--sinch-comp-date-picker-day-color-default-range-background)}.day:enabled.selected{color:var(--sinch-comp-date-picker-day-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-day-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-day-color-checked-border-initial)}.day.today{font:var(--sinch-comp-date-picker-font-today);color:var(--sinch-comp-date-picker-today-color-default-text-initial);background-color:var(--sinch-comp-date-picker-today-color-default-background-initial);border-color:var(--sinch-comp-date-picker-today-color-default-border-initial)}.day.today:hover{background-color:var(--sinch-comp-date-picker-today-color-default-background-hover)}.day.today:disabled{color:var(--sinch-comp-date-picker-today-color-disabled-text-initial);border-color:var(--sinch-comp-date-picker-today-color-disabled-border-initial)}.day.today.selected{color:var(--sinch-comp-date-picker-today-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-today-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-today-color-checked-border-initial)}#week-day-names{display:flex;flex-direction:row;gap:8px;height:24px}.week-day-name{font:var(--sinch-comp-date-picker-font-weekday);color:var(--sinch-comp-date-picker-weekday-color-default-text-initial);text-align:center;width:24px;height:24px;line-height:24px;user-select:none;text-transform:uppercase}#content-header{display:flex;flex-direction:row;height:32px;align-items:center}#date{flex:1;text-align:center;text-transform:capitalize;--sinch-com-text-font:var(--sinch-comp-date-picker-font-header);--sinch-global-color-text:var(--sinch-comp-date-picker-header-color-default-text-initial)}#prev-year{margin-left:-4px}#next-year{margin-right:-4px}</style><div id="content"><div id="content-header"><sinch-button id="prev-year" size="s"><sinch-icon icons-version="2" name="fa-angles-left" id="icon-prev-year" slot="icon"></sinch-icon></sinch-button><sinch-button id="prev-month" size="s"><sinch-icon icons-version="2" name="fa-angle-left" id="icon-prev-month" slot="icon"></sinch-icon></sinch-button><sinch-text id="date" type="m" emphasized aria-live="polite"></sinch-text><sinch-button id="next-month" size="s"><sinch-icon icons-version="2" name="fa-angle-right" id="icon-next-month" slot="icon"></sinch-icon></sinch-button><sinch-button id="next-year" size="s"><sinch-icon icons-version="2" name="fa-angles-right" id="icon-next-year" slot="icon"></sinch-icon></sinch-button></div><div id="calendar" role="grid" aria-labelledby="date"><div id="week-day-names" role="row"><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div></div><div id="month"><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div></div></div></div>';
5997
6011
  const template$V = document.createElement("template");
5998
6012
  template$V.innerHTML = templateHTML$V;
5999
6013
  class DatePicker extends NectaryElement {
6014
+ #$calendar;
6000
6015
  #$month;
6001
6016
  #$weeks;
6002
6017
  #$days;
6003
6018
  #$weekDayNames;
6004
6019
  #uiDate = null;
6020
+ #focusDate = null;
6005
6021
  #date1 = null;
6006
6022
  #date2 = null;
6007
6023
  #minDate = null;
@@ -6021,6 +6037,7 @@ class DatePicker extends NectaryElement {
6021
6037
  const shadowRoot = this.attachShadow({ delegatesFocus: true });
6022
6038
  shadowRoot.appendChild(template$V.content.cloneNode(true));
6023
6039
  this.#internals = this.attachInternals();
6040
+ this.#$calendar = shadowRoot.querySelector("#calendar");
6024
6041
  this.#$prevMonth = shadowRoot.querySelector("#prev-month");
6025
6042
  this.#$nextMonth = shadowRoot.querySelector("#next-month");
6026
6043
  this.#$prevYear = shadowRoot.querySelector("#prev-year");
@@ -6050,6 +6067,7 @@ class DatePicker extends NectaryElement {
6050
6067
  this.#$prevYear.addEventListener("click", this.#onPrevYearClick, options);
6051
6068
  this.#$nextYear.addEventListener("click", this.#onNextYearClick, options);
6052
6069
  this.#$month.addEventListener("click", this.#onDateClick, options);
6070
+ this.#$calendar.addEventListener("keydown", this.#onGridKeyDown, options);
6053
6071
  this.addEventListener("-change", this.#onChangeReactHandler, options);
6054
6072
  }
6055
6073
  disconnectedCallback() {
@@ -6249,17 +6267,7 @@ class DatePicker extends NectaryElement {
6249
6267
  if (hoverDateIso === null) {
6250
6268
  return;
6251
6269
  }
6252
- const hoverDate = isoToDate(hoverDateIso);
6253
- const todayDate = today();
6254
- for (const week of this.#$days) {
6255
- for (const $day of week) {
6256
- if ($day.hasAttribute("disabled")) {
6257
- continue;
6258
- }
6259
- const dayDate = isoToDate($day.getAttribute("data-date"));
6260
- setClass($day, "range", !areDatesEqual(todayDate, dayDate) && (isDateBetween(dayDate, this.#date1, hoverDate) || isDateBetween(dayDate, hoverDate, this.#date1)));
6261
- }
6262
- }
6270
+ this.#paintRangePreview(isoToDate(hoverDateIso));
6263
6271
  }
6264
6272
  };
6265
6273
  #onDateClick = (e) => {
@@ -6294,6 +6302,7 @@ class DatePicker extends NectaryElement {
6294
6302
  };
6295
6303
  #onValueChange() {
6296
6304
  const value = this.value;
6305
+ this.#focusDate = null;
6297
6306
  setFormValue(this.#internals, this.value);
6298
6307
  this.#date1 = null;
6299
6308
  this.#date2 = null;
@@ -6358,22 +6367,38 @@ class DatePicker extends NectaryElement {
6358
6367
  if (day == null) {
6359
6368
  $day.textContent = "";
6360
6369
  $day.removeAttribute("data-date");
6370
+ $day.removeAttribute("aria-label");
6371
+ $day.removeAttribute("aria-selected");
6372
+ $day.removeAttribute("aria-current");
6373
+ $day.removeAttribute("tabindex");
6361
6374
  $day.setAttribute("disabled", "");
6362
6375
  $day.setAttribute("aria-hidden", "true");
6363
6376
  } else {
6364
6377
  const dayIso = dateToIso(day);
6378
+ const isSelected = areDatesEqual(day, this.#date1) || areDatesEqual(day, this.#date2);
6379
+ const isToday = areDatesEqual(day, todayDate);
6380
+ const isAllowed = isDateBetween(day, this.#minDate, this.#maxDate);
6365
6381
  $day.textContent = day.getUTCDate().toString();
6366
6382
  $day.setAttribute("data-date", dayIso);
6367
- if (isDateBetween(day, this.#minDate, this.#maxDate)) {
6383
+ $day.setAttribute("aria-label", formatAccessibleDate(this.locale, day));
6384
+ $day.removeAttribute("aria-hidden");
6385
+ if (isToday) {
6386
+ $day.setAttribute("aria-current", "date");
6387
+ } else {
6388
+ $day.removeAttribute("aria-current");
6389
+ }
6390
+ if (isAllowed) {
6368
6391
  $day.removeAttribute("disabled");
6369
- $day.removeAttribute("aria-hidden");
6392
+ $day.removeAttribute("tabindex");
6393
+ $day.setAttribute("aria-selected", isSelected ? "true" : "false");
6370
6394
  } else {
6371
6395
  $day.setAttribute("disabled", "");
6372
- $day.setAttribute("aria-hidden", "true");
6396
+ $day.removeAttribute("tabindex");
6397
+ $day.removeAttribute("aria-selected");
6373
6398
  }
6374
- if (areDatesEqual(day, this.#date1) || areDatesEqual(day, this.#date2)) {
6399
+ if (isSelected) {
6375
6400
  $day.classList.add("selected");
6376
- } else if (areDatesEqual(day, todayDate)) {
6401
+ } else if (isToday) {
6377
6402
  $day.classList.add("today");
6378
6403
  } else if (isDateBetween(day, this.#date1, this.#date2)) {
6379
6404
  $day.classList.add("range");
@@ -6383,6 +6408,91 @@ class DatePicker extends NectaryElement {
6383
6408
  }
6384
6409
  setClass(this.#$weeks[wi], "empty", isEmptyWeek);
6385
6410
  }
6411
+ if (this.range && this.#date1 !== null && this.#date2 === null && this.#focusDate !== null) {
6412
+ this.#paintRangePreview(this.#focusDate);
6413
+ }
6414
+ }
6415
+ #onGridKeyDown = (e) => {
6416
+ const target = e.target instanceof Element ? e.target.closest(".day") : null;
6417
+ if (target === null || target.hasAttribute("disabled")) {
6418
+ return;
6419
+ }
6420
+ let delta = 0;
6421
+ switch (e.code) {
6422
+ case "ArrowLeft": {
6423
+ delta = -1;
6424
+ break;
6425
+ }
6426
+ case "ArrowRight": {
6427
+ delta = 1;
6428
+ break;
6429
+ }
6430
+ case "ArrowUp": {
6431
+ delta = -7;
6432
+ break;
6433
+ }
6434
+ case "ArrowDown": {
6435
+ delta = 7;
6436
+ break;
6437
+ }
6438
+ default: {
6439
+ return;
6440
+ }
6441
+ }
6442
+ e.preventDefault();
6443
+ e.stopPropagation();
6444
+ this.#moveFocus(delta);
6445
+ };
6446
+ #moveFocus(delta) {
6447
+ const current = this.#dateFromFocus();
6448
+ if (current === null || this.#minDate === null || this.#maxDate === null) {
6449
+ return;
6450
+ }
6451
+ const next = addUtcDays(current, delta);
6452
+ if (!isDateBetween(next, this.#minDate, this.#maxDate)) {
6453
+ return;
6454
+ }
6455
+ this.#focusDate = next;
6456
+ if (this.#uiDate === null || !isDateOnScreen(this.#uiDate, next)) {
6457
+ this.#uiDate = cloneDate(next);
6458
+ }
6459
+ this.#render();
6460
+ this.#focusDay(next);
6461
+ }
6462
+ #dateFromFocus() {
6463
+ const active = this.shadowRoot?.activeElement;
6464
+ const iso = active?.getAttribute("data-date");
6465
+ if (iso !== null && iso !== void 0 && iso.length > 0) {
6466
+ return isoToDate(iso);
6467
+ }
6468
+ return this.#focusDate;
6469
+ }
6470
+ #focusDay(date) {
6471
+ const iso = dateToIso(date);
6472
+ for (const week of this.#$days) {
6473
+ for (const $day of week) {
6474
+ if ($day.getAttribute("data-date") === iso) {
6475
+ $day.focus();
6476
+ return;
6477
+ }
6478
+ }
6479
+ }
6480
+ }
6481
+ #paintRangePreview(hoverDate) {
6482
+ if (this.#date1 === null) {
6483
+ return;
6484
+ }
6485
+ const todayDate = today();
6486
+ for (const week of this.#$days) {
6487
+ for (const $day of week) {
6488
+ if ($day.hasAttribute("disabled")) {
6489
+ continue;
6490
+ }
6491
+ const dayDate = isoToDate($day.getAttribute("data-date"));
6492
+ const inRange = isDateBetween(dayDate, this.#date1, hoverDate) || isDateBetween(dayDate, hoverDate, this.#date1);
6493
+ setClass($day, "range", !areDatesEqual(todayDate, dayDate) && inRange);
6494
+ }
6495
+ }
6386
6496
  }
6387
6497
  #subscribeRangeHover() {
6388
6498
  if (!this.#isHoverSubscribed) {
@@ -6657,7 +6767,7 @@ class Dialog extends NectaryElement {
6657
6767
  };
6658
6768
  }
6659
6769
  defineCustomElement("sinch-dialog", Dialog);
6660
- const inputTypes = ["text", "password", "number"];
6770
+ const inputTypes = ["text", "password", "number", "email"];
6661
6771
  const MASK_SYMBOL_LETTER = "A";
6662
6772
  const MASK_SYMBOL_DIGIT = "0";
6663
6773
  const EMPTY_CHAR = " ";
@@ -7158,7 +7268,7 @@ class Input extends NectaryElement {
7158
7268
  break;
7159
7269
  }
7160
7270
  case "type": {
7161
- updateLiteralAttribute(this.#$input, inputTypes, "type", newVal);
7271
+ this.#applyNativeType();
7162
7272
  updateAttribute(this.#$input, "spellcheck", newVal === "password" ? "false" : null);
7163
7273
  this.#updateInputRole();
7164
7274
  this.#updateAriaValueAttributes();
@@ -7325,21 +7435,39 @@ class Input extends NectaryElement {
7325
7435
  return getAttribute(this, "autocomplete", "");
7326
7436
  }
7327
7437
  get selectionStart() {
7438
+ if (!this.#canSetSelection()) {
7439
+ return null;
7440
+ }
7328
7441
  return this.#$input.selectionStart;
7329
7442
  }
7330
7443
  set selectionStart(value) {
7444
+ if (!this.#canSetSelection()) {
7445
+ return;
7446
+ }
7331
7447
  this.#$input.selectionStart = value;
7332
7448
  }
7333
7449
  get selectionEnd() {
7450
+ if (!this.#canSetSelection()) {
7451
+ return null;
7452
+ }
7334
7453
  return this.#$input.selectionEnd;
7335
7454
  }
7336
7455
  set selectionEnd(value) {
7456
+ if (!this.#canSetSelection()) {
7457
+ return;
7458
+ }
7337
7459
  this.#$input.selectionEnd = value;
7338
7460
  }
7339
7461
  get selectionDirection() {
7462
+ if (!this.#canSetSelection()) {
7463
+ return null;
7464
+ }
7340
7465
  return this.#$input.selectionDirection;
7341
7466
  }
7342
7467
  set selectionDirection(value) {
7468
+ if (!this.#canSetSelection()) {
7469
+ return;
7470
+ }
7343
7471
  this.#$input.selectionDirection = value;
7344
7472
  }
7345
7473
  setSelectionRange(selectionStart, selectionEnd) {
@@ -7360,15 +7488,43 @@ class Input extends NectaryElement {
7360
7488
  blur() {
7361
7489
  this.#$input.blur();
7362
7490
  }
7491
+ // The native control exposes a caret for text and password. number and email throw.
7492
+ #canSetSelection() {
7493
+ const type = this.#$input.type;
7494
+ return type === "text" || type === "password";
7495
+ }
7496
+ // A mask rewrites the value from the caret. Email cannot report one, so the
7497
+ // native control is text while the mask is on. The host type stays email.
7498
+ #applyNativeType() {
7499
+ if (this.#maskSymbols !== null && this.type === "email") {
7500
+ this.#$input.type = "text";
7501
+ return;
7502
+ }
7503
+ updateLiteralAttribute(this.#$input, inputTypes, "type", this.getAttribute("type"));
7504
+ }
7505
+ #readSelection() {
7506
+ if (!this.#canSetSelection()) {
7507
+ return null;
7508
+ }
7509
+ return {
7510
+ start: this.#$input.selectionStart ?? 0,
7511
+ end: this.#$input.selectionEnd ?? 0
7512
+ };
7513
+ }
7363
7514
  #setSelectionRange = (start, end, direction) => {
7364
- if (this.type !== "number") {
7365
- this.#$input.setSelectionRange(start, end, direction);
7515
+ if (!this.#canSetSelection()) {
7516
+ return;
7366
7517
  }
7518
+ this.#$input.setSelectionRange(start, end, direction);
7367
7519
  };
7368
7520
  #onCompositionStart = () => {
7369
7521
  this.#isCompositionInProgress = true;
7370
7522
  if (this.#maskSymbols !== null) {
7371
- const selectionStart = this.#$input.selectionStart;
7523
+ const selection = this.#readSelection();
7524
+ if (selection === null) {
7525
+ return;
7526
+ }
7527
+ const selectionStart = selection.start;
7372
7528
  this.#compositionBeginValue = this.#$input.value;
7373
7529
  if (selectionStart === this.#$input.value.length) {
7374
7530
  return;
@@ -7385,7 +7541,11 @@ class Input extends NectaryElement {
7385
7541
  if (this.#maskSymbols !== null) {
7386
7542
  const value = this.#$input.value;
7387
7543
  const wasValueInserted = value.length !== this.#compositionBeginValue.length;
7388
- const res = endMaskedComposition(value, e.data, this.#maskSymbols, this.#$input.selectionStart, wasValueInserted);
7544
+ const selectionStart = this.#readSelection()?.start;
7545
+ if (selectionStart === void 0) {
7546
+ return;
7547
+ }
7548
+ const res = endMaskedComposition(value, e.data, this.#maskSymbols, selectionStart, wasValueInserted);
7389
7549
  this.#compositionBeginValue = "";
7390
7550
  if (res !== null) {
7391
7551
  const { value: value2, placeholder, mergedValue, cursorPos } = res;
@@ -7406,13 +7566,20 @@ class Input extends NectaryElement {
7406
7566
  }
7407
7567
  };
7408
7568
  #onMaskBeforeInput = (e) => {
7569
+ if (this.#readSelection() === null) {
7570
+ return;
7571
+ }
7409
7572
  this.#handleMaskBeforeInput(e.inputType, e.data);
7410
7573
  e.preventDefault();
7411
7574
  };
7412
7575
  #handleMaskBeforeInput(inputType, data2) {
7413
7576
  this.#wasClearedByMask = false;
7414
- const selectionStart = this.#$input.selectionStart ?? 0;
7415
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7577
+ const selection = this.#readSelection();
7578
+ if (selection === null) {
7579
+ return;
7580
+ }
7581
+ const selectionStart = selection.start;
7582
+ const selectionEnd = selection.end;
7416
7583
  let res = null;
7417
7584
  switch (inputType) {
7418
7585
  case "insertText": {
@@ -7450,8 +7617,12 @@ class Input extends NectaryElement {
7450
7617
  }
7451
7618
  }
7452
7619
  #handleBeforeInput(inputType, data2) {
7453
- const selectionStart = this.#$input.selectionStart ?? 0;
7454
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7620
+ const selection = this.#readSelection();
7621
+ if (selection === null) {
7622
+ return;
7623
+ }
7624
+ const selectionStart = selection.start;
7625
+ const selectionEnd = selection.end;
7455
7626
  const value = this.#$input.value;
7456
7627
  switch (inputType) {
7457
7628
  case "insertFromPaste": {
@@ -7486,14 +7657,15 @@ class Input extends NectaryElement {
7486
7657
  const prevValue = this.#previousValue;
7487
7658
  setFormValue(this.#internals, nextValue);
7488
7659
  if (prevValue !== nextValue) {
7489
- const nextSelectionStart = this.#$input.selectionStart;
7490
- const nextSelectionEnd = this.#$input.selectionEnd;
7491
- if (this.#isControlledInput === true && this.hasAttribute("value") === true) {
7660
+ const selection = this.#readSelection();
7661
+ if (this.type !== "email" && this.#isControlledInput === true && this.hasAttribute("value") === true) {
7492
7662
  this.#$input.value = prevValue;
7493
7663
  this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
7494
7664
  }
7495
- this.#selectionStart = nextSelectionStart;
7496
- this.#selectionEnd = nextSelectionEnd;
7665
+ if (selection !== null) {
7666
+ this.#selectionStart = selection.start;
7667
+ this.#selectionEnd = selection.end;
7668
+ }
7497
7669
  this.#dispatchChangeEvent(nextValue);
7498
7670
  }
7499
7671
  };
@@ -7520,12 +7692,11 @@ class Input extends NectaryElement {
7520
7692
  };
7521
7693
  #onCopy = (e) => {
7522
7694
  const value = this.#$input.value;
7523
- const selectionStart = this.#$input.selectionStart ?? 0;
7524
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7525
- if (e.clipboardData === null || selectionStart === selectionEnd) {
7695
+ const selection = this.#readSelection();
7696
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
7526
7697
  return;
7527
7698
  }
7528
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
7699
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
7529
7700
  let replacedValue = null;
7530
7701
  const replaceWith = (value2) => {
7531
7702
  replacedValue = value2 ?? null;
@@ -7551,12 +7722,11 @@ class Input extends NectaryElement {
7551
7722
  };
7552
7723
  #onCut = (e) => {
7553
7724
  const value = this.#$input.value;
7554
- const selectionStart = this.#$input.selectionStart ?? 0;
7555
- const selectionEnd = this.#$input.selectionEnd ?? 0;
7556
- if (e.clipboardData === null || selectionStart === selectionEnd) {
7725
+ const selection = this.#readSelection();
7726
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
7557
7727
  return;
7558
7728
  }
7559
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
7729
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
7560
7730
  let replacedValue = null;
7561
7731
  const replaceWith = (value2) => {
7562
7732
  replacedValue = value2 ?? null;
@@ -7606,6 +7776,10 @@ class Input extends NectaryElement {
7606
7776
  return;
7607
7777
  }
7608
7778
  e.preventDefault();
7779
+ if (this.#readSelection() === null) {
7780
+ document.execCommand("insertText", false, replacedValue);
7781
+ return;
7782
+ }
7609
7783
  if (this.#maskSymbols !== null) {
7610
7784
  this.#handleMaskBeforeInput("insertFromPaste", replacedValue);
7611
7785
  } else {
@@ -7648,6 +7822,7 @@ class Input extends NectaryElement {
7648
7822
  this.#$input.addEventListener("change", this.#onMaskInputAutofillChange, { signal: this.#controller.signal });
7649
7823
  }
7650
7824
  this.#maskSymbols = getMaskSymbols(this.mask);
7825
+ this.#applyNativeType();
7651
7826
  const { value, placeholder } = splitValueAndMask(this.#$input.value, this.#maskSymbols);
7652
7827
  this.#$input.value = value;
7653
7828
  this.#$inputMask.textContent = placeholder;
@@ -7655,6 +7830,7 @@ class Input extends NectaryElement {
7655
7830
  this.#maskSymbols = null;
7656
7831
  this.#$input.removeEventListener("beforeinput", this.#onMaskBeforeInput);
7657
7832
  this.#$input.removeEventListener("change", this.#onMaskInputAutofillChange);
7833
+ this.#applyNativeType();
7658
7834
  }
7659
7835
  this.#updatePlaceholder();
7660
7836
  }
@@ -7,16 +7,18 @@ import { getRect } from "../utils/rect.js";
7
7
  import { getReactEventHandler } from "../utils/get-react-event-handler.js";
8
8
  import { getTargetAttribute } from "../utils/event-target.js";
9
9
  import { setFormValue } from "../utils/form.js";
10
- import { getDayNames, getMonthNames, isoToDate, clampMaxDate, clampMinDate, decMonth, incMonth, decYear, incYear, today, isDateBetween, areDatesEqual, sortDates, dateToIso, isValidDate, isDateOnScreen, cloneDate, getCalendarMonth, canGoPrevMonth, canGoNextMonth, canGoPrevYear, canGoNextYear } from "./utils.js";
11
- const templateHTML = '<style>:host{display:block;outline:0}#content{width:fit-content;box-sizing:border-box;padding:16px;display:flex;flex-direction:column;gap:8px}#month{display:flex;flex-direction:column;row-gap:8px}.week{display:flex;flex-direction:row;column-gap:8px}.week.empty{display:none}.day{all:initial;font:var(--sinch-comp-date-picker-font-day);width:24px;height:24px;line-height:22px;color:var(--sinch-comp-date-picker-day-color-default-text-initial);background-color:var(--sinch-comp-date-picker-day-color-default-background-initial);border:1px solid var(--sinch-comp-date-picker-day-color-default-border-initial);border-radius:var(--sinch-comp-date-picker-day-shape-radius);text-align:center;box-sizing:border-box;user-select:none;cursor:pointer}.day:focus-visible{outline:1px solid var(--sinch-comp-date-picker-day-color-default-outline-focus);outline-offset:1px}.day:disabled{cursor:initial;color:var(--sinch-comp-date-picker-day-color-disabled-text-initial)}.day:enabled:hover{background-color:var(--sinch-comp-date-picker-day-color-default-background-hover)}.day:enabled.range{background-color:var(--sinch-comp-date-picker-day-color-default-range-background)}.day:enabled.selected{color:var(--sinch-comp-date-picker-day-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-day-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-day-color-checked-border-initial)}.day.today{font:var(--sinch-comp-date-picker-font-today);color:var(--sinch-comp-date-picker-today-color-default-text-initial);background-color:var(--sinch-comp-date-picker-today-color-default-background-initial);border-color:var(--sinch-comp-date-picker-today-color-default-border-initial)}.day.today:hover{background-color:var(--sinch-comp-date-picker-today-color-default-background-hover)}.day.today:disabled{color:var(--sinch-comp-date-picker-today-color-disabled-text-initial);border-color:var(--sinch-comp-date-picker-today-color-disabled-border-initial)}.day.today.selected{color:var(--sinch-comp-date-picker-today-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-today-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-today-color-checked-border-initial)}#week-day-names{display:flex;flex-direction:row;gap:8px;height:24px}.week-day-name{font:var(--sinch-comp-date-picker-font-weekday);color:var(--sinch-comp-date-picker-weekday-color-default-text-initial);text-align:center;width:24px;height:24px;line-height:24px;user-select:none;text-transform:uppercase}#content-header{display:flex;flex-direction:row;height:32px;align-items:center}#date{flex:1;text-align:center;text-transform:capitalize;--sinch-com-text-font:var(--sinch-comp-date-picker-font-header);--sinch-global-color-text:var(--sinch-comp-date-picker-header-color-default-text-initial)}#prev-year{margin-left:-4px}#next-year{margin-right:-4px}</style><div id="content"><div id="content-header"><sinch-button id="prev-year" size="s"><sinch-icon icons-version="2" name="fa-angles-left" id="icon-prev-year" slot="icon"></sinch-icon></sinch-button><sinch-button id="prev-month" size="s"><sinch-icon icons-version="2" name="fa-angle-left" id="icon-prev-month" slot="icon"></sinch-icon></sinch-button><sinch-text id="date" type="m" emphasized aria-live="polite"></sinch-text><sinch-button id="next-month" size="s"><sinch-icon icons-version="2" name="fa-angle-right" id="icon-next-month" slot="icon"></sinch-icon></sinch-button><sinch-button id="next-year" size="s"><sinch-icon icons-version="2" name="fa-angles-right" id="icon-next-year" slot="icon"></sinch-icon></sinch-button></div><div id="week-day-names"><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div></div><div id="month"><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div></div></div>';
10
+ import { getDayNames, getMonthNames, isoToDate, clampMaxDate, clampMinDate, decMonth, incMonth, decYear, incYear, sortDates, dateToIso, isValidDate, isDateOnScreen, cloneDate, today, getCalendarMonth, canGoPrevMonth, canGoNextMonth, canGoPrevYear, canGoNextYear, areDatesEqual, isDateBetween, formatAccessibleDate, addUtcDays } from "./utils.js";
11
+ const templateHTML = '<style>:host{display:block;outline:0}#content{width:fit-content;box-sizing:border-box;padding:16px;display:flex;flex-direction:column;gap:8px}#calendar{display:flex;flex-direction:column;row-gap:8px}#month{display:flex;flex-direction:column;row-gap:8px}.week{display:flex;flex-direction:row;column-gap:8px}.week.empty{display:none}.day{all:initial;font:var(--sinch-comp-date-picker-font-day);width:24px;height:24px;line-height:22px;color:var(--sinch-comp-date-picker-day-color-default-text-initial);background-color:var(--sinch-comp-date-picker-day-color-default-background-initial);border:1px solid var(--sinch-comp-date-picker-day-color-default-border-initial);border-radius:var(--sinch-comp-date-picker-day-shape-radius);text-align:center;box-sizing:border-box;user-select:none;cursor:pointer}.day:focus-visible{outline:1px solid var(--sinch-comp-date-picker-day-color-default-outline-focus);outline-offset:1px}.day:disabled{cursor:initial;color:var(--sinch-comp-date-picker-day-color-disabled-text-initial)}.day:enabled:hover{background-color:var(--sinch-comp-date-picker-day-color-default-background-hover)}.day:enabled.range{background-color:var(--sinch-comp-date-picker-day-color-default-range-background)}.day:enabled.selected{color:var(--sinch-comp-date-picker-day-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-day-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-day-color-checked-border-initial)}.day.today{font:var(--sinch-comp-date-picker-font-today);color:var(--sinch-comp-date-picker-today-color-default-text-initial);background-color:var(--sinch-comp-date-picker-today-color-default-background-initial);border-color:var(--sinch-comp-date-picker-today-color-default-border-initial)}.day.today:hover{background-color:var(--sinch-comp-date-picker-today-color-default-background-hover)}.day.today:disabled{color:var(--sinch-comp-date-picker-today-color-disabled-text-initial);border-color:var(--sinch-comp-date-picker-today-color-disabled-border-initial)}.day.today.selected{color:var(--sinch-comp-date-picker-today-color-checked-text-initial);background-color:var(--sinch-comp-date-picker-today-color-checked-background-initial);border-color:var(--sinch-comp-date-picker-today-color-checked-border-initial)}#week-day-names{display:flex;flex-direction:row;gap:8px;height:24px}.week-day-name{font:var(--sinch-comp-date-picker-font-weekday);color:var(--sinch-comp-date-picker-weekday-color-default-text-initial);text-align:center;width:24px;height:24px;line-height:24px;user-select:none;text-transform:uppercase}#content-header{display:flex;flex-direction:row;height:32px;align-items:center}#date{flex:1;text-align:center;text-transform:capitalize;--sinch-com-text-font:var(--sinch-comp-date-picker-font-header);--sinch-global-color-text:var(--sinch-comp-date-picker-header-color-default-text-initial)}#prev-year{margin-left:-4px}#next-year{margin-right:-4px}</style><div id="content"><div id="content-header"><sinch-button id="prev-year" size="s"><sinch-icon icons-version="2" name="fa-angles-left" id="icon-prev-year" slot="icon"></sinch-icon></sinch-button><sinch-button id="prev-month" size="s"><sinch-icon icons-version="2" name="fa-angle-left" id="icon-prev-month" slot="icon"></sinch-icon></sinch-button><sinch-text id="date" type="m" emphasized aria-live="polite"></sinch-text><sinch-button id="next-month" size="s"><sinch-icon icons-version="2" name="fa-angle-right" id="icon-next-month" slot="icon"></sinch-icon></sinch-button><sinch-button id="next-year" size="s"><sinch-icon icons-version="2" name="fa-angles-right" id="icon-next-year" slot="icon"></sinch-icon></sinch-button></div><div id="calendar" role="grid" aria-labelledby="date"><div id="week-day-names" role="row"><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div><div class="week-day-name" role="columnheader"></div></div><div id="month"><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div><div class="week" role="row"><button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button> <button type="button" class="day" role="gridcell"></button></div></div></div></div>';
12
12
  const template = document.createElement("template");
13
13
  template.innerHTML = templateHTML;
14
14
  class DatePicker extends NectaryElement {
15
+ #$calendar;
15
16
  #$month;
16
17
  #$weeks;
17
18
  #$days;
18
19
  #$weekDayNames;
19
20
  #uiDate = null;
21
+ #focusDate = null;
20
22
  #date1 = null;
21
23
  #date2 = null;
22
24
  #minDate = null;
@@ -36,6 +38,7 @@ class DatePicker extends NectaryElement {
36
38
  const shadowRoot = this.attachShadow({ delegatesFocus: true });
37
39
  shadowRoot.appendChild(template.content.cloneNode(true));
38
40
  this.#internals = this.attachInternals();
41
+ this.#$calendar = shadowRoot.querySelector("#calendar");
39
42
  this.#$prevMonth = shadowRoot.querySelector("#prev-month");
40
43
  this.#$nextMonth = shadowRoot.querySelector("#next-month");
41
44
  this.#$prevYear = shadowRoot.querySelector("#prev-year");
@@ -65,6 +68,7 @@ class DatePicker extends NectaryElement {
65
68
  this.#$prevYear.addEventListener("click", this.#onPrevYearClick, options);
66
69
  this.#$nextYear.addEventListener("click", this.#onNextYearClick, options);
67
70
  this.#$month.addEventListener("click", this.#onDateClick, options);
71
+ this.#$calendar.addEventListener("keydown", this.#onGridKeyDown, options);
68
72
  this.addEventListener("-change", this.#onChangeReactHandler, options);
69
73
  }
70
74
  disconnectedCallback() {
@@ -264,17 +268,7 @@ class DatePicker extends NectaryElement {
264
268
  if (hoverDateIso === null) {
265
269
  return;
266
270
  }
267
- const hoverDate = isoToDate(hoverDateIso);
268
- const todayDate = today();
269
- for (const week of this.#$days) {
270
- for (const $day of week) {
271
- if ($day.hasAttribute("disabled")) {
272
- continue;
273
- }
274
- const dayDate = isoToDate($day.getAttribute("data-date"));
275
- setClass($day, "range", !areDatesEqual(todayDate, dayDate) && (isDateBetween(dayDate, this.#date1, hoverDate) || isDateBetween(dayDate, hoverDate, this.#date1)));
276
- }
277
- }
271
+ this.#paintRangePreview(isoToDate(hoverDateIso));
278
272
  }
279
273
  };
280
274
  #onDateClick = (e) => {
@@ -309,6 +303,7 @@ class DatePicker extends NectaryElement {
309
303
  };
310
304
  #onValueChange() {
311
305
  const value = this.value;
306
+ this.#focusDate = null;
312
307
  setFormValue(this.#internals, this.value);
313
308
  this.#date1 = null;
314
309
  this.#date2 = null;
@@ -373,22 +368,38 @@ class DatePicker extends NectaryElement {
373
368
  if (day == null) {
374
369
  $day.textContent = "";
375
370
  $day.removeAttribute("data-date");
371
+ $day.removeAttribute("aria-label");
372
+ $day.removeAttribute("aria-selected");
373
+ $day.removeAttribute("aria-current");
374
+ $day.removeAttribute("tabindex");
376
375
  $day.setAttribute("disabled", "");
377
376
  $day.setAttribute("aria-hidden", "true");
378
377
  } else {
379
378
  const dayIso = dateToIso(day);
379
+ const isSelected = areDatesEqual(day, this.#date1) || areDatesEqual(day, this.#date2);
380
+ const isToday = areDatesEqual(day, todayDate);
381
+ const isAllowed = isDateBetween(day, this.#minDate, this.#maxDate);
380
382
  $day.textContent = day.getUTCDate().toString();
381
383
  $day.setAttribute("data-date", dayIso);
382
- if (isDateBetween(day, this.#minDate, this.#maxDate)) {
384
+ $day.setAttribute("aria-label", formatAccessibleDate(this.locale, day));
385
+ $day.removeAttribute("aria-hidden");
386
+ if (isToday) {
387
+ $day.setAttribute("aria-current", "date");
388
+ } else {
389
+ $day.removeAttribute("aria-current");
390
+ }
391
+ if (isAllowed) {
383
392
  $day.removeAttribute("disabled");
384
- $day.removeAttribute("aria-hidden");
393
+ $day.removeAttribute("tabindex");
394
+ $day.setAttribute("aria-selected", isSelected ? "true" : "false");
385
395
  } else {
386
396
  $day.setAttribute("disabled", "");
387
- $day.setAttribute("aria-hidden", "true");
397
+ $day.removeAttribute("tabindex");
398
+ $day.removeAttribute("aria-selected");
388
399
  }
389
- if (areDatesEqual(day, this.#date1) || areDatesEqual(day, this.#date2)) {
400
+ if (isSelected) {
390
401
  $day.classList.add("selected");
391
- } else if (areDatesEqual(day, todayDate)) {
402
+ } else if (isToday) {
392
403
  $day.classList.add("today");
393
404
  } else if (isDateBetween(day, this.#date1, this.#date2)) {
394
405
  $day.classList.add("range");
@@ -398,6 +409,91 @@ class DatePicker extends NectaryElement {
398
409
  }
399
410
  setClass(this.#$weeks[wi], "empty", isEmptyWeek);
400
411
  }
412
+ if (this.range && this.#date1 !== null && this.#date2 === null && this.#focusDate !== null) {
413
+ this.#paintRangePreview(this.#focusDate);
414
+ }
415
+ }
416
+ #onGridKeyDown = (e) => {
417
+ const target = e.target instanceof Element ? e.target.closest(".day") : null;
418
+ if (target === null || target.hasAttribute("disabled")) {
419
+ return;
420
+ }
421
+ let delta = 0;
422
+ switch (e.code) {
423
+ case "ArrowLeft": {
424
+ delta = -1;
425
+ break;
426
+ }
427
+ case "ArrowRight": {
428
+ delta = 1;
429
+ break;
430
+ }
431
+ case "ArrowUp": {
432
+ delta = -7;
433
+ break;
434
+ }
435
+ case "ArrowDown": {
436
+ delta = 7;
437
+ break;
438
+ }
439
+ default: {
440
+ return;
441
+ }
442
+ }
443
+ e.preventDefault();
444
+ e.stopPropagation();
445
+ this.#moveFocus(delta);
446
+ };
447
+ #moveFocus(delta) {
448
+ const current = this.#dateFromFocus();
449
+ if (current === null || this.#minDate === null || this.#maxDate === null) {
450
+ return;
451
+ }
452
+ const next = addUtcDays(current, delta);
453
+ if (!isDateBetween(next, this.#minDate, this.#maxDate)) {
454
+ return;
455
+ }
456
+ this.#focusDate = next;
457
+ if (this.#uiDate === null || !isDateOnScreen(this.#uiDate, next)) {
458
+ this.#uiDate = cloneDate(next);
459
+ }
460
+ this.#render();
461
+ this.#focusDay(next);
462
+ }
463
+ #dateFromFocus() {
464
+ const active = this.shadowRoot?.activeElement;
465
+ const iso = active?.getAttribute("data-date");
466
+ if (iso !== null && iso !== void 0 && iso.length > 0) {
467
+ return isoToDate(iso);
468
+ }
469
+ return this.#focusDate;
470
+ }
471
+ #focusDay(date) {
472
+ const iso = dateToIso(date);
473
+ for (const week of this.#$days) {
474
+ for (const $day of week) {
475
+ if ($day.getAttribute("data-date") === iso) {
476
+ $day.focus();
477
+ return;
478
+ }
479
+ }
480
+ }
481
+ }
482
+ #paintRangePreview(hoverDate) {
483
+ if (this.#date1 === null) {
484
+ return;
485
+ }
486
+ const todayDate = today();
487
+ for (const week of this.#$days) {
488
+ for (const $day of week) {
489
+ if ($day.hasAttribute("disabled")) {
490
+ continue;
491
+ }
492
+ const dayDate = isoToDate($day.getAttribute("data-date"));
493
+ const inRange = isDateBetween(dayDate, this.#date1, hoverDate) || isDateBetween(dayDate, hoverDate, this.#date1);
494
+ setClass($day, "range", !areDatesEqual(todayDate, dayDate) && inRange);
495
+ }
496
+ }
401
497
  }
402
498
  #subscribeRangeHover() {
403
499
  if (!this.#isHoverSubscribed) {
@@ -23,6 +23,8 @@ export declare const canGoPrevYear: (date: Date, min: Date) => boolean;
23
23
  export declare const isDateBetween: (date: Date, min: Date | null, max: Date | null) => boolean;
24
24
  export declare const areDatesEqual: (a: Date, b: Date | null) => boolean;
25
25
  export declare const cloneDate: (date: Date) => Date;
26
+ export declare const addUtcDays: (date: Date, days: number) => Date;
27
+ export declare const formatAccessibleDate: (locale: string, date: Date) => string;
26
28
  export declare const sortDates: (dateTuple: [Date, Date]) => [Date, Date];
27
29
  export declare const isDateOnScreen: (uiDate: Date | null, date: Date | null) => boolean;
28
30
  export {};
@@ -168,6 +168,20 @@ const areDatesEqual = (a, b) => {
168
168
  const cloneDate = (date) => {
169
169
  return new Date(date.getTime());
170
170
  };
171
+ const addUtcDays = (date, days) => {
172
+ const next = new Date(date.getTime());
173
+ next.setUTCDate(next.getUTCDate() + days);
174
+ return next;
175
+ };
176
+ const formatAccessibleDate = (locale, date) => {
177
+ return new Intl.DateTimeFormat(locale, {
178
+ weekday: "long",
179
+ year: "numeric",
180
+ month: "long",
181
+ day: "numeric",
182
+ timeZone: "UTC"
183
+ }).format(date);
184
+ };
171
185
  const sortDates = (dateTuple) => {
172
186
  if (compareDates(dateTuple[0], dateTuple[1]) > 0) {
173
187
  return [dateTuple[1], dateTuple[0]];
@@ -183,6 +197,7 @@ const isDateOnScreen = (uiDate, date) => {
183
197
  return isDateBetween(date, firstDateOfMonth, lastDateOfMonth);
184
198
  };
185
199
  export {
200
+ addUtcDays,
186
201
  areDatesEqual,
187
202
  canGoNextMonth,
188
203
  canGoNextYear,
@@ -195,6 +210,7 @@ export {
195
210
  dateToIso,
196
211
  decMonth,
197
212
  decYear,
213
+ formatAccessibleDate,
198
214
  getCalendarMonth,
199
215
  getDayNames,
200
216
  getMonthNames,
package/input/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context, subscribeContext } from "../utils/context.js";
2
- import { getBooleanAttribute, getAttribute, updateAttribute, isAttrEqual, isAttrTrue, updateBooleanAttribute, updateLiteralAttribute, getLiteralAttribute, setClass } from "../utils/dom.js";
2
+ import { getBooleanAttribute, getAttribute, updateAttribute, isAttrEqual, isAttrTrue, updateBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, setClass } from "../utils/dom.js";
3
3
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
4
4
  import { isElementFocused } from "../utils/slot.js";
5
5
  import { getReactEventHandler } from "../utils/get-react-event-handler.js";
@@ -207,7 +207,7 @@ class Input extends NectaryElement {
207
207
  break;
208
208
  }
209
209
  case "type": {
210
- updateLiteralAttribute(this.#$input, inputTypes, "type", newVal);
210
+ this.#applyNativeType();
211
211
  updateAttribute(this.#$input, "spellcheck", newVal === "password" ? "false" : null);
212
212
  this.#updateInputRole();
213
213
  this.#updateAriaValueAttributes();
@@ -374,21 +374,39 @@ class Input extends NectaryElement {
374
374
  return getAttribute(this, "autocomplete", "");
375
375
  }
376
376
  get selectionStart() {
377
+ if (!this.#canSetSelection()) {
378
+ return null;
379
+ }
377
380
  return this.#$input.selectionStart;
378
381
  }
379
382
  set selectionStart(value) {
383
+ if (!this.#canSetSelection()) {
384
+ return;
385
+ }
380
386
  this.#$input.selectionStart = value;
381
387
  }
382
388
  get selectionEnd() {
389
+ if (!this.#canSetSelection()) {
390
+ return null;
391
+ }
383
392
  return this.#$input.selectionEnd;
384
393
  }
385
394
  set selectionEnd(value) {
395
+ if (!this.#canSetSelection()) {
396
+ return;
397
+ }
386
398
  this.#$input.selectionEnd = value;
387
399
  }
388
400
  get selectionDirection() {
401
+ if (!this.#canSetSelection()) {
402
+ return null;
403
+ }
389
404
  return this.#$input.selectionDirection;
390
405
  }
391
406
  set selectionDirection(value) {
407
+ if (!this.#canSetSelection()) {
408
+ return;
409
+ }
392
410
  this.#$input.selectionDirection = value;
393
411
  }
394
412
  setSelectionRange(selectionStart, selectionEnd) {
@@ -409,15 +427,43 @@ class Input extends NectaryElement {
409
427
  blur() {
410
428
  this.#$input.blur();
411
429
  }
430
+ // The native control exposes a caret for text and password. number and email throw.
431
+ #canSetSelection() {
432
+ const type = this.#$input.type;
433
+ return type === "text" || type === "password";
434
+ }
435
+ // A mask rewrites the value from the caret. Email cannot report one, so the
436
+ // native control is text while the mask is on. The host type stays email.
437
+ #applyNativeType() {
438
+ if (this.#maskSymbols !== null && this.type === "email") {
439
+ this.#$input.type = "text";
440
+ return;
441
+ }
442
+ updateLiteralAttribute(this.#$input, inputTypes, "type", this.getAttribute("type"));
443
+ }
444
+ #readSelection() {
445
+ if (!this.#canSetSelection()) {
446
+ return null;
447
+ }
448
+ return {
449
+ start: this.#$input.selectionStart ?? 0,
450
+ end: this.#$input.selectionEnd ?? 0
451
+ };
452
+ }
412
453
  #setSelectionRange = (start, end, direction) => {
413
- if (this.type !== "number") {
414
- this.#$input.setSelectionRange(start, end, direction);
454
+ if (!this.#canSetSelection()) {
455
+ return;
415
456
  }
457
+ this.#$input.setSelectionRange(start, end, direction);
416
458
  };
417
459
  #onCompositionStart = () => {
418
460
  this.#isCompositionInProgress = true;
419
461
  if (this.#maskSymbols !== null) {
420
- const selectionStart = this.#$input.selectionStart;
462
+ const selection = this.#readSelection();
463
+ if (selection === null) {
464
+ return;
465
+ }
466
+ const selectionStart = selection.start;
421
467
  this.#compositionBeginValue = this.#$input.value;
422
468
  if (selectionStart === this.#$input.value.length) {
423
469
  return;
@@ -434,7 +480,11 @@ class Input extends NectaryElement {
434
480
  if (this.#maskSymbols !== null) {
435
481
  const value = this.#$input.value;
436
482
  const wasValueInserted = value.length !== this.#compositionBeginValue.length;
437
- const res = endMaskedComposition(value, e.data, this.#maskSymbols, this.#$input.selectionStart, wasValueInserted);
483
+ const selectionStart = this.#readSelection()?.start;
484
+ if (selectionStart === void 0) {
485
+ return;
486
+ }
487
+ const res = endMaskedComposition(value, e.data, this.#maskSymbols, selectionStart, wasValueInserted);
438
488
  this.#compositionBeginValue = "";
439
489
  if (res !== null) {
440
490
  const { value: value2, placeholder, mergedValue, cursorPos } = res;
@@ -455,13 +505,20 @@ class Input extends NectaryElement {
455
505
  }
456
506
  };
457
507
  #onMaskBeforeInput = (e) => {
508
+ if (this.#readSelection() === null) {
509
+ return;
510
+ }
458
511
  this.#handleMaskBeforeInput(e.inputType, e.data);
459
512
  e.preventDefault();
460
513
  };
461
514
  #handleMaskBeforeInput(inputType, data) {
462
515
  this.#wasClearedByMask = false;
463
- const selectionStart = this.#$input.selectionStart ?? 0;
464
- const selectionEnd = this.#$input.selectionEnd ?? 0;
516
+ const selection = this.#readSelection();
517
+ if (selection === null) {
518
+ return;
519
+ }
520
+ const selectionStart = selection.start;
521
+ const selectionEnd = selection.end;
465
522
  let res = null;
466
523
  switch (inputType) {
467
524
  case "insertText": {
@@ -499,8 +556,12 @@ class Input extends NectaryElement {
499
556
  }
500
557
  }
501
558
  #handleBeforeInput(inputType, data) {
502
- const selectionStart = this.#$input.selectionStart ?? 0;
503
- const selectionEnd = this.#$input.selectionEnd ?? 0;
559
+ const selection = this.#readSelection();
560
+ if (selection === null) {
561
+ return;
562
+ }
563
+ const selectionStart = selection.start;
564
+ const selectionEnd = selection.end;
504
565
  const value = this.#$input.value;
505
566
  switch (inputType) {
506
567
  case "insertFromPaste": {
@@ -535,14 +596,15 @@ class Input extends NectaryElement {
535
596
  const prevValue = this.#previousValue;
536
597
  setFormValue(this.#internals, nextValue);
537
598
  if (prevValue !== nextValue) {
538
- const nextSelectionStart = this.#$input.selectionStart;
539
- const nextSelectionEnd = this.#$input.selectionEnd;
540
- if (this.#isControlledInput === true && this.hasAttribute("value") === true) {
599
+ const selection = this.#readSelection();
600
+ if (this.type !== "email" && this.#isControlledInput === true && this.hasAttribute("value") === true) {
541
601
  this.#$input.value = prevValue;
542
602
  this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
543
603
  }
544
- this.#selectionStart = nextSelectionStart;
545
- this.#selectionEnd = nextSelectionEnd;
604
+ if (selection !== null) {
605
+ this.#selectionStart = selection.start;
606
+ this.#selectionEnd = selection.end;
607
+ }
546
608
  this.#dispatchChangeEvent(nextValue);
547
609
  }
548
610
  };
@@ -569,12 +631,11 @@ class Input extends NectaryElement {
569
631
  };
570
632
  #onCopy = (e) => {
571
633
  const value = this.#$input.value;
572
- const selectionStart = this.#$input.selectionStart ?? 0;
573
- const selectionEnd = this.#$input.selectionEnd ?? 0;
574
- if (e.clipboardData === null || selectionStart === selectionEnd) {
634
+ const selection = this.#readSelection();
635
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
575
636
  return;
576
637
  }
577
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
638
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
578
639
  let replacedValue = null;
579
640
  const replaceWith = (value2) => {
580
641
  replacedValue = value2 ?? null;
@@ -600,12 +661,11 @@ class Input extends NectaryElement {
600
661
  };
601
662
  #onCut = (e) => {
602
663
  const value = this.#$input.value;
603
- const selectionStart = this.#$input.selectionStart ?? 0;
604
- const selectionEnd = this.#$input.selectionEnd ?? 0;
605
- if (e.clipboardData === null || selectionStart === selectionEnd) {
664
+ const selection = this.#readSelection();
665
+ if (e.clipboardData === null || selection === null || selection.start === selection.end) {
606
666
  return;
607
667
  }
608
- const copiedValue = this.#maskSymbols === null ? value.substring(selectionStart, selectionEnd) : getMergedValueSliced(value, this.#maskSymbols, selectionStart, selectionEnd);
668
+ const copiedValue = this.#maskSymbols === null ? value.substring(selection.start, selection.end) : getMergedValueSliced(value, this.#maskSymbols, selection.start, selection.end);
609
669
  let replacedValue = null;
610
670
  const replaceWith = (value2) => {
611
671
  replacedValue = value2 ?? null;
@@ -655,6 +715,10 @@ class Input extends NectaryElement {
655
715
  return;
656
716
  }
657
717
  e.preventDefault();
718
+ if (this.#readSelection() === null) {
719
+ document.execCommand("insertText", false, replacedValue);
720
+ return;
721
+ }
658
722
  if (this.#maskSymbols !== null) {
659
723
  this.#handleMaskBeforeInput("insertFromPaste", replacedValue);
660
724
  } else {
@@ -697,6 +761,7 @@ class Input extends NectaryElement {
697
761
  this.#$input.addEventListener("change", this.#onMaskInputAutofillChange, { signal: this.#controller.signal });
698
762
  }
699
763
  this.#maskSymbols = getMaskSymbols(this.mask);
764
+ this.#applyNativeType();
700
765
  const { value, placeholder } = splitValueAndMask(this.#$input.value, this.#maskSymbols);
701
766
  this.#$input.value = value;
702
767
  this.#$inputMask.textContent = placeholder;
@@ -704,6 +769,7 @@ class Input extends NectaryElement {
704
769
  this.#maskSymbols = null;
705
770
  this.#$input.removeEventListener("beforeinput", this.#onMaskBeforeInput);
706
771
  this.#$input.removeEventListener("change", this.#onMaskInputAutofillChange);
772
+ this.#applyNativeType();
707
773
  }
708
774
  this.#updatePlaceholder();
709
775
  }
package/input/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NectaryComponentReactByType, NectaryComponentVanillaByType, NectaryComponentVanilla, NectaryComponentReact } from '../types';
2
2
  import type { TSinchSize } from '../utils/size';
3
- export type TSinchInputType = 'text' | 'password' | 'number';
3
+ export type TSinchInputType = 'text' | 'password' | 'number' | 'email';
4
4
  export type TSinchInputClipboardEvent = CustomEvent<{
5
5
  value: string;
6
6
  replaceWith: (value: string) => void;
package/input/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- const inputTypes = ["text", "password", "number"];
1
+ const inputTypes = ["text", "password", "number", "email"];
2
2
  const MASK_SYMBOL_LETTER = "A";
3
3
  const MASK_SYMBOL_DIGIT = "0";
4
4
  const EMPTY_CHAR = " ";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.60.0",
3
+ "version": "5.62.0",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",