@descope/web-components-ui 1.98.0 → 1.100.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.
@@ -1902,6 +1902,12 @@ const inputValidationMixin$1 = (superclass) =>
1902
1902
  return `Please match the requested type.`;
1903
1903
  }
1904
1904
 
1905
+ getCustomErrorMessage(attr, defaultMsg) {
1906
+ return this.hasAttribute(attr)
1907
+ ? this.getAttribute(attr) || ' '
1908
+ : defaultMsg;
1909
+ }
1910
+
1905
1911
  getErrorMessage(flags) {
1906
1912
  const {
1907
1913
  valueMissing,
@@ -1918,31 +1924,39 @@ const inputValidationMixin$1 = (superclass) =>
1918
1924
 
1919
1925
  switch (true) {
1920
1926
  case valueMissing:
1921
- return (
1922
- this.getAttribute(errorAttributes$1.valueMissing) || this.defaultErrorMsgValueMissing
1927
+ return this.getCustomErrorMessage(
1928
+ errorAttributes$1.valueMissing,
1929
+ this.defaultErrorMsgValueMissing,
1923
1930
  );
1924
1931
  case patternMismatch || stepMismatch || badInput:
1925
- return (
1926
- this.getAttribute(errorAttributes$1.patternMismatch) ||
1927
- this.defaultErrorMsgPatternMismatch
1932
+ return this.getCustomErrorMessage(
1933
+ errorAttributes$1.patternMismatch,
1934
+ this.defaultErrorMsgPatternMismatch,
1928
1935
  );
1929
1936
  case typeMismatch:
1930
- return (
1931
- this.getAttribute(errorAttributes$1.typeMismatch) ||
1932
- this.getAttribute(errorAttributes$1.patternMismatch) ||
1933
- this.defaultErrorMsgTypeMismatch
1937
+ return this.getCustomErrorMessage(
1938
+ errorAttributes$1.typeMismatch,
1939
+ this.defaultErrorMsgTypeMismatch,
1934
1940
  );
1935
1941
  case tooShort:
1936
- return this.getAttribute(errorAttributes$1.tooShort) || this.defaultErrorMsgTooShort;
1942
+ return this.getCustomErrorMessage(
1943
+ errorAttributes$1.tooShort,
1944
+ this.defaultErrorMsgTooShort,
1945
+ );
1937
1946
  case tooLong:
1938
- return this.getAttribute(errorAttributes$1.tooLong) || this.defaultErrorMsgTooLong;
1947
+ return this.getCustomErrorMessage(
1948
+ errorAttributes$1.tooLong,
1949
+ this.defaultErrorMsgTooLong,
1950
+ );
1939
1951
  case rangeUnderflow:
1940
- return (
1941
- this.getAttribute(errorAttributes$1.rangeUnderflow) || this.defaultErrorMsgRangeUnderflow
1952
+ return this.getCustomErrorMessage(
1953
+ errorAttributes$1.rangeUnderflow,
1954
+ this.defaultErrorMsgRangeUnderflow,
1942
1955
  );
1943
1956
  case rangeOverflow:
1944
- return (
1945
- this.getAttribute(errorAttributes$1.rangeOverflow) || this.defaultErrorMsgRangeOverflow
1957
+ return this.getCustomErrorMessage(
1958
+ errorAttributes$1.rangeOverflow,
1959
+ this.defaultErrorMsgRangeOverflow,
1946
1960
  );
1947
1961
  case customError:
1948
1962
  return this.validationMessage;
@@ -1953,7 +1967,11 @@ const inputValidationMixin$1 = (superclass) =>
1953
1967
 
1954
1968
  #setValidity() {
1955
1969
  const validity = this.isReadOnly ? {} : this.getValidity();
1956
- this.#internals.setValidity(validity, this.getErrorMessage(validity), this.validationTarget);
1970
+ this.#internals.setValidity(
1971
+ validity,
1972
+ this.getErrorMessage(validity),
1973
+ this.validationTarget,
1974
+ );
1957
1975
  }
1958
1976
 
1959
1977
  get validationMessage() {
@@ -1990,7 +2008,11 @@ const inputValidationMixin$1 = (superclass) =>
1990
2008
 
1991
2009
  setCustomValidity(errorMessage) {
1992
2010
  if (errorMessage) {
1993
- this.#internals.setValidity({ customError: true }, errorMessage, this.validationTarget);
2011
+ this.#internals.setValidity(
2012
+ { customError: true },
2013
+ errorMessage,
2014
+ this.validationTarget,
2015
+ );
1994
2016
  } else {
1995
2017
  this.#internals.setValidity({});
1996
2018
  this.#setValidity();
@@ -1998,15 +2020,24 @@ const inputValidationMixin$1 = (superclass) =>
1998
2020
  }
1999
2021
 
2000
2022
  get isRequired() {
2001
- return this.hasAttribute('required') && this.getAttribute('required') !== 'false';
2023
+ return (
2024
+ this.hasAttribute('required') &&
2025
+ this.getAttribute('required') !== 'false'
2026
+ );
2002
2027
  }
2003
2028
 
2004
2029
  get isReadOnly() {
2005
- return this.hasAttribute('readonly') && this.getAttribute('readonly') !== 'false';
2030
+ return (
2031
+ this.hasAttribute('readonly') &&
2032
+ this.getAttribute('readonly') !== 'false'
2033
+ );
2006
2034
  }
2007
2035
 
2008
2036
  get isDisabled() {
2009
- return this.hasAttribute('disabled') && this.getAttribute('disabled') !== 'false';
2037
+ return (
2038
+ this.hasAttribute('disabled') &&
2039
+ this.getAttribute('disabled') !== 'false'
2040
+ );
2010
2041
  }
2011
2042
 
2012
2043
  get pattern() {
@@ -3493,6 +3524,10 @@ const inputValidationMixin = (superclass) =>
3493
3524
  return `Please match the requested type.`;
3494
3525
  }
3495
3526
 
3527
+ getCustomErrorMessage(attr, defaultMsg) {
3528
+ return this.hasAttribute(attr) ? this.getAttribute(attr) || ' ' : defaultMsg;
3529
+ }
3530
+
3496
3531
  getErrorMessage(flags) {
3497
3532
  const {
3498
3533
  valueMissing,
@@ -3509,31 +3544,33 @@ const inputValidationMixin = (superclass) =>
3509
3544
 
3510
3545
  switch (true) {
3511
3546
  case valueMissing:
3512
- return (
3513
- this.getAttribute(errorAttributes.valueMissing) || this.defaultErrorMsgValueMissing
3547
+ return this.getCustomErrorMessage(
3548
+ errorAttributes.valueMissing,
3549
+ this.defaultErrorMsgValueMissing
3514
3550
  );
3515
3551
  case patternMismatch || stepMismatch || badInput:
3516
- return (
3517
- this.getAttribute(errorAttributes.patternMismatch) ||
3552
+ return this.getCustomErrorMessage(
3553
+ errorAttributes.patternMismatch,
3518
3554
  this.defaultErrorMsgPatternMismatch
3519
3555
  );
3520
3556
  case typeMismatch:
3521
- return (
3522
- this.getAttribute(errorAttributes.typeMismatch) ||
3523
- this.getAttribute(errorAttributes.patternMismatch) ||
3557
+ return this.getCustomErrorMessage(
3558
+ errorAttributes.typeMismatch,
3524
3559
  this.defaultErrorMsgTypeMismatch
3525
3560
  );
3526
3561
  case tooShort:
3527
- return this.getAttribute(errorAttributes.tooShort) || this.defaultErrorMsgTooShort;
3562
+ return this.getCustomErrorMessage(errorAttributes.tooShort, this.defaultErrorMsgTooShort);
3528
3563
  case tooLong:
3529
- return this.getAttribute(errorAttributes.tooLong) || this.defaultErrorMsgTooLong;
3564
+ return this.getCustomErrorMessage(errorAttributes.tooLong, this.defaultErrorMsgTooLong);
3530
3565
  case rangeUnderflow:
3531
- return (
3532
- this.getAttribute(errorAttributes.rangeUnderflow) || this.defaultErrorMsgRangeUnderflow
3566
+ return this.getCustomErrorMessage(
3567
+ errorAttributes.rangeUnderflow,
3568
+ this.defaultErrorMsgRangeUnderflow
3533
3569
  );
3534
3570
  case rangeOverflow:
3535
- return (
3536
- this.getAttribute(errorAttributes.rangeOverflow) || this.defaultErrorMsgRangeOverflow
3571
+ return this.getCustomErrorMessage(
3572
+ errorAttributes.rangeOverflow,
3573
+ this.defaultErrorMsgRangeOverflow
3537
3574
  );
3538
3575
  case customError:
3539
3576
  return this.validationMessage;
@@ -16778,6 +16815,8 @@ class RawDateFieldClass extends BaseInputClass$1 {
16778
16815
 
16779
16816
  selectedCounterIdx = 0;
16780
16817
 
16818
+ #focused = false;
16819
+
16781
16820
  updateCountersDisplay() {
16782
16821
  this.inputElement.value = this.countersValue;
16783
16822
  }
@@ -16988,6 +17027,22 @@ class RawDateFieldClass extends BaseInputClass$1 {
16988
17027
  this.inputElement.addEventListener('keydown', this.handleArrowKeys.bind(this));
16989
17028
  this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
16990
17029
 
17030
+ // We want to handle touch events the same way we handle `click` events.
17031
+ // Since we can't seem to block touch events (`touch-action: none` or preventing default on `touchstart`
17032
+ // or `touchend`, we listen to `pointerdown` and in case it's of type `touch` we execute
17033
+ // the component's logic for range selection.
17034
+ this.inputElement.addEventListener('pointerdown', (e) => {
17035
+ if (e.pointerType === 'touch') {
17036
+ e.preventDefault();
17037
+ if (!this.#focused) {
17038
+ this.inputElement.focus();
17039
+ }
17040
+ setTimeout(() => {
17041
+ this.handleMouseCaretPositionChange(e);
17042
+ }, 250);
17043
+ }
17044
+ });
17045
+
16991
17046
  forwardAttrs$1(this, this.inputElement, {
16992
17047
  includeAttrs: [
16993
17048
  'label',
@@ -17185,20 +17240,34 @@ class RawDateFieldClass extends BaseInputClass$1 {
17185
17240
  }
17186
17241
 
17187
17242
  onFocus() {
17188
- if (this.isReadOnly) {
17243
+ if (this.isReadOnly || this.#focused) {
17189
17244
  return;
17190
17245
  }
17191
17246
 
17247
+ // We use this flag to support mobile logic, which calls `focus` on touch event, we want to make sure
17248
+ // focus executes it logic only when needed.
17249
+ this.#focused = true;
17250
+
17251
+ this.resetDisplay();
17252
+ }
17253
+
17254
+ resetDisplay() {
17192
17255
  if (!this.inputElement.value) {
17193
17256
  this.inputElement.value = this.format;
17194
17257
  }
17195
17258
 
17196
17259
  // On focus select the first part of the format placeholder
17197
17260
  this.selectedCounterIdx = 0;
17198
- this.setInputSelectionRange();
17261
+
17262
+ setTimeout(() => {
17263
+ // set selection on first counter
17264
+ this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
17265
+ });
17199
17266
  }
17200
17267
 
17201
17268
  onBlur() {
17269
+ this.#focused = false;
17270
+
17202
17271
  if (this.opened) {
17203
17272
  return;
17204
17273
  }
@@ -17242,7 +17311,9 @@ class RawDateFieldClass extends BaseInputClass$1 {
17242
17311
  }
17243
17312
 
17244
17313
  setSelectedCounterByCaretPosition(e) {
17245
- this.selectedCounterIdx = this.getCounterIdx(e.target.selectionStart);
17314
+ this.selectedCounterIdx = this.getCounterIdx(
17315
+ e.target.selectionStart || this.inputElement.selectionStart
17316
+ );
17246
17317
  }
17247
17318
 
17248
17319
  selectNextCounter() {
@@ -17348,7 +17419,12 @@ class RawDateFieldClass extends BaseInputClass$1 {
17348
17419
  }
17349
17420
  e.preventDefault();
17350
17421
  this.setSelectedCounterByCaretPosition(e);
17351
- this.setInputSelectionRange();
17422
+
17423
+ // On keydown - in desktop mode - selection is sometimes not set, and instead there is a cursor.
17424
+ // We need to wait until we can set selection range.
17425
+ setTimeout(() => {
17426
+ this.setInputSelectionRange();
17427
+ });
17352
17428
  }
17353
17429
 
17354
17430
  onInitialValueChange(val) {