@descope/web-components-ui 1.99.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.
@@ -16815,6 +16815,8 @@ class RawDateFieldClass extends BaseInputClass$1 {
16815
16815
 
16816
16816
  selectedCounterIdx = 0;
16817
16817
 
16818
+ #focused = false;
16819
+
16818
16820
  updateCountersDisplay() {
16819
16821
  this.inputElement.value = this.countersValue;
16820
16822
  }
@@ -17025,6 +17027,22 @@ class RawDateFieldClass extends BaseInputClass$1 {
17025
17027
  this.inputElement.addEventListener('keydown', this.handleArrowKeys.bind(this));
17026
17028
  this.inputElement.addEventListener('beforeinput', this.handleInput.bind(this));
17027
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
+
17028
17046
  forwardAttrs$1(this, this.inputElement, {
17029
17047
  includeAttrs: [
17030
17048
  'label',
@@ -17222,20 +17240,34 @@ class RawDateFieldClass extends BaseInputClass$1 {
17222
17240
  }
17223
17241
 
17224
17242
  onFocus() {
17225
- if (this.isReadOnly) {
17243
+ if (this.isReadOnly || this.#focused) {
17226
17244
  return;
17227
17245
  }
17228
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() {
17229
17255
  if (!this.inputElement.value) {
17230
17256
  this.inputElement.value = this.format;
17231
17257
  }
17232
17258
 
17233
17259
  // On focus select the first part of the format placeholder
17234
17260
  this.selectedCounterIdx = 0;
17235
- this.setInputSelectionRange();
17261
+
17262
+ setTimeout(() => {
17263
+ // set selection on first counter
17264
+ this.inputElement.setSelectionRange(0, this.sortedCounters[0].length);
17265
+ });
17236
17266
  }
17237
17267
 
17238
17268
  onBlur() {
17269
+ this.#focused = false;
17270
+
17239
17271
  if (this.opened) {
17240
17272
  return;
17241
17273
  }
@@ -17279,7 +17311,9 @@ class RawDateFieldClass extends BaseInputClass$1 {
17279
17311
  }
17280
17312
 
17281
17313
  setSelectedCounterByCaretPosition(e) {
17282
- this.selectedCounterIdx = this.getCounterIdx(e.target.selectionStart);
17314
+ this.selectedCounterIdx = this.getCounterIdx(
17315
+ e.target.selectionStart || this.inputElement.selectionStart
17316
+ );
17283
17317
  }
17284
17318
 
17285
17319
  selectNextCounter() {
@@ -17385,7 +17419,12 @@ class RawDateFieldClass extends BaseInputClass$1 {
17385
17419
  }
17386
17420
  e.preventDefault();
17387
17421
  this.setSelectedCounterByCaretPosition(e);
17388
- 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
+ });
17389
17428
  }
17390
17429
 
17391
17430
  onInitialValueChange(val) {