@y14e/roving-tabindex 3.1.18 → 3.1.20

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/README.md CHANGED
@@ -13,11 +13,11 @@ npm i @y14e/roving-tabindex
13
13
  import { createRovingTabIndex } from '@y14e/roving-tabindex';
14
14
 
15
15
  // CDNs
16
- import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.18';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.1.20';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.18/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.1.20/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.18';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.1.20';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -366,17 +366,20 @@ var RovingTabIndex = class _RovingTabIndex {
366
366
  noStart = false;
367
367
  }
368
368
  if (selector !== "") {
369
+ let hasError = false;
369
370
  if (typeof selector !== "string" || !selector.trim()) {
370
- console.warn("Invalid selector. Fallback: no selector string.");
371
- selector = "";
371
+ hasError = true;
372
372
  } else {
373
373
  try {
374
- container.querySelector(selector);
374
+ this.#container.querySelector(selector);
375
375
  } catch {
376
- console.warn("Invalid selector. Fallback: no selector string.");
377
- selector = "";
376
+ hasError = true;
378
377
  }
379
378
  }
379
+ if (hasError) {
380
+ console.warn("Invalid selector. Fallback: no selector string.");
381
+ selector = "";
382
+ }
380
383
  }
381
384
  if (typeof typeahead !== "boolean") {
382
385
  console.warn("Invalid typeahead option. Fallback: false.");
@@ -457,20 +460,20 @@ var RovingTabIndex = class _RovingTabIndex {
457
460
  return;
458
461
  }
459
462
  }
463
+ const candidates = this.#getFocusables().filter(
464
+ (focusable2) => this.#focusables.has(focusable2)
465
+ );
460
466
  const active = getActiveElement();
461
467
  if (!(active instanceof Element)) {
462
468
  return;
463
469
  }
464
- const candidates = this.#getFocusables().filter(
465
- (focusable2) => this.#focusables.has(focusable2)
466
- );
467
470
  if (!candidates.includes(active)) {
468
471
  return;
469
472
  }
470
473
  event.preventDefault();
471
- const activeIndex = candidates.indexOf(active);
472
474
  let newIndex;
473
- let target = candidates;
475
+ const activeIndex = candidates.indexOf(active);
476
+ let focusables = candidates;
474
477
  switch (key) {
475
478
  case "End":
476
479
  newIndex = -1;
@@ -487,22 +490,24 @@ var RovingTabIndex = class _RovingTabIndex {
487
490
  case "ArrowRight":
488
491
  case "ArrowDown": {
489
492
  const rawIndex = activeIndex + 1;
490
- const length = target.length;
493
+ const length = focusables.length;
491
494
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
492
495
  break;
493
496
  }
494
497
  default: {
495
- const focusables = new Set(
498
+ const focusablesByFirstChar = new Set(
496
499
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
497
500
  );
498
- target = candidates.filter((focusable2) => focusables.has(focusable2));
499
- const afterIndex = target.findIndex(
501
+ focusables = candidates.filter(
502
+ (candidate) => focusablesByFirstChar.has(candidate)
503
+ );
504
+ const afterIndex = focusables.findIndex(
500
505
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
501
506
  );
502
507
  newIndex = afterIndex >= 0 ? afterIndex : 0;
503
508
  }
504
509
  }
505
- const focusable = target.at(newIndex);
510
+ const focusable = focusables.at(newIndex);
506
511
  focusable && focusElement(focusable);
507
512
  };
508
513
  #update(active) {
@@ -586,7 +591,7 @@ var RovingTabIndex = class _RovingTabIndex {
586
591
  * Lightweight roving tabindex utility with fully focus management.
587
592
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
588
593
  *
589
- * @version 3.1.18
594
+ * @version 3.1.20
590
595
  * @author Yusuke Kamiyamane
591
596
  * @license MIT
592
597
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -364,17 +364,20 @@ var RovingTabIndex = class _RovingTabIndex {
364
364
  noStart = false;
365
365
  }
366
366
  if (selector !== "") {
367
+ let hasError = false;
367
368
  if (typeof selector !== "string" || !selector.trim()) {
368
- console.warn("Invalid selector. Fallback: no selector string.");
369
- selector = "";
369
+ hasError = true;
370
370
  } else {
371
371
  try {
372
- container.querySelector(selector);
372
+ this.#container.querySelector(selector);
373
373
  } catch {
374
- console.warn("Invalid selector. Fallback: no selector string.");
375
- selector = "";
374
+ hasError = true;
376
375
  }
377
376
  }
377
+ if (hasError) {
378
+ console.warn("Invalid selector. Fallback: no selector string.");
379
+ selector = "";
380
+ }
378
381
  }
379
382
  if (typeof typeahead !== "boolean") {
380
383
  console.warn("Invalid typeahead option. Fallback: false.");
@@ -455,20 +458,20 @@ var RovingTabIndex = class _RovingTabIndex {
455
458
  return;
456
459
  }
457
460
  }
461
+ const candidates = this.#getFocusables().filter(
462
+ (focusable2) => this.#focusables.has(focusable2)
463
+ );
458
464
  const active = getActiveElement();
459
465
  if (!(active instanceof Element)) {
460
466
  return;
461
467
  }
462
- const candidates = this.#getFocusables().filter(
463
- (focusable2) => this.#focusables.has(focusable2)
464
- );
465
468
  if (!candidates.includes(active)) {
466
469
  return;
467
470
  }
468
471
  event.preventDefault();
469
- const activeIndex = candidates.indexOf(active);
470
472
  let newIndex;
471
- let target = candidates;
473
+ const activeIndex = candidates.indexOf(active);
474
+ let focusables = candidates;
472
475
  switch (key) {
473
476
  case "End":
474
477
  newIndex = -1;
@@ -485,22 +488,24 @@ var RovingTabIndex = class _RovingTabIndex {
485
488
  case "ArrowRight":
486
489
  case "ArrowDown": {
487
490
  const rawIndex = activeIndex + 1;
488
- const length = target.length;
491
+ const length = focusables.length;
489
492
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
490
493
  break;
491
494
  }
492
495
  default: {
493
- const focusables = new Set(
496
+ const focusablesByFirstChar = new Set(
494
497
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
495
498
  );
496
- target = candidates.filter((focusable2) => focusables.has(focusable2));
497
- const afterIndex = target.findIndex(
499
+ focusables = candidates.filter(
500
+ (candidate) => focusablesByFirstChar.has(candidate)
501
+ );
502
+ const afterIndex = focusables.findIndex(
498
503
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
499
504
  );
500
505
  newIndex = afterIndex >= 0 ? afterIndex : 0;
501
506
  }
502
507
  }
503
- const focusable = target.at(newIndex);
508
+ const focusable = focusables.at(newIndex);
504
509
  focusable && focusElement(focusable);
505
510
  };
506
511
  #update(active) {
@@ -584,7 +589,7 @@ var RovingTabIndex = class _RovingTabIndex {
584
589
  * Lightweight roving tabindex utility with fully focus management.
585
590
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
586
591
  *
587
- * @version 3.1.18
592
+ * @version 3.1.20
588
593
  * @author Yusuke Kamiyamane
589
594
  * @license MIT
590
595
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -50,17 +50,20 @@ var RovingTabIndex = class _RovingTabIndex {
50
50
  noStart = false;
51
51
  }
52
52
  if (selector !== "") {
53
+ let hasError = false;
53
54
  if (typeof selector !== "string" || !selector.trim()) {
54
- console.warn("Invalid selector. Fallback: no selector string.");
55
- selector = "";
55
+ hasError = true;
56
56
  } else {
57
57
  try {
58
- container.querySelector(selector);
58
+ this.#container.querySelector(selector);
59
59
  } catch {
60
- console.warn("Invalid selector. Fallback: no selector string.");
61
- selector = "";
60
+ hasError = true;
62
61
  }
63
62
  }
63
+ if (hasError) {
64
+ console.warn("Invalid selector. Fallback: no selector string.");
65
+ selector = "";
66
+ }
64
67
  }
65
68
  if (typeof typeahead !== "boolean") {
66
69
  console.warn("Invalid typeahead option. Fallback: false.");
@@ -141,20 +144,20 @@ var RovingTabIndex = class _RovingTabIndex {
141
144
  return;
142
145
  }
143
146
  }
147
+ const candidates = this.#getFocusables().filter(
148
+ (focusable2) => this.#focusables.has(focusable2)
149
+ );
144
150
  const active = powerFocusable.getActiveElement();
145
151
  if (!(active instanceof Element)) {
146
152
  return;
147
153
  }
148
- const candidates = this.#getFocusables().filter(
149
- (focusable2) => this.#focusables.has(focusable2)
150
- );
151
154
  if (!candidates.includes(active)) {
152
155
  return;
153
156
  }
154
157
  event.preventDefault();
155
- const activeIndex = candidates.indexOf(active);
156
158
  let newIndex;
157
- let target = candidates;
159
+ const activeIndex = candidates.indexOf(active);
160
+ let focusables = candidates;
158
161
  switch (key) {
159
162
  case "End":
160
163
  newIndex = -1;
@@ -171,22 +174,24 @@ var RovingTabIndex = class _RovingTabIndex {
171
174
  case "ArrowRight":
172
175
  case "ArrowDown": {
173
176
  const rawIndex = activeIndex + 1;
174
- const length = target.length;
177
+ const length = focusables.length;
175
178
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
176
179
  break;
177
180
  }
178
181
  default: {
179
- const focusables = new Set(
182
+ const focusablesByFirstChar = new Set(
180
183
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
181
184
  );
182
- target = candidates.filter((focusable2) => focusables.has(focusable2));
183
- const afterIndex = target.findIndex(
185
+ focusables = candidates.filter(
186
+ (candidate) => focusablesByFirstChar.has(candidate)
187
+ );
188
+ const afterIndex = focusables.findIndex(
184
189
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
185
190
  );
186
191
  newIndex = afterIndex >= 0 ? afterIndex : 0;
187
192
  }
188
193
  }
189
- const focusable = target.at(newIndex);
194
+ const focusable = focusables.at(newIndex);
190
195
  focusable && powerFocusable.focusElement(focusable);
191
196
  };
192
197
  #update(active) {
@@ -270,7 +275,7 @@ var RovingTabIndex = class _RovingTabIndex {
270
275
  * Lightweight roving tabindex utility with fully focus management.
271
276
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
272
277
  *
273
- * @version 3.1.18
278
+ * @version 3.1.20
274
279
  * @author Yusuke Kamiyamane
275
280
  * @license MIT
276
281
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight roving tabindex utility with fully focus management.
4
4
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
5
5
  *
6
- * @version 3.1.18
6
+ * @version 3.1.20
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight roving tabindex utility with fully focus management.
4
4
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
5
5
  *
6
- * @version 3.1.18
6
+ * @version 3.1.20
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -48,17 +48,20 @@ var RovingTabIndex = class _RovingTabIndex {
48
48
  noStart = false;
49
49
  }
50
50
  if (selector !== "") {
51
+ let hasError = false;
51
52
  if (typeof selector !== "string" || !selector.trim()) {
52
- console.warn("Invalid selector. Fallback: no selector string.");
53
- selector = "";
53
+ hasError = true;
54
54
  } else {
55
55
  try {
56
- container.querySelector(selector);
56
+ this.#container.querySelector(selector);
57
57
  } catch {
58
- console.warn("Invalid selector. Fallback: no selector string.");
59
- selector = "";
58
+ hasError = true;
60
59
  }
61
60
  }
61
+ if (hasError) {
62
+ console.warn("Invalid selector. Fallback: no selector string.");
63
+ selector = "";
64
+ }
62
65
  }
63
66
  if (typeof typeahead !== "boolean") {
64
67
  console.warn("Invalid typeahead option. Fallback: false.");
@@ -139,20 +142,20 @@ var RovingTabIndex = class _RovingTabIndex {
139
142
  return;
140
143
  }
141
144
  }
145
+ const candidates = this.#getFocusables().filter(
146
+ (focusable2) => this.#focusables.has(focusable2)
147
+ );
142
148
  const active = getActiveElement();
143
149
  if (!(active instanceof Element)) {
144
150
  return;
145
151
  }
146
- const candidates = this.#getFocusables().filter(
147
- (focusable2) => this.#focusables.has(focusable2)
148
- );
149
152
  if (!candidates.includes(active)) {
150
153
  return;
151
154
  }
152
155
  event.preventDefault();
153
- const activeIndex = candidates.indexOf(active);
154
156
  let newIndex;
155
- let target = candidates;
157
+ const activeIndex = candidates.indexOf(active);
158
+ let focusables = candidates;
156
159
  switch (key) {
157
160
  case "End":
158
161
  newIndex = -1;
@@ -169,22 +172,24 @@ var RovingTabIndex = class _RovingTabIndex {
169
172
  case "ArrowRight":
170
173
  case "ArrowDown": {
171
174
  const rawIndex = activeIndex + 1;
172
- const length = target.length;
175
+ const length = focusables.length;
173
176
  newIndex = wrap ? rawIndex % length : Math.min(rawIndex, length - 1);
174
177
  break;
175
178
  }
176
179
  default: {
177
- const focusables = new Set(
180
+ const focusablesByFirstChar = new Set(
178
181
  this.#focusablesByFirstChar.get(key.toUpperCase()) ?? []
179
182
  );
180
- target = candidates.filter((focusable2) => focusables.has(focusable2));
181
- const afterIndex = target.findIndex(
183
+ focusables = candidates.filter(
184
+ (candidate) => focusablesByFirstChar.has(candidate)
185
+ );
186
+ const afterIndex = focusables.findIndex(
182
187
  (focusable2) => candidates.indexOf(focusable2) > activeIndex
183
188
  );
184
189
  newIndex = afterIndex >= 0 ? afterIndex : 0;
185
190
  }
186
191
  }
187
- const focusable = target.at(newIndex);
192
+ const focusable = focusables.at(newIndex);
188
193
  focusable && focusElement(focusable);
189
194
  };
190
195
  #update(active) {
@@ -268,7 +273,7 @@ var RovingTabIndex = class _RovingTabIndex {
268
273
  * Lightweight roving tabindex utility with fully focus management.
269
274
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
270
275
  *
271
- * @version 3.1.18
276
+ * @version 3.1.20
272
277
  * @author Yusuke Kamiyamane
273
278
  * @license MIT
274
279
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "3.1.18",
3
+ "version": "3.1.20",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",