@idds/js 1.2.2 → 1.2.3
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/dist/index.iife.js +71 -28
- package/dist/index.js +71 -28
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -297,6 +297,7 @@ var InaUI = (() => {
|
|
|
297
297
|
this.index = this.group.registerItem(this);
|
|
298
298
|
}
|
|
299
299
|
this.toggle.addEventListener("click", (e) => this.handleClick(e));
|
|
300
|
+
this.toggle.addEventListener("keydown", (e) => this.handleKeyDown(e));
|
|
300
301
|
if (this.group) {
|
|
301
302
|
const isOpen = this.group.isItemOpen(this.index);
|
|
302
303
|
this.setOpenState(isOpen);
|
|
@@ -325,6 +326,22 @@ var InaUI = (() => {
|
|
|
325
326
|
this.setOpenState(nextState);
|
|
326
327
|
}
|
|
327
328
|
}
|
|
329
|
+
handleKeyDown(e) {
|
|
330
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
331
|
+
e.preventDefault();
|
|
332
|
+
const currentAccordion = this.element;
|
|
333
|
+
const container = currentAccordion.closest(".ina-accordion-group") || currentAccordion.parentElement;
|
|
334
|
+
if (!container) return;
|
|
335
|
+
const toggles = Array.from(
|
|
336
|
+
container.querySelectorAll(".ina-accordion__toggle:not([disabled])")
|
|
337
|
+
);
|
|
338
|
+
const currentIndex = toggles.indexOf(this.toggle);
|
|
339
|
+
if (currentIndex > -1) {
|
|
340
|
+
const nextIndex = e.key === "ArrowDown" ? (currentIndex + 1) % toggles.length : (currentIndex - 1 + toggles.length) % toggles.length;
|
|
341
|
+
toggles[nextIndex]?.focus();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
328
345
|
setOpenState(isOpen) {
|
|
329
346
|
if (isOpen) {
|
|
330
347
|
this.element.classList.add(`${PREFIX}-accordion--open`);
|
|
@@ -3114,6 +3131,10 @@ var InaUI = (() => {
|
|
|
3114
3131
|
if (!normSelected.includes(finalValue)) {
|
|
3115
3132
|
normSelected.push(finalValue);
|
|
3116
3133
|
}
|
|
3134
|
+
} else {
|
|
3135
|
+
if (toggleVal) {
|
|
3136
|
+
normSelected = normSelected.filter((v) => v !== toggleVal);
|
|
3137
|
+
}
|
|
3117
3138
|
}
|
|
3118
3139
|
if (isMultiple) {
|
|
3119
3140
|
selectedValue = normSelected.join(",");
|
|
@@ -3134,38 +3155,12 @@ var InaUI = (() => {
|
|
|
3134
3155
|
const val = item.getAttribute("data-value");
|
|
3135
3156
|
if (showCustomization && isToggleBtn(item)) {
|
|
3136
3157
|
const normSelected = getNormalizedSelected();
|
|
3137
|
-
let newSelected = [...normSelected];
|
|
3138
3158
|
const standardValues = Array.from(items).filter((i) => !isToggleBtn(i)).map((i) => i.getAttribute("data-value"));
|
|
3139
3159
|
const customValues = normSelected.filter(
|
|
3140
3160
|
(v) => !standardValues.includes(v) && v !== "" && v !== val
|
|
3141
3161
|
);
|
|
3142
|
-
const primaryCustomValue = customValues[customValues.length - 1];
|
|
3143
3162
|
const isInputVisible = normSelected.includes(val) || customValues.length > 0;
|
|
3144
|
-
if (isInputVisible) {
|
|
3145
|
-
newSelected = newSelected.filter((v) => v !== val);
|
|
3146
|
-
if (primaryCustomValue) {
|
|
3147
|
-
if (isMultiple) {
|
|
3148
|
-
newSelected = newSelected.filter(
|
|
3149
|
-
(v) => v !== primaryCustomValue
|
|
3150
|
-
);
|
|
3151
|
-
} else {
|
|
3152
|
-
newSelected = [];
|
|
3153
|
-
}
|
|
3154
|
-
}
|
|
3155
|
-
if (isMultiple) {
|
|
3156
|
-
selectedValue = newSelected.join(",");
|
|
3157
|
-
} else {
|
|
3158
|
-
selectedValue = newSelected.length ? newSelected[0] : "";
|
|
3159
|
-
}
|
|
3160
|
-
updateUI();
|
|
3161
|
-
const changeEvent = new CustomEvent(`${PREFIX4}-chip:change`, {
|
|
3162
|
-
detail: {
|
|
3163
|
-
value: isMultiple ? getNormalizedSelected() : selectedValue
|
|
3164
|
-
},
|
|
3165
|
-
bubbles: true
|
|
3166
|
-
});
|
|
3167
|
-
container.dispatchEvent(changeEvent);
|
|
3168
|
-
} else {
|
|
3163
|
+
if (!isInputVisible) {
|
|
3169
3164
|
handleSelect(val);
|
|
3170
3165
|
}
|
|
3171
3166
|
} else {
|
|
@@ -3385,6 +3380,28 @@ var InaUI = (() => {
|
|
|
3385
3380
|
lastBtn.addEventListener("click", () => {
|
|
3386
3381
|
if (!isDisabled && currentPage < totalPages) goToPage(totalPages);
|
|
3387
3382
|
});
|
|
3383
|
+
if (navButtonsContainer && !navButtonsContainer.__inaKeyboardSet) {
|
|
3384
|
+
navButtonsContainer.addEventListener("keydown", (e) => {
|
|
3385
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
3386
|
+
const focusable = Array.from(
|
|
3387
|
+
navButtonsContainer.querySelectorAll("button:not([disabled])")
|
|
3388
|
+
);
|
|
3389
|
+
if (!focusable.length) return;
|
|
3390
|
+
const currentIndex = focusable.indexOf(document.activeElement);
|
|
3391
|
+
if (currentIndex >= 0) {
|
|
3392
|
+
e.preventDefault();
|
|
3393
|
+
const nextIndex = e.key === "ArrowRight" ? (currentIndex + 1) % focusable.length : (currentIndex - 1 + focusable.length) % focusable.length;
|
|
3394
|
+
focusable[nextIndex]?.focus();
|
|
3395
|
+
}
|
|
3396
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
3397
|
+
if (document.activeElement && document.activeElement.tagName === "BUTTON") {
|
|
3398
|
+
e.preventDefault();
|
|
3399
|
+
document.activeElement.click();
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
});
|
|
3403
|
+
navButtonsContainer.__inaKeyboardSet = true;
|
|
3404
|
+
}
|
|
3388
3405
|
if (pageSizeSelect) {
|
|
3389
3406
|
pageSizeSelect.addEventListener("change", (e) => {
|
|
3390
3407
|
if (isDisabled) return;
|
|
@@ -4589,13 +4606,39 @@ var InaUI = (() => {
|
|
|
4589
4606
|
})
|
|
4590
4607
|
);
|
|
4591
4608
|
};
|
|
4592
|
-
buttons.forEach((button) => {
|
|
4609
|
+
buttons.forEach((button, index2) => {
|
|
4593
4610
|
button.addEventListener("click", (e) => {
|
|
4594
4611
|
if (button.type !== "submit") {
|
|
4595
4612
|
e.preventDefault();
|
|
4596
4613
|
}
|
|
4597
4614
|
updateState(button);
|
|
4598
4615
|
});
|
|
4616
|
+
button.addEventListener("keydown", (e) => {
|
|
4617
|
+
const isDisabled = button.hasAttribute("disabled") || button.classList.contains(`${PREFIX}-button-group__button--disabled`);
|
|
4618
|
+
if (isDisabled) return;
|
|
4619
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4620
|
+
e.preventDefault();
|
|
4621
|
+
updateState(button);
|
|
4622
|
+
} else if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
4623
|
+
e.preventDefault();
|
|
4624
|
+
let nextIndex = (index2 + 1) % buttons.length;
|
|
4625
|
+
while ((buttons[nextIndex].hasAttribute("disabled") || buttons[nextIndex].classList.contains(
|
|
4626
|
+
`${PREFIX}-button-group__button--disabled`
|
|
4627
|
+
)) && nextIndex !== index2) {
|
|
4628
|
+
nextIndex = (nextIndex + 1) % buttons.length;
|
|
4629
|
+
}
|
|
4630
|
+
buttons[nextIndex]?.focus();
|
|
4631
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
4632
|
+
e.preventDefault();
|
|
4633
|
+
let prevIndex = (index2 - 1 + buttons.length) % buttons.length;
|
|
4634
|
+
while ((buttons[prevIndex].hasAttribute("disabled") || buttons[prevIndex].classList.contains(
|
|
4635
|
+
`${PREFIX}-button-group__button--disabled`
|
|
4636
|
+
)) && prevIndex !== index2) {
|
|
4637
|
+
prevIndex = (prevIndex - 1 + buttons.length) % buttons.length;
|
|
4638
|
+
}
|
|
4639
|
+
buttons[prevIndex]?.focus();
|
|
4640
|
+
}
|
|
4641
|
+
});
|
|
4599
4642
|
});
|
|
4600
4643
|
buttonGroup.__inaButtonGroupInitialized = true;
|
|
4601
4644
|
});
|
package/dist/index.js
CHANGED
|
@@ -29,13 +29,39 @@ function initButtonGroup(rootSelector = `.${PREFIX}-button-group`) {
|
|
|
29
29
|
})
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
|
-
buttons.forEach((button) => {
|
|
32
|
+
buttons.forEach((button, index2) => {
|
|
33
33
|
button.addEventListener("click", (e) => {
|
|
34
34
|
if (button.type !== "submit") {
|
|
35
35
|
e.preventDefault();
|
|
36
36
|
}
|
|
37
37
|
updateState(button);
|
|
38
38
|
});
|
|
39
|
+
button.addEventListener("keydown", (e) => {
|
|
40
|
+
const isDisabled = button.hasAttribute("disabled") || button.classList.contains(`${PREFIX}-button-group__button--disabled`);
|
|
41
|
+
if (isDisabled) return;
|
|
42
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
updateState(button);
|
|
45
|
+
} else if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
let nextIndex = (index2 + 1) % buttons.length;
|
|
48
|
+
while ((buttons[nextIndex].hasAttribute("disabled") || buttons[nextIndex].classList.contains(
|
|
49
|
+
`${PREFIX}-button-group__button--disabled`
|
|
50
|
+
)) && nextIndex !== index2) {
|
|
51
|
+
nextIndex = (nextIndex + 1) % buttons.length;
|
|
52
|
+
}
|
|
53
|
+
buttons[nextIndex]?.focus();
|
|
54
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
let prevIndex = (index2 - 1 + buttons.length) % buttons.length;
|
|
57
|
+
while ((buttons[prevIndex].hasAttribute("disabled") || buttons[prevIndex].classList.contains(
|
|
58
|
+
`${PREFIX}-button-group__button--disabled`
|
|
59
|
+
)) && prevIndex !== index2) {
|
|
60
|
+
prevIndex = (prevIndex - 1 + buttons.length) % buttons.length;
|
|
61
|
+
}
|
|
62
|
+
buttons[prevIndex]?.focus();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
39
65
|
});
|
|
40
66
|
buttonGroup.__inaButtonGroupInitialized = true;
|
|
41
67
|
});
|
|
@@ -285,6 +311,7 @@ var Accordion = class {
|
|
|
285
311
|
this.index = this.group.registerItem(this);
|
|
286
312
|
}
|
|
287
313
|
this.toggle.addEventListener("click", (e) => this.handleClick(e));
|
|
314
|
+
this.toggle.addEventListener("keydown", (e) => this.handleKeyDown(e));
|
|
288
315
|
if (this.group) {
|
|
289
316
|
const isOpen = this.group.isItemOpen(this.index);
|
|
290
317
|
this.setOpenState(isOpen);
|
|
@@ -313,6 +340,22 @@ var Accordion = class {
|
|
|
313
340
|
this.setOpenState(nextState);
|
|
314
341
|
}
|
|
315
342
|
}
|
|
343
|
+
handleKeyDown(e) {
|
|
344
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
345
|
+
e.preventDefault();
|
|
346
|
+
const currentAccordion = this.element;
|
|
347
|
+
const container = currentAccordion.closest(".ina-accordion-group") || currentAccordion.parentElement;
|
|
348
|
+
if (!container) return;
|
|
349
|
+
const toggles = Array.from(
|
|
350
|
+
container.querySelectorAll(".ina-accordion__toggle:not([disabled])")
|
|
351
|
+
);
|
|
352
|
+
const currentIndex = toggles.indexOf(this.toggle);
|
|
353
|
+
if (currentIndex > -1) {
|
|
354
|
+
const nextIndex = e.key === "ArrowDown" ? (currentIndex + 1) % toggles.length : (currentIndex - 1 + toggles.length) % toggles.length;
|
|
355
|
+
toggles[nextIndex]?.focus();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
316
359
|
setOpenState(isOpen) {
|
|
317
360
|
if (isOpen) {
|
|
318
361
|
this.element.classList.add(`${PREFIX}-accordion--open`);
|
|
@@ -3194,6 +3237,10 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3194
3237
|
if (!normSelected.includes(finalValue)) {
|
|
3195
3238
|
normSelected.push(finalValue);
|
|
3196
3239
|
}
|
|
3240
|
+
} else {
|
|
3241
|
+
if (toggleVal) {
|
|
3242
|
+
normSelected = normSelected.filter((v) => v !== toggleVal);
|
|
3243
|
+
}
|
|
3197
3244
|
}
|
|
3198
3245
|
if (isMultiple) {
|
|
3199
3246
|
selectedValue = normSelected.join(",");
|
|
@@ -3214,38 +3261,12 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3214
3261
|
const val = item.getAttribute("data-value");
|
|
3215
3262
|
if (showCustomization && isToggleBtn(item)) {
|
|
3216
3263
|
const normSelected = getNormalizedSelected();
|
|
3217
|
-
let newSelected = [...normSelected];
|
|
3218
3264
|
const standardValues = Array.from(items).filter((i) => !isToggleBtn(i)).map((i) => i.getAttribute("data-value"));
|
|
3219
3265
|
const customValues = normSelected.filter(
|
|
3220
3266
|
(v) => !standardValues.includes(v) && v !== "" && v !== val
|
|
3221
3267
|
);
|
|
3222
|
-
const primaryCustomValue = customValues[customValues.length - 1];
|
|
3223
3268
|
const isInputVisible = normSelected.includes(val) || customValues.length > 0;
|
|
3224
|
-
if (isInputVisible) {
|
|
3225
|
-
newSelected = newSelected.filter((v) => v !== val);
|
|
3226
|
-
if (primaryCustomValue) {
|
|
3227
|
-
if (isMultiple) {
|
|
3228
|
-
newSelected = newSelected.filter(
|
|
3229
|
-
(v) => v !== primaryCustomValue
|
|
3230
|
-
);
|
|
3231
|
-
} else {
|
|
3232
|
-
newSelected = [];
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
if (isMultiple) {
|
|
3236
|
-
selectedValue = newSelected.join(",");
|
|
3237
|
-
} else {
|
|
3238
|
-
selectedValue = newSelected.length ? newSelected[0] : "";
|
|
3239
|
-
}
|
|
3240
|
-
updateUI();
|
|
3241
|
-
const changeEvent = new CustomEvent(`${PREFIX5}-chip:change`, {
|
|
3242
|
-
detail: {
|
|
3243
|
-
value: isMultiple ? getNormalizedSelected() : selectedValue
|
|
3244
|
-
},
|
|
3245
|
-
bubbles: true
|
|
3246
|
-
});
|
|
3247
|
-
container.dispatchEvent(changeEvent);
|
|
3248
|
-
} else {
|
|
3269
|
+
if (!isInputVisible) {
|
|
3249
3270
|
handleSelect(val);
|
|
3250
3271
|
}
|
|
3251
3272
|
} else {
|
|
@@ -3465,6 +3486,28 @@ function initPagination() {
|
|
|
3465
3486
|
lastBtn.addEventListener("click", () => {
|
|
3466
3487
|
if (!isDisabled && currentPage < totalPages) goToPage(totalPages);
|
|
3467
3488
|
});
|
|
3489
|
+
if (navButtonsContainer && !navButtonsContainer.__inaKeyboardSet) {
|
|
3490
|
+
navButtonsContainer.addEventListener("keydown", (e) => {
|
|
3491
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
3492
|
+
const focusable = Array.from(
|
|
3493
|
+
navButtonsContainer.querySelectorAll("button:not([disabled])")
|
|
3494
|
+
);
|
|
3495
|
+
if (!focusable.length) return;
|
|
3496
|
+
const currentIndex = focusable.indexOf(document.activeElement);
|
|
3497
|
+
if (currentIndex >= 0) {
|
|
3498
|
+
e.preventDefault();
|
|
3499
|
+
const nextIndex = e.key === "ArrowRight" ? (currentIndex + 1) % focusable.length : (currentIndex - 1 + focusable.length) % focusable.length;
|
|
3500
|
+
focusable[nextIndex]?.focus();
|
|
3501
|
+
}
|
|
3502
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
3503
|
+
if (document.activeElement && document.activeElement.tagName === "BUTTON") {
|
|
3504
|
+
e.preventDefault();
|
|
3505
|
+
document.activeElement.click();
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
});
|
|
3509
|
+
navButtonsContainer.__inaKeyboardSet = true;
|
|
3510
|
+
}
|
|
3468
3511
|
if (pageSizeSelect) {
|
|
3469
3512
|
pageSizeSelect.addEventListener("change", (e) => {
|
|
3470
3513
|
if (isDisabled) return;
|