@georapbox/files-dropzone-element 1.2.1 → 2.0.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.
@@ -62,13 +62,10 @@ const styles = /* css */`
62
62
  transition: border var(--dropzone-transition-duration) ease-in-out, background-color var(--dropzone-transition-duration) ease-in-out, color var(--dropzone-transition-duration) ease-in-out, box-shadow var(--dropzone-transition-duration) ease-in-out;
63
63
  }
64
64
 
65
- :host(:not([no-style])[no-click]) .dropzone {
66
- cursor: default;
67
- }
68
-
69
65
  :host(:not([no-style])[disabled]) .dropzone {
70
66
  opacity: 0.8;
71
67
  cursor: not-allowed;
68
+ user-select: none;
72
69
  }
73
70
 
74
71
  :host(:not([no-style]):not([disabled])) .dropzone--dragover {
@@ -96,9 +93,9 @@ template.innerHTML = /* html */`
96
93
  ${styles}
97
94
  </style>
98
95
 
99
- <input type="file" id="fileInput" hidden>
96
+ <input type="file" id="file-input" hidden>
100
97
 
101
- <div part="dropzone" class="dropzone" id="dropzoneEl" tabindex="0" role="presentation">
98
+ <div part="dropzone" class="dropzone" id="dropzone" tabindex="0" role="button" aria-disabled="false">
102
99
  <slot>Drag 'n' drop files here, or click to select files</slot>
103
100
  </div>
104
101
  `;
@@ -115,9 +112,6 @@ template.innerHTML = /* html */`
115
112
  * @property {number} maxSize - The maximum file size allowed in bytes.
116
113
  * @property {number} minSize - The minimum file size allowed in bytes.
117
114
  * @property {boolean} multiple - Allows multiple files to be dropped.
118
- * @property {boolean} noClick - Prevents the file dialog from opening when the dropzone is clicked.
119
- * @property {boolean} noDrag - Prevents the dropzone from reacting to drag events.
120
- * @property {boolean} noKeyboard - Prevents the dropzone from reacting to keyboard events.
121
115
  * @property {boolean} autoFocus - Automatically focuses the dropzone when it's connected to the DOM.
122
116
  * @property {boolean} noStyle - Prevents the dropzone from applying any styling.
123
117
  *
@@ -127,9 +121,6 @@ template.innerHTML = /* html */`
127
121
  * @attribute {number} max-size - Reflects the maxSize property.
128
122
  * @attribute {number} min-size - Reflects the minSize property.
129
123
  * @attribute {boolean} multiple - Reflects the multiple property.
130
- * @attribute {boolean} no-click - Reflects the noClick property.
131
- * @attribute {boolean} no-drag - Reflects the noDrag property.
132
- * @attribute {boolean} no-keyboard - Reflects the noKeyboard property.
133
124
  * @attribute {boolean} auto-focus - Reflects the autoFocus property.
134
125
  * @attribute {boolean} no-style - Reflects the noStyle property.
135
126
  *
@@ -176,18 +167,18 @@ class FilesDropzone extends HTMLElement {
176
167
  super();
177
168
 
178
169
  if (!this.shadowRoot) {
179
- const shadowRoot = this.attachShadow({ mode: 'open' });
170
+ const shadowRoot = this.attachShadow({ mode: 'open', delegatesFocus: true });
180
171
  shadowRoot.appendChild(template.content.cloneNode(true));
181
172
  }
182
173
 
183
174
  if (this.shadowRoot) {
184
- this.#fileInput = /** @type {Nullable<HTMLInputElement>} */(this.shadowRoot.getElementById('fileInput'));
185
- this.#dropzoneEl = this.shadowRoot.getElementById('dropzoneEl');
175
+ this.#fileInput = /** @type {Nullable<HTMLInputElement>} */(this.shadowRoot.getElementById('file-input'));
176
+ this.#dropzoneEl = this.shadowRoot.getElementById('dropzone');
186
177
  }
187
178
  }
188
179
 
189
180
  static get observedAttributes() {
190
- return ['accept', 'disabled', 'multiple', 'no-keyboard'];
181
+ return ['accept', 'disabled', 'multiple'];
191
182
  }
192
183
 
193
184
  /**
@@ -207,22 +198,16 @@ class FilesDropzone extends HTMLElement {
207
198
 
208
199
  if (this.disabled) {
209
200
  this.#dropzoneEl?.removeAttribute('tabindex');
201
+ this.#dropzoneEl?.setAttribute('aria-disabled', 'true');
210
202
  } else {
211
203
  this.#dropzoneEl?.setAttribute('tabindex', '0');
204
+ this.#dropzoneEl?.setAttribute('aria-disabled', 'false');
212
205
  }
213
206
  }
214
207
 
215
208
  if (name === 'multiple' && oldValue !== newValue && this.#fileInput) {
216
209
  this.#fileInput.multiple = this.multiple;
217
210
  }
218
-
219
- if (name === 'no-keyboard' && oldValue !== newValue && this.#dropzoneEl) {
220
- if (this.noKeyboard) {
221
- this.#dropzoneEl.removeAttribute('tabindex');
222
- } else {
223
- this.#dropzoneEl.setAttribute('tabindex', '0');
224
- }
225
- }
226
211
  }
227
212
 
228
213
  /**
@@ -235,9 +220,6 @@ class FilesDropzone extends HTMLElement {
235
220
  this.#upgradeProperty('maxSize');
236
221
  this.#upgradeProperty('minSize');
237
222
  this.#upgradeProperty('multiple');
238
- this.#upgradeProperty('noClick');
239
- this.#upgradeProperty('noDrag');
240
- this.#upgradeProperty('noKeyboard');
241
223
  this.#upgradeProperty('autoFocus');
242
224
  this.#upgradeProperty('noStyle');
243
225
 
@@ -364,45 +346,6 @@ class FilesDropzone extends HTMLElement {
364
346
  this.toggleAttribute('multiple', !!value);
365
347
  }
366
348
 
367
- /**
368
- * @type {boolean} - Prevents the file dialog from opening when the dropzone is clicked.
369
- * @default false
370
- * @attribute no-click - Reflects the noClick property.
371
- */
372
- get noClick() {
373
- return this.hasAttribute('no-click');
374
- }
375
-
376
- set noClick(value) {
377
- this.toggleAttribute('no-click', !!value);
378
- }
379
-
380
- /**
381
- * @type {boolean} - Prevents the dropzone from reacting to drag events.
382
- * @default false
383
- * @attribute no-drag - Reflects the noDrag property.
384
- */
385
- get noDrag() {
386
- return this.hasAttribute('no-drag');
387
- }
388
-
389
- set noDrag(value) {
390
- this.toggleAttribute('no-drag', !!value);
391
- }
392
-
393
- /**
394
- * @type {boolean} - Prevents the dropzone from reacting to keyboard events.
395
- * @default false
396
- * @attribute no-keyboard - Reflects the noKeyboard property.
397
- */
398
- get noKeyboard() {
399
- return this.hasAttribute('no-keyboard');
400
- }
401
-
402
- set noKeyboard(value) {
403
- this.toggleAttribute('no-keyboard', !!value);
404
- }
405
-
406
349
  /**
407
350
  * @type {boolean} - Automatically focuses the dropzone when it's connected to the DOM.
408
351
  * @default false
@@ -450,7 +393,7 @@ class FilesDropzone extends HTMLElement {
450
393
  * Handles the dragenter event of the dropzone.
451
394
  */
452
395
  #handleDragEnter = () => {
453
- if (this.disabled || this.noDrag) {
396
+ if (this.disabled) {
454
397
  return;
455
398
  }
456
399
 
@@ -468,7 +411,7 @@ class FilesDropzone extends HTMLElement {
468
411
  #handleDragOver = evt => {
469
412
  evt.preventDefault();
470
413
 
471
- if (this.disabled || this.noDrag) {
414
+ if (this.disabled) {
472
415
  evt.dataTransfer.dropEffect = 'none';
473
416
  return;
474
417
  }
@@ -490,7 +433,7 @@ class FilesDropzone extends HTMLElement {
490
433
  * Handles the dragleave event of the dropzone.
491
434
  */
492
435
  #handleDragLeave = () => {
493
- if (this.disabled || this.noDrag) {
436
+ if (this.disabled) {
494
437
  return;
495
438
  }
496
439
 
@@ -511,7 +454,7 @@ class FilesDropzone extends HTMLElement {
511
454
  * @param {*} evt - The event object.
512
455
  */
513
456
  #handleDrop = async evt => {
514
- if (this.disabled || this.noDrag) {
457
+ if (this.disabled) {
515
458
  return;
516
459
  }
517
460
 
@@ -537,7 +480,7 @@ class FilesDropzone extends HTMLElement {
537
480
  * Handles the click event of the dropzone.
538
481
  */
539
482
  #handleClick = () => {
540
- if (this.disabled || this.noClick) {
483
+ if (this.disabled) {
541
484
  return;
542
485
  }
543
486
 
@@ -550,7 +493,7 @@ class FilesDropzone extends HTMLElement {
550
493
  * @param {*} evt - The event object.
551
494
  */
552
495
  #handleKeyUp = evt => {
553
- if (this.disabled || this.noKeyboard) {
496
+ if (this.disabled) {
554
497
  return;
555
498
  }
556
499
 
@@ -687,7 +630,7 @@ class FilesDropzone extends HTMLElement {
687
630
  *
688
631
  * https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
689
632
  *
690
- * @param {'accept' | 'disabled' | 'maxFiles' | 'maxSize' | 'minSize' | 'multiple' | 'noClick' | 'noDrag' | 'noKeyboard' | 'autoFocus' | 'noStyle'} prop - The property name to upgrade.
633
+ * @param {'accept' | 'disabled' | 'maxFiles' | 'maxSize' | 'minSize' | 'multiple' | 'autoFocus' | 'noStyle'} prop - The property name to upgrade.
691
634
  */
692
635
  #upgradeProperty(prop) {
693
636
  /** @type {any} */