@human-kit/svelte-components 1.0.0-alpha.12 → 1.0.0-alpha.14
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/checkbox/root/checkbox-root.svelte +22 -2
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +4 -1
- package/dist/combobox/input/combobox-input.svelte +1 -0
- package/dist/combobox/list/combobox-listbox.svelte +1 -0
- package/dist/combobox/list/combobox-listbox.svelte.d.ts +1 -0
- package/dist/combobox/root/combobox-test.svelte +8 -2
- package/dist/combobox/root/combobox-test.svelte.d.ts +1 -0
- package/dist/combobox/root/combobox.svelte +16 -9
- package/dist/listbox/item/listbox-item.svelte +24 -2
- package/dist/listbox/root/listbox.svelte +14 -2
- package/dist/listbox/root/listbox.svelte.d.ts +2 -0
- package/dist/table/IMPLEMENTATION_NOTES.md +2 -1
- package/dist/table/PLAN.md +440 -17
- package/dist/table/TODO.md +39 -1
- package/dist/table/cell/table-cell.svelte +86 -79
- package/dist/table/checkbox/table-checkbox-test.svelte +7 -0
- package/dist/table/checkbox/table-checkbox-test.svelte.d.ts +3 -1
- package/dist/table/checkbox/table-checkbox.svelte +55 -30
- package/dist/table/index.d.ts +1 -1
- package/dist/table/root/context.d.ts +16 -1
- package/dist/table/root/context.js +199 -24
- package/dist/table/root/table-root.svelte +30 -0
- package/dist/table/root/table-root.svelte.d.ts +4 -1
- package/dist/table/root/table-test.svelte +29 -0
- package/dist/table/root/table-test.svelte.d.ts +5 -1
- package/dist/table/row/table-row.svelte +44 -67
- package/dist/table/utils/handle-body-keydown.d.ts +13 -0
- package/dist/table/utils/handle-body-keydown.js +67 -0
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
shouldShowFocusVisible,
|
|
15
15
|
trackInteractionModality
|
|
16
16
|
} from '../../primitives/input-modality';
|
|
17
|
+
import { handleTableBodyKeydown } from '../utils/handle-body-keydown';
|
|
17
18
|
|
|
18
19
|
type TableRowProps = Omit<HTMLAttributes<HTMLTableRowElement>, 'children' | 'id'> & {
|
|
19
20
|
id?: TableSelectionKey;
|
|
@@ -199,6 +200,14 @@
|
|
|
199
200
|
void $selectionVersion;
|
|
200
201
|
return section.section === 'body' ? table.isRowDisabled(id, isDisabled) : isDisabled;
|
|
201
202
|
});
|
|
203
|
+
const isSelectionDisabled = $derived.by(() => {
|
|
204
|
+
void $selectionVersion;
|
|
205
|
+
return section.section === 'body' ? table.isRowSelectionDisabled(id, isDisabled) : isDisabled;
|
|
206
|
+
});
|
|
207
|
+
const isActionable = $derived.by(() => {
|
|
208
|
+
void $selectionVersion;
|
|
209
|
+
return section.section === 'body' ? table.isRowActionable(id, isDisabled) : false;
|
|
210
|
+
});
|
|
202
211
|
|
|
203
212
|
function handleFocus() {
|
|
204
213
|
if (section.section !== 'body') return;
|
|
@@ -216,77 +225,38 @@
|
|
|
216
225
|
function handleKeyDown(event: KeyboardEvent) {
|
|
217
226
|
if (section.section !== 'body') return;
|
|
218
227
|
if (event.target !== rowElement) return;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
table.moveToGridStart();
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if ((event.ctrlKey || event.metaKey) && event.key === 'End') {
|
|
236
|
-
event.preventDefault();
|
|
237
|
-
table.moveToGridEnd();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
switch (event.key) {
|
|
242
|
-
case 'ArrowUp':
|
|
243
|
-
event.preventDefault();
|
|
244
|
-
table.moveFocus('up', {
|
|
245
|
-
shiftKey: event.shiftKey,
|
|
246
|
-
ctrlKey: event.ctrlKey,
|
|
247
|
-
metaKey: event.metaKey,
|
|
248
|
-
altKey: event.altKey
|
|
249
|
-
});
|
|
250
|
-
return;
|
|
251
|
-
case 'ArrowDown':
|
|
252
|
-
event.preventDefault();
|
|
253
|
-
table.moveFocus('down', {
|
|
254
|
-
shiftKey: event.shiftKey,
|
|
255
|
-
ctrlKey: event.ctrlKey,
|
|
256
|
-
metaKey: event.metaKey,
|
|
257
|
-
altKey: event.altKey
|
|
258
|
-
});
|
|
259
|
-
return;
|
|
260
|
-
case 'ArrowLeft':
|
|
261
|
-
event.preventDefault();
|
|
262
|
-
table.moveFocus('left');
|
|
263
|
-
return;
|
|
264
|
-
case 'ArrowRight':
|
|
265
|
-
event.preventDefault();
|
|
266
|
-
table.moveFocus('right');
|
|
267
|
-
return;
|
|
268
|
-
case 'Home':
|
|
269
|
-
event.preventDefault();
|
|
270
|
-
table.moveToBodyRowStart();
|
|
271
|
-
return;
|
|
272
|
-
case 'End':
|
|
273
|
-
event.preventDefault();
|
|
274
|
-
table.moveToBodyRowEnd();
|
|
275
|
-
return;
|
|
276
|
-
case 'Enter':
|
|
277
|
-
case ' ':
|
|
278
|
-
event.preventDefault();
|
|
279
|
-
if (event.repeat) return;
|
|
280
|
-
if (!isAriaDisabled) {
|
|
281
|
-
table.pressRow(id, {
|
|
228
|
+
handleTableBodyKeydown({
|
|
229
|
+
event,
|
|
230
|
+
table,
|
|
231
|
+
focusTarget: rowElement,
|
|
232
|
+
isDisabled: isAriaDisabled,
|
|
233
|
+
onHome: () => table.moveToBodyRowStart(),
|
|
234
|
+
onEnd: () => table.moveToBodyRowEnd(),
|
|
235
|
+
onEnter: () =>
|
|
236
|
+
table.pressRow(
|
|
237
|
+
id,
|
|
238
|
+
'keyboard-enter',
|
|
239
|
+
{
|
|
282
240
|
shiftKey: event.shiftKey,
|
|
283
241
|
ctrlKey: event.ctrlKey,
|
|
284
242
|
metaKey: event.metaKey,
|
|
285
243
|
altKey: event.altKey
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
244
|
+
},
|
|
245
|
+
isDisabled
|
|
246
|
+
),
|
|
247
|
+
onSpace: () =>
|
|
248
|
+
table.pressRow(
|
|
249
|
+
id,
|
|
250
|
+
'keyboard-space',
|
|
251
|
+
{
|
|
252
|
+
shiftKey: event.shiftKey,
|
|
253
|
+
ctrlKey: event.ctrlKey,
|
|
254
|
+
metaKey: event.metaKey,
|
|
255
|
+
altKey: event.altKey
|
|
256
|
+
},
|
|
257
|
+
isDisabled
|
|
258
|
+
)
|
|
259
|
+
});
|
|
290
260
|
}
|
|
291
261
|
</script>
|
|
292
262
|
|
|
@@ -304,7 +274,14 @@
|
|
|
304
274
|
data-focus-visible={isFocusVisible ? 'true' : undefined}
|
|
305
275
|
data-focus-within={isFocusWithin ? 'true' : undefined}
|
|
306
276
|
data-focus-visible-within={isFocusVisibleWithin ? 'true' : undefined}
|
|
277
|
+
data-actionable={isActionable ? 'true' : undefined}
|
|
307
278
|
data-selected={isSelected ? 'true' : undefined}
|
|
279
|
+
data-selection-disabled={section.section === 'body' &&
|
|
280
|
+
table.selectionMode !== 'none' &&
|
|
281
|
+
!isAriaDisabled &&
|
|
282
|
+
isSelectionDisabled
|
|
283
|
+
? 'true'
|
|
284
|
+
: undefined}
|
|
308
285
|
data-disabled={isAriaDisabled || undefined}
|
|
309
286
|
aria-selected={section.section === 'body' && table.selectionMode !== 'none'
|
|
310
287
|
? isSelected
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TableContext } from '../root/context';
|
|
2
|
+
type TableBodyKeydownOptions = {
|
|
3
|
+
event: KeyboardEvent;
|
|
4
|
+
table: Pick<TableContext, 'selectionMode' | 'selectAllRows' | 'moveToGridStart' | 'moveToGridEnd' | 'moveFocus'>;
|
|
5
|
+
focusTarget: HTMLElement | null | undefined;
|
|
6
|
+
isDisabled: boolean;
|
|
7
|
+
onHome: () => void;
|
|
8
|
+
onEnd: () => void;
|
|
9
|
+
onEnter: () => void;
|
|
10
|
+
onSpace: () => void;
|
|
11
|
+
};
|
|
12
|
+
export declare function handleTableBodyKeydown({ event, table, focusTarget, isDisabled, onHome, onEnd, onEnter, onSpace }: TableBodyKeydownOptions): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { trackInteractionModality } from '../../primitives/input-modality';
|
|
2
|
+
function getInteraction(event) {
|
|
3
|
+
return {
|
|
4
|
+
shiftKey: event.shiftKey,
|
|
5
|
+
ctrlKey: event.ctrlKey,
|
|
6
|
+
metaKey: event.metaKey,
|
|
7
|
+
altKey: event.altKey
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function handleTableBodyKeydown({ event, table, focusTarget, isDisabled, onHome, onEnd, onEnter, onSpace }) {
|
|
11
|
+
trackInteractionModality(event, focusTarget ?? null);
|
|
12
|
+
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'a') {
|
|
13
|
+
if (table.selectionMode === 'multiple') {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
table.selectAllRows();
|
|
16
|
+
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 'Home') {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
table.moveToGridStart();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 'End') {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
table.moveToGridEnd();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
switch (event.key) {
|
|
30
|
+
case 'ArrowUp':
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
table.moveFocus('up', getInteraction(event));
|
|
33
|
+
return;
|
|
34
|
+
case 'ArrowDown':
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
table.moveFocus('down', getInteraction(event));
|
|
37
|
+
return;
|
|
38
|
+
case 'ArrowLeft':
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
table.moveFocus('left');
|
|
41
|
+
return;
|
|
42
|
+
case 'ArrowRight':
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
table.moveFocus('right');
|
|
45
|
+
return;
|
|
46
|
+
case 'Home':
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
onHome();
|
|
49
|
+
return;
|
|
50
|
+
case 'End':
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
onEnd();
|
|
53
|
+
return;
|
|
54
|
+
case 'Enter':
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
if (event.repeat || isDisabled)
|
|
57
|
+
return;
|
|
58
|
+
onEnter();
|
|
59
|
+
return;
|
|
60
|
+
case ' ':
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
if (event.repeat || isDisabled)
|
|
63
|
+
return;
|
|
64
|
+
onSpace();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|