@aleph-alpha/ui-library 5.3.1 → 5.5.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.
- package/config.d.ts +38 -3
- package/config.js +103 -6
- package/dist/system/lib.js +8926 -8768
- package/dist/system/patterns/UiDataTable/UiDataTableFilterMenu.vue.d.ts +24 -0
- package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
- package/dist/system/patterns/UiDataTable/index.d.ts +1 -0
- package/dist/system/patterns/UiDataTable/types.d.ts +23 -1
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
- package/dist/system/story-sidebar-icons.json +5 -1
- package/docs/public-docs/getting-started-designers.md +3 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +2 -1
- package/src/components/UiAutocomplete/UiAutocomplete.vue +5 -5
- package/src/components/UiButton/UiButton.stories.ts +14 -14
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +260 -9
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
- package/src/components/UiChip/UiChip.vue +1 -1
- package/src/components/UiDrawer/UiDrawer.stories.ts +2 -2
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +4 -4
- package/src/components/UiEmpty/UiEmpty.vue +2 -2
- package/src/components/UiField/UiField.stories.ts +610 -3
- package/src/components/UiField/UiFieldDescription.vue +7 -2
- package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +2 -2
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +2 -2
- package/src/components/UiInput/UiInput.stories.ts +336 -2
- package/src/components/UiInput/UiInput.vue +3 -3
- package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
- package/src/components/UiItem/UiItem.stories.ts +236 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
- package/src/components/UiKbd/UiKbd.stories.ts +14 -14
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +42 -42
- package/src/components/UiPopover/UiPopover.stories.ts +6 -6
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +2 -2
- package/src/components/UiResizable/UiResizable.stories.ts +6 -5
- package/src/components/UiSeparator/UiSeparator.stories.ts +6 -6
- package/src/components/UiSheet/UiSheet.stories.ts +2 -2
- package/src/components/UiSlider/UiSlider.stories.ts +8 -8
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
- package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
- package/src/components/UiSpinner/UiSpinner.stories.ts +8 -8
- package/src/components/UiSwitch/UiSwitch.stories.ts +2 -2
- package/src/components/UiTabs/UiTabs.stories.ts +30 -30
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +5 -3
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +9 -9
- package/src/components/UiTooltip/UiTooltip.stories.ts +3 -3
- package/src/components/core/accordion/AccordionTrigger.vue +2 -2
- package/src/components/core/alert/AlertDescription.vue +1 -1
- package/src/components/core/badge/index.ts +1 -1
- package/src/components/core/button/index.ts +2 -2
- package/src/components/core/calendar/CalendarCellTrigger.vue +2 -2
- package/src/components/core/calendar/CalendarHeadCell.vue +1 -1
- package/src/components/core/card/CardDescription.vue +1 -1
- package/src/components/core/checkbox/Checkbox.vue +1 -2
- package/src/components/core/drawer/DrawerDescription.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuShortcut.vue +1 -1
- package/src/components/core/field/FieldDescription.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/field/FieldSeparator.vue +1 -1
- package/src/components/core/input/Input.vue +2 -2
- package/src/components/core/item/index.ts +1 -1
- package/src/components/core/kbd/Kbd.vue +1 -1
- package/src/components/core/listbox/ListboxFilter.vue +1 -1
- package/src/components/core/listbox/ListboxGroupLabel.vue +4 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/native-select/NativeSelect.vue +3 -3
- package/src/components/core/navigation-menu/NavigationMenuLink.vue +1 -1
- package/src/components/core/navigation-menu/index.ts +1 -1
- package/src/components/core/radio-group/RadioGroupItem.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +2 -2
- package/src/components/core/range-calendar/RangeCalendarHeadCell.vue +1 -1
- package/src/components/core/select/SelectItem.vue +1 -1
- package/src/components/core/select/SelectLabel.vue +4 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/sheet/SheetDescription.vue +3 -1
- package/src/components/core/switch/Switch.vue +1 -1
- package/src/components/core/table/TableCaption.vue +3 -1
- package/src/components/core/tabs/TabsList.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/core/tags-input/TagsInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputItemDelete.vue +1 -1
- package/src/components/core/textarea/Textarea.vue +1 -1
- package/src/components/core/toggle/index.ts +3 -3
- package/src/components/core/toggle-group/index.ts +2 -2
- package/src/lib/useDrag.stories.ts +8 -8
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +913 -16
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +91 -0
- package/src/patterns/UiDataTable/UiDataTablePagination.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
- package/src/patterns/UiDataTable/constants.ts +12 -0
- package/src/patterns/UiDataTable/index.ts +1 -0
- package/src/patterns/UiDataTable/types.ts +24 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +4 -4
- package/src/patterns/UiDatePicker/UiDatePicker.vue +1 -1
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +140 -12
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +1231 -438
- package/src/patterns/UiFloatActions/UiFloatActions.vue +1 -1
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
- package/src/patterns/UiFloatActions/types.ts +28 -1
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +2 -2
- package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
3
|
+
import type { ColumnDef, Row } from '@aleph-alpha/ui-library';
|
|
4
|
+
import { computed, h, ref, reactive } from 'vue';
|
|
4
5
|
import {
|
|
5
6
|
UiDataTable,
|
|
6
7
|
UiDataTableColumnFilter,
|
|
8
|
+
UiDataTableFilterMenu,
|
|
7
9
|
UiDataTableColumnHeader,
|
|
8
10
|
UiDataTablePagination,
|
|
9
11
|
UiDataTableToolbar,
|
|
@@ -13,6 +15,14 @@ import { UiCheckbox } from '@/components/UiCheckbox';
|
|
|
13
15
|
import { UiButton } from '@/components/UiButton';
|
|
14
16
|
import { UiIcon } from '@/components/UiIcon';
|
|
15
17
|
import { UiInput } from '@/components/UiInput';
|
|
18
|
+
import {
|
|
19
|
+
UiField,
|
|
20
|
+
UiFieldLabel,
|
|
21
|
+
UiFieldContent,
|
|
22
|
+
UiFieldSet,
|
|
23
|
+
UiFieldLegend,
|
|
24
|
+
UiFieldGroup,
|
|
25
|
+
} from '@/components/UiField';
|
|
16
26
|
import {
|
|
17
27
|
UiDropdownMenu,
|
|
18
28
|
UiDropdownMenuContent,
|
|
@@ -106,14 +116,14 @@ const selectableColumns: ColumnDef<Payment>[] = [
|
|
|
106
116
|
(table.getIsSomePageRowsSelected() && 'indeterminate'),
|
|
107
117
|
'onUpdate:modelValue': (value: boolean) =>
|
|
108
118
|
table.toggleAllPageRowsSelected(!!value),
|
|
109
|
-
|
|
119
|
+
'aria-label': 'Select all',
|
|
110
120
|
name: 'select-all',
|
|
111
121
|
}),
|
|
112
122
|
cell: ({ row }) =>
|
|
113
123
|
h(UiCheckbox, {
|
|
114
124
|
modelValue: row.getIsSelected(),
|
|
115
125
|
'onUpdate:modelValue': (value: boolean) => row.toggleSelected(!!value),
|
|
116
|
-
|
|
126
|
+
'aria-label': 'Select row',
|
|
117
127
|
name: `select-${row.id}`,
|
|
118
128
|
}),
|
|
119
129
|
enableSorting: false,
|
|
@@ -485,13 +495,13 @@ const columns: ColumnDef<Payment>[] = [
|
|
|
485
495
|
header: ({ table }) => h(UiCheckbox, {
|
|
486
496
|
modelValue: table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && 'indeterminate'),
|
|
487
497
|
'onUpdate:modelValue': (value: boolean) => table.toggleAllPageRowsSelected(!!value),
|
|
488
|
-
|
|
498
|
+
'aria-label': 'Select all',
|
|
489
499
|
name: 'select-all',
|
|
490
500
|
}),
|
|
491
501
|
cell: ({ row }) => h(UiCheckbox, {
|
|
492
502
|
modelValue: row.getIsSelected(),
|
|
493
503
|
'onUpdate:modelValue': (value: boolean) => row.toggleSelected(!!value),
|
|
494
|
-
|
|
504
|
+
'aria-label': 'Select row',
|
|
495
505
|
name: \`select-\${row.id}\`,
|
|
496
506
|
}),
|
|
497
507
|
enableSorting: false,
|
|
@@ -624,13 +634,13 @@ const columns: ColumnDef<Payment>[] = [
|
|
|
624
634
|
header: ({ table }) => h(UiCheckbox, {
|
|
625
635
|
modelValue: table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && 'indeterminate'),
|
|
626
636
|
'onUpdate:modelValue': (value: boolean) => table.toggleAllPageRowsSelected(!!value),
|
|
627
|
-
|
|
637
|
+
'aria-label': 'Select all',
|
|
628
638
|
name: 'select-all',
|
|
629
639
|
}),
|
|
630
640
|
cell: ({ row }) => h(UiCheckbox, {
|
|
631
641
|
modelValue: row.getIsSelected(),
|
|
632
642
|
'onUpdate:modelValue': (value: boolean) => row.toggleSelected(!!value),
|
|
633
|
-
|
|
643
|
+
'aria-label': 'Select row',
|
|
634
644
|
name: \`select-\${row.id}\`,
|
|
635
645
|
}),
|
|
636
646
|
enableSorting: false,
|
|
@@ -717,7 +727,7 @@ function handleColumnOrderChange(nextOrder: string[]) {
|
|
|
717
727
|
draggable-columns
|
|
718
728
|
:on-column-order-change="handleColumnOrderChange"
|
|
719
729
|
/>
|
|
720
|
-
<p class="body-14-regular text-muted
|
|
730
|
+
<p class="body-14-regular text-content-on-surface-muted">
|
|
721
731
|
Drag a column header to reorder columns.
|
|
722
732
|
<span v-if="columnOrder.length">
|
|
723
733
|
Current order: {{ columnOrder.join(', ') }}
|
|
@@ -1221,7 +1231,7 @@ export const WithDraggableColumns: Story = {
|
|
|
1221
1231
|
v-bind="args"
|
|
1222
1232
|
:on-column-order-change="handleColumnOrderChange"
|
|
1223
1233
|
/>
|
|
1224
|
-
<p class="body-14-regular text-muted
|
|
1234
|
+
<p class="body-14-regular text-content-on-surface-muted">
|
|
1225
1235
|
Drag a column header to reorder columns.
|
|
1226
1236
|
<span v-if="columnOrder.length">
|
|
1227
1237
|
Current order: {{ columnOrder.join(', ') }}
|
|
@@ -1261,7 +1271,7 @@ export const WithExpandableRows: Story = {
|
|
|
1261
1271
|
<template #expanded-row="{ row }">
|
|
1262
1272
|
<div class="body-14-regular rounded-md bg-background-surface-muted p-4">
|
|
1263
1273
|
<p class="font-medium">Payment {{ row.original.id }}</p>
|
|
1264
|
-
<p class="text-muted
|
|
1274
|
+
<p class="text-content-on-surface-muted">
|
|
1265
1275
|
Customer: {{ row.original.email }} - Status: {{ row.original.status }}
|
|
1266
1276
|
</p>
|
|
1267
1277
|
</div>
|
|
@@ -1379,7 +1389,7 @@ const columns: ColumnDef<Payment>[] = [
|
|
|
1379
1389
|
<template>
|
|
1380
1390
|
<UiDataTable :data="data" :columns="columns">
|
|
1381
1391
|
<template #empty>
|
|
1382
|
-
<div class="flex flex-col items-center gap-2 text-muted
|
|
1392
|
+
<div class="flex flex-col items-center gap-2 text-content-on-surface-muted">
|
|
1383
1393
|
<UiIcon name="ban" :size="32" />
|
|
1384
1394
|
<p>No data available for this view.</p>
|
|
1385
1395
|
</div>
|
|
@@ -1414,7 +1424,7 @@ export const WithCustomEmptySlot: Story = {
|
|
|
1414
1424
|
template: `
|
|
1415
1425
|
<UiDataTable v-bind="args">
|
|
1416
1426
|
<template #empty>
|
|
1417
|
-
<div class="flex flex-col items-center gap-2 text-muted
|
|
1427
|
+
<div class="flex flex-col items-center gap-2 text-content-on-surface-muted">
|
|
1418
1428
|
<UiIcon name="ban" :size="32" />
|
|
1419
1429
|
<p>No data available for this view.</p>
|
|
1420
1430
|
</div>
|
|
@@ -1927,7 +1937,7 @@ const cellFormattingColumns: ColumnDef<Payment>[] = [
|
|
|
1927
1937
|
return h(
|
|
1928
1938
|
'div',
|
|
1929
1939
|
{
|
|
1930
|
-
class: `text-right font-medium ${amount > 500 ? 'text-green-800' : 'text-muted
|
|
1940
|
+
class: `text-right font-medium ${amount > 500 ? 'text-green-800' : 'text-content-on-surface-muted'}`,
|
|
1931
1941
|
},
|
|
1932
1942
|
formatted,
|
|
1933
1943
|
);
|
|
@@ -1995,7 +2005,7 @@ const columns: ColumnDef<Payment>[] = [
|
|
|
1995
2005
|
currency: 'EUR',
|
|
1996
2006
|
}).format(amount);
|
|
1997
2007
|
return h('div', {
|
|
1998
|
-
class: \`text-right font-medium \${amount > 500 ? 'text-green-800' : 'text-muted
|
|
2008
|
+
class: \`text-right font-medium \${amount > 500 ? 'text-green-800' : 'text-content-on-surface-muted'}\`,
|
|
1999
2009
|
}, formatted);
|
|
2000
2010
|
},
|
|
2001
2011
|
},
|
|
@@ -2128,8 +2138,895 @@ export const WithRowClick: Story = {
|
|
|
2128
2138
|
<div v-if="clickedRow" class="body-14-regular mt-4 rounded border p-3">
|
|
2129
2139
|
Clicked: <strong>{{ clickedRow.email }}</strong> - {{ clickedRow.status }} - {{ new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(clickedRow.amount) }}
|
|
2130
2140
|
</div>
|
|
2131
|
-
<div v-else class="body-14-regular text-muted
|
|
2141
|
+
<div v-else class="body-14-regular text-content-on-surface-muted mt-4">Click a row to see its data</div>
|
|
2142
|
+
</div>
|
|
2143
|
+
`,
|
|
2144
|
+
}),
|
|
2145
|
+
};
|
|
2146
|
+
|
|
2147
|
+
/**
|
|
2148
|
+
* Amount ranges (in EUR) used by the filter menu checkbox group. Ranges are
|
|
2149
|
+
* non-overlapping: the upper bound is inclusive while the lower bound is
|
|
2150
|
+
* exclusive (except the first range), so e.g. 100 falls in "0–100" only.
|
|
2151
|
+
*/
|
|
2152
|
+
const AMOUNT_RANGES: Record<
|
|
2153
|
+
string,
|
|
2154
|
+
{ min: number; max: number; minInclusive: boolean }
|
|
2155
|
+
> = {
|
|
2156
|
+
'amount-0': { min: 0, max: 100, minInclusive: true },
|
|
2157
|
+
'amount-1': { min: 100, max: 400, minInclusive: false },
|
|
2158
|
+
'amount-2': { min: 400, max: 700, minInclusive: false },
|
|
2159
|
+
'amount-3': { min: 700, max: 1000, minInclusive: false },
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2162
|
+
const AMOUNT_OPTIONS = [
|
|
2163
|
+
{ id: 'amount-0', label: 'From 0 to 100,00 €' },
|
|
2164
|
+
{ id: 'amount-1', label: 'From 100,00 € to 400,00 €' },
|
|
2165
|
+
{ id: 'amount-2', label: 'From 400,00 € to 700,00 €' },
|
|
2166
|
+
{ id: 'amount-3', label: 'From 700,00 € to 1.000,00 €' },
|
|
2167
|
+
];
|
|
2168
|
+
|
|
2169
|
+
// UiButton's `end-icon` takes a component, so wrap UiIcon to render the "x".
|
|
2170
|
+
const XIcon = {
|
|
2171
|
+
components: { UiIcon },
|
|
2172
|
+
template: '<UiIcon name="x" :size="16" />',
|
|
2173
|
+
};
|
|
2174
|
+
|
|
2175
|
+
// Reuse the sortable columns but give `amount` a custom range filter so the
|
|
2176
|
+
// checkbox group can match rows falling into any selected range.
|
|
2177
|
+
const filterMenuColumns: ColumnDef<Payment>[] = sortableColumns.map((column) =>
|
|
2178
|
+
'accessorKey' in column && column.accessorKey === 'amount'
|
|
2179
|
+
? {
|
|
2180
|
+
...column,
|
|
2181
|
+
filterFn: (row: Row<Payment>, columnId: string, value: string[]) => {
|
|
2182
|
+
if (!value?.length) return true;
|
|
2183
|
+
const amount = Number(row.getValue(columnId));
|
|
2184
|
+
return value.some((key) => {
|
|
2185
|
+
const range = AMOUNT_RANGES[key];
|
|
2186
|
+
if (!range) return true;
|
|
2187
|
+
const aboveMin = range.minInclusive
|
|
2188
|
+
? amount >= range.min
|
|
2189
|
+
: amount > range.min;
|
|
2190
|
+
return aboveMin && amount <= range.max;
|
|
2191
|
+
});
|
|
2192
|
+
},
|
|
2193
|
+
}
|
|
2194
|
+
: column,
|
|
2195
|
+
);
|
|
2196
|
+
|
|
2197
|
+
const withFilterMenuTemplateSource = `<script setup lang="ts">
|
|
2198
|
+
import { computed, h, reactive, ref } from 'vue';
|
|
2199
|
+
import {
|
|
2200
|
+
UiButton,
|
|
2201
|
+
UiCheckbox,
|
|
2202
|
+
UiDataTable,
|
|
2203
|
+
UiDataTableColumnHeader,
|
|
2204
|
+
UiDataTableFilterMenu,
|
|
2205
|
+
UiDataTableToolbar,
|
|
2206
|
+
UiField,
|
|
2207
|
+
UiFieldContent,
|
|
2208
|
+
UiFieldGroup,
|
|
2209
|
+
UiFieldLabel,
|
|
2210
|
+
UiFieldLegend,
|
|
2211
|
+
UiFieldSet,
|
|
2212
|
+
UiIcon,
|
|
2213
|
+
UiInput,
|
|
2214
|
+
} from '@aleph-alpha/ui-library';
|
|
2215
|
+
import type { ColumnDef, Row } from '@aleph-alpha/ui-library';
|
|
2216
|
+
|
|
2217
|
+
interface Payment {
|
|
2218
|
+
id: string;
|
|
2219
|
+
amount: number;
|
|
2220
|
+
status: string;
|
|
2221
|
+
email: string;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
const data: Payment[] = [
|
|
2225
|
+
{ id: '1', amount: 316, status: 'success', email: 'ken99@yahoo.com' },
|
|
2226
|
+
{ id: '2', amount: 242, status: 'success', email: 'abe45@gmail.com' },
|
|
2227
|
+
{ id: '3', amount: 837, status: 'processing', email: 'monserrat44@gmail.com' },
|
|
2228
|
+
];
|
|
2229
|
+
|
|
2230
|
+
// Non-overlapping amount ranges (EUR) matched by the checkbox group.
|
|
2231
|
+
const amountRanges: Record<string, { min: number; max: number; minInclusive: boolean }> = {
|
|
2232
|
+
'amount-0': { min: 0, max: 100, minInclusive: true },
|
|
2233
|
+
'amount-1': { min: 100, max: 400, minInclusive: false },
|
|
2234
|
+
'amount-2': { min: 400, max: 700, minInclusive: false },
|
|
2235
|
+
'amount-3': { min: 700, max: 1000, minInclusive: false },
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
const amountOptions = [
|
|
2239
|
+
{ id: 'amount-0', label: 'From 0 to 100,00 €' },
|
|
2240
|
+
{ id: 'amount-1', label: 'From 100,00 € to 400,00 €' },
|
|
2241
|
+
{ id: 'amount-2', label: 'From 400,00 € to 700,00 €' },
|
|
2242
|
+
{ id: 'amount-3', label: 'From 700,00 € to 1.000,00 €' },
|
|
2243
|
+
];
|
|
2244
|
+
|
|
2245
|
+
// UiButton's \`end-icon\` takes a component, so wrap UiIcon to render the "x".
|
|
2246
|
+
const XIcon = {
|
|
2247
|
+
components: { UiIcon },
|
|
2248
|
+
template: '<UiIcon name="x" :size="16" />',
|
|
2249
|
+
};
|
|
2250
|
+
|
|
2251
|
+
const columns: ColumnDef<Payment>[] = [
|
|
2252
|
+
{
|
|
2253
|
+
accessorKey: 'status',
|
|
2254
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Status' }),
|
|
2255
|
+
},
|
|
2256
|
+
{
|
|
2257
|
+
accessorKey: 'email',
|
|
2258
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Email' }),
|
|
2259
|
+
},
|
|
2260
|
+
{
|
|
2261
|
+
accessorKey: 'amount',
|
|
2262
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Amount', class: 'justify-end' }),
|
|
2263
|
+
// Match rows whose amount falls into any selected range.
|
|
2264
|
+
filterFn: (row: Row<Payment>, columnId, value: string[]) => {
|
|
2265
|
+
if (!value?.length) return true;
|
|
2266
|
+
const amount = Number(row.getValue(columnId));
|
|
2267
|
+
return value.some((key) => {
|
|
2268
|
+
const range = amountRanges[key];
|
|
2269
|
+
if (!range) return true;
|
|
2270
|
+
const aboveMin = range.minInclusive ? amount >= range.min : amount > range.min;
|
|
2271
|
+
return aboveMin && amount <= range.max;
|
|
2272
|
+
});
|
|
2273
|
+
},
|
|
2274
|
+
},
|
|
2275
|
+
];
|
|
2276
|
+
|
|
2277
|
+
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
2278
|
+
const table = computed(() => tableRef.value?.table);
|
|
2279
|
+
const filterOpen = ref(false);
|
|
2280
|
+
|
|
2281
|
+
// Draft state edited in the form; committed to the table only on "Apply".
|
|
2282
|
+
const draft = reactive({ email: '', status: '', amount: [] as string[] });
|
|
2283
|
+
|
|
2284
|
+
// Count of applied filters drives the trigger badge and the "Remove filters" button.
|
|
2285
|
+
const activeCount = computed(() => table.value?.getState().columnFilters.length ?? 0);
|
|
2286
|
+
|
|
2287
|
+
// Checkbox group: toggle membership in the array (each checkbox is a boolean).
|
|
2288
|
+
function toggleAmount(id: string, checked: boolean | 'indeterminate') {
|
|
2289
|
+
const next = new Set(draft.amount);
|
|
2290
|
+
checked ? next.add(id) : next.delete(id);
|
|
2291
|
+
draft.amount = [...next];
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
function syncDraftFromTable() {
|
|
2295
|
+
draft.email = (table.value?.getColumn('email')?.getFilterValue() as string) ?? '';
|
|
2296
|
+
draft.status = (table.value?.getColumn('status')?.getFilterValue() as string) ?? '';
|
|
2297
|
+
draft.amount = [...((table.value?.getColumn('amount')?.getFilterValue() as string[]) ?? [])];
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
function applyFilters() {
|
|
2301
|
+
table.value?.getColumn('email')?.setFilterValue(draft.email || undefined);
|
|
2302
|
+
table.value?.getColumn('status')?.setFilterValue(draft.status || undefined);
|
|
2303
|
+
table.value?.getColumn('amount')?.setFilterValue(draft.amount.length ? [...draft.amount] : undefined);
|
|
2304
|
+
filterOpen.value = false;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
function cancelFilters() {
|
|
2308
|
+
syncDraftFromTable();
|
|
2309
|
+
filterOpen.value = false;
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// Clear every applied filter and reset the draft form.
|
|
2313
|
+
function removeFilters() {
|
|
2314
|
+
table.value?.resetColumnFilters();
|
|
2315
|
+
draft.email = '';
|
|
2316
|
+
draft.status = '';
|
|
2317
|
+
draft.amount = [];
|
|
2318
|
+
}
|
|
2319
|
+
</script>
|
|
2320
|
+
|
|
2321
|
+
<template>
|
|
2322
|
+
<div class="space-y-4">
|
|
2323
|
+
<UiDataTableToolbar>
|
|
2324
|
+
<UiDataTableFilterMenu v-if="table" v-model:open="filterOpen" :active-count="activeCount">
|
|
2325
|
+
<form class="flex flex-col gap-5" @submit.prevent="applyFilters">
|
|
2326
|
+
<UiFieldGroup>
|
|
2327
|
+
<UiField>
|
|
2328
|
+
<UiFieldLabel for="filter-email">Email</UiFieldLabel>
|
|
2329
|
+
<UiFieldContent>
|
|
2330
|
+
<UiInput id="filter-email" v-model="draft.email" name="email" placeholder="Placeholder" />
|
|
2331
|
+
</UiFieldContent>
|
|
2332
|
+
</UiField>
|
|
2333
|
+
<UiField>
|
|
2334
|
+
<UiFieldLabel for="filter-status">Status</UiFieldLabel>
|
|
2335
|
+
<UiFieldContent>
|
|
2336
|
+
<UiInput id="filter-status" v-model="draft.status" name="status" placeholder="Placeholder" />
|
|
2337
|
+
</UiFieldContent>
|
|
2338
|
+
</UiField>
|
|
2339
|
+
<UiFieldSet>
|
|
2340
|
+
<UiFieldLegend variant="legend">Amount</UiFieldLegend>
|
|
2341
|
+
<UiFieldGroup data-slot="checkbox-group">
|
|
2342
|
+
<UiField v-for="option in amountOptions" :key="option.id" orientation="responsive">
|
|
2343
|
+
<UiCheckbox
|
|
2344
|
+
:id="option.id"
|
|
2345
|
+
:name="option.id"
|
|
2346
|
+
:model-value="draft.amount.includes(option.id)"
|
|
2347
|
+
@update:model-value="(checked) => toggleAmount(option.id, checked)"
|
|
2348
|
+
/>
|
|
2349
|
+
<UiFieldLabel :for="option.id">{{ option.label }}</UiFieldLabel>
|
|
2350
|
+
</UiField>
|
|
2351
|
+
</UiFieldGroup>
|
|
2352
|
+
</UiFieldSet>
|
|
2353
|
+
<div class="flex items-center gap-2">
|
|
2354
|
+
<UiButton v-if="!!activeCount" variant="outline" :end-icon="XIcon" type="button" @click="removeFilters">
|
|
2355
|
+
Remove filters
|
|
2356
|
+
</UiButton>
|
|
2357
|
+
<div class="ml-auto flex gap-2">
|
|
2358
|
+
<UiButton variant="ghost" type="button" @click="cancelFilters">Cancel</UiButton>
|
|
2359
|
+
<UiButton type="submit">Apply</UiButton>
|
|
2360
|
+
</div>
|
|
2361
|
+
</div>
|
|
2362
|
+
</UiFieldGroup>
|
|
2363
|
+
</form>
|
|
2364
|
+
</UiDataTableFilterMenu>
|
|
2365
|
+
</UiDataTableToolbar>
|
|
2366
|
+
<UiDataTable ref="tableRef" :columns="columns" :data="data" />
|
|
2367
|
+
</div>
|
|
2368
|
+
</template>`;
|
|
2369
|
+
|
|
2370
|
+
/**
|
|
2371
|
+
* Table with a multi-field filter menu popover.
|
|
2372
|
+
*
|
|
2373
|
+
* `UiDataTableFilterMenu` holds a form of filter controls. Edits are kept in a
|
|
2374
|
+
* local `draft` and only committed to the table on **Apply**; **Cancel** reverts
|
|
2375
|
+
* the draft to the applied state. When any filter is active, a **Remove filters**
|
|
2376
|
+
* button clears them all via `table.resetColumnFilters()`. The trigger badge
|
|
2377
|
+
* reflects the number of applied column filters.
|
|
2378
|
+
*/
|
|
2379
|
+
export const WithFilterMenu: Story = {
|
|
2380
|
+
args: {
|
|
2381
|
+
data: payments,
|
|
2382
|
+
columns: filterMenuColumns,
|
|
2383
|
+
},
|
|
2384
|
+
parameters: {
|
|
2385
|
+
docs: {
|
|
2386
|
+
source: {
|
|
2387
|
+
code: withFilterMenuTemplateSource,
|
|
2388
|
+
},
|
|
2389
|
+
},
|
|
2390
|
+
},
|
|
2391
|
+
render: (args) => ({
|
|
2392
|
+
components: {
|
|
2393
|
+
UiDataTable,
|
|
2394
|
+
UiDataTableFilterMenu,
|
|
2395
|
+
UiDataTableToolbar,
|
|
2396
|
+
UiField,
|
|
2397
|
+
UiFieldLabel,
|
|
2398
|
+
UiFieldContent,
|
|
2399
|
+
UiFieldSet,
|
|
2400
|
+
UiFieldLegend,
|
|
2401
|
+
UiFieldGroup,
|
|
2402
|
+
UiButton,
|
|
2403
|
+
UiCheckbox,
|
|
2404
|
+
UiInput,
|
|
2405
|
+
},
|
|
2406
|
+
setup() {
|
|
2407
|
+
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
2408
|
+
const table = computed(() => tableRef.value?.table);
|
|
2409
|
+
const filterOpen = ref(false);
|
|
2410
|
+
|
|
2411
|
+
const draft = reactive({
|
|
2412
|
+
email: '',
|
|
2413
|
+
status: '',
|
|
2414
|
+
amount: [] as string[],
|
|
2415
|
+
});
|
|
2416
|
+
|
|
2417
|
+
const activeCount = computed(
|
|
2418
|
+
() => table.value?.getState().columnFilters.length ?? 0,
|
|
2419
|
+
);
|
|
2420
|
+
|
|
2421
|
+
function toggleAmount(id: string, checked: boolean | 'indeterminate') {
|
|
2422
|
+
const next = new Set(draft.amount);
|
|
2423
|
+
if (checked) {
|
|
2424
|
+
next.add(id);
|
|
2425
|
+
} else {
|
|
2426
|
+
next.delete(id);
|
|
2427
|
+
}
|
|
2428
|
+
draft.amount = [...next];
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
function syncDraftFromTable() {
|
|
2432
|
+
draft.email =
|
|
2433
|
+
(table.value?.getColumn('email')?.getFilterValue() as string) ?? '';
|
|
2434
|
+
draft.status =
|
|
2435
|
+
(table.value?.getColumn('status')?.getFilterValue() as string) ?? '';
|
|
2436
|
+
draft.amount = [
|
|
2437
|
+
...((table.value?.getColumn('amount')?.getFilterValue() as
|
|
2438
|
+
| string[]
|
|
2439
|
+
| undefined) ?? []),
|
|
2440
|
+
];
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
function applyFilters() {
|
|
2444
|
+
table.value
|
|
2445
|
+
?.getColumn('email')
|
|
2446
|
+
?.setFilterValue(draft.email || undefined);
|
|
2447
|
+
table.value
|
|
2448
|
+
?.getColumn('status')
|
|
2449
|
+
?.setFilterValue(draft.status || undefined);
|
|
2450
|
+
table.value
|
|
2451
|
+
?.getColumn('amount')
|
|
2452
|
+
?.setFilterValue(draft.amount.length ? [...draft.amount] : undefined);
|
|
2453
|
+
filterOpen.value = false;
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
function cancelFilters() {
|
|
2457
|
+
syncDraftFromTable();
|
|
2458
|
+
filterOpen.value = false;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
function removeFilters() {
|
|
2462
|
+
table.value?.resetColumnFilters();
|
|
2463
|
+
draft.email = '';
|
|
2464
|
+
draft.status = '';
|
|
2465
|
+
draft.amount = [];
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
return {
|
|
2469
|
+
args,
|
|
2470
|
+
table,
|
|
2471
|
+
tableRef,
|
|
2472
|
+
filterOpen,
|
|
2473
|
+
draft,
|
|
2474
|
+
activeCount,
|
|
2475
|
+
amountOptions: AMOUNT_OPTIONS,
|
|
2476
|
+
XIcon,
|
|
2477
|
+
toggleAmount,
|
|
2478
|
+
applyFilters,
|
|
2479
|
+
cancelFilters,
|
|
2480
|
+
removeFilters,
|
|
2481
|
+
};
|
|
2482
|
+
},
|
|
2483
|
+
template: `
|
|
2484
|
+
<div class="space-y-4">
|
|
2485
|
+
<UiDataTableToolbar>
|
|
2486
|
+
<UiDataTableFilterMenu
|
|
2487
|
+
v-if="table"
|
|
2488
|
+
v-model:open="filterOpen"
|
|
2489
|
+
:active-count="activeCount"
|
|
2490
|
+
>
|
|
2491
|
+
<form class="flex flex-col gap-5" @submit.prevent="applyFilters">
|
|
2492
|
+
<UiFieldGroup>
|
|
2493
|
+
<UiField>
|
|
2494
|
+
<UiFieldLabel for="filter-email">Email</UiFieldLabel>
|
|
2495
|
+
<UiFieldContent>
|
|
2496
|
+
<UiInput id="filter-email" v-model="draft.email" name="email" placeholder="Placeholder" />
|
|
2497
|
+
</UiFieldContent>
|
|
2498
|
+
</UiField>
|
|
2499
|
+
<UiField>
|
|
2500
|
+
<UiFieldLabel for="filter-status">Status</UiFieldLabel>
|
|
2501
|
+
<UiFieldContent>
|
|
2502
|
+
<UiInput id="filter-status" v-model="draft.status" name="status" placeholder="Placeholder" />
|
|
2503
|
+
</UiFieldContent>
|
|
2504
|
+
</UiField>
|
|
2505
|
+
<UiFieldSet>
|
|
2506
|
+
<UiFieldLegend variant="legend">Amount</UiFieldLegend>
|
|
2507
|
+
<UiFieldGroup data-slot="checkbox-group">
|
|
2508
|
+
<UiField
|
|
2509
|
+
v-for="option in amountOptions"
|
|
2510
|
+
:key="option.id"
|
|
2511
|
+
orientation="responsive"
|
|
2512
|
+
>
|
|
2513
|
+
<UiCheckbox
|
|
2514
|
+
:id="option.id"
|
|
2515
|
+
:name="option.id"
|
|
2516
|
+
:model-value="draft.amount.includes(option.id)"
|
|
2517
|
+
@update:model-value="(checked) => toggleAmount(option.id, checked)"
|
|
2518
|
+
/>
|
|
2519
|
+
<UiFieldLabel :for="option.id">{{ option.label }}</UiFieldLabel>
|
|
2520
|
+
</UiField>
|
|
2521
|
+
</UiFieldGroup>
|
|
2522
|
+
</UiFieldSet>
|
|
2523
|
+
<div class="flex items-center gap-2">
|
|
2524
|
+
<UiButton
|
|
2525
|
+
v-if="!!activeCount"
|
|
2526
|
+
variant="outline"
|
|
2527
|
+
:end-icon="XIcon"
|
|
2528
|
+
type="button"
|
|
2529
|
+
@click="removeFilters"
|
|
2530
|
+
>
|
|
2531
|
+
Remove filters
|
|
2532
|
+
</UiButton>
|
|
2533
|
+
<div class="ml-auto flex gap-2">
|
|
2534
|
+
<UiButton variant="ghost" type="button" @click="cancelFilters">Cancel</UiButton>
|
|
2535
|
+
<UiButton type="submit">Apply</UiButton>
|
|
2536
|
+
</div>
|
|
2537
|
+
</div>
|
|
2538
|
+
</UiFieldGroup>
|
|
2539
|
+
</form>
|
|
2540
|
+
</UiDataTableFilterMenu>
|
|
2541
|
+
</UiDataTableToolbar>
|
|
2542
|
+
<UiDataTable ref="tableRef" v-bind="args" />
|
|
2132
2543
|
</div>
|
|
2133
2544
|
`,
|
|
2134
2545
|
}),
|
|
2135
2546
|
};
|
|
2547
|
+
|
|
2548
|
+
// ---------------------------------------------------------------------------
|
|
2549
|
+
// Accessibility & interaction test scenarios
|
|
2550
|
+
// ---------------------------------------------------------------------------
|
|
2551
|
+
//
|
|
2552
|
+
// The stories below drive the Storybook test-runner. Each labels its checks
|
|
2553
|
+
// with a category-prefixed `step()` so the automated report and the scenario
|
|
2554
|
+
// PDF can group them consistently:
|
|
2555
|
+
//
|
|
2556
|
+
// await step('interaction: ...', async () => { … }); // behaviour + state
|
|
2557
|
+
// await step('keyboard: ...', async () => { … }); // Tab / Enter / Space
|
|
2558
|
+
// await step('screen-reader: ...', async () => { … }); // roles, names, ARIA
|
|
2559
|
+
// await step('zoom: ...', async () => { … }); // 200% resize text
|
|
2560
|
+
// await step('mobile: ...', async () => { … }); // 320px reflow
|
|
2561
|
+
//
|
|
2562
|
+
// Accessibility (axe) is audited automatically for every visited story, so it
|
|
2563
|
+
// is not a labelled category here. The test-only stories are hidden from the
|
|
2564
|
+
// sidebar and docs via the `!dev` / `!autodocs` tags but keep the implicit
|
|
2565
|
+
// `test` tag, so they still run in CI. `name`/`tags` must be literal so
|
|
2566
|
+
// Storybook's static CSF indexer can read them. Focus/sort state mutates during
|
|
2567
|
+
// these plays, so each disables its Chromatic snapshot.
|
|
2568
|
+
|
|
2569
|
+
// Deterministic dataset for the test scenarios: emails and statuses sort into a
|
|
2570
|
+
// predictable order so the plays can assert row ordering without flakiness.
|
|
2571
|
+
const a11yTestData: Payment[] = [
|
|
2572
|
+
{ id: '1', amount: 300, status: 'success', email: 'charlie@example.com' },
|
|
2573
|
+
{ id: '2', amount: 100, status: 'processing', email: 'alice@example.com' },
|
|
2574
|
+
{ id: '3', amount: 200, status: 'failed', email: 'bob@example.com' },
|
|
2575
|
+
];
|
|
2576
|
+
|
|
2577
|
+
/**
|
|
2578
|
+
* Accessibility guidance for data tables: descriptive headers, labelled sort
|
|
2579
|
+
* controls and selection checkboxes, and sufficient contrast.
|
|
2580
|
+
*/
|
|
2581
|
+
export const Accessibility: Story = {
|
|
2582
|
+
tags: ['!autodocs'],
|
|
2583
|
+
parameters: {
|
|
2584
|
+
a11y: { test: 'off' },
|
|
2585
|
+
chromatic: { disableSnapshot: true },
|
|
2586
|
+
docs: {
|
|
2587
|
+
canvas: {
|
|
2588
|
+
sourceState: 'none',
|
|
2589
|
+
},
|
|
2590
|
+
},
|
|
2591
|
+
},
|
|
2592
|
+
render: () => ({
|
|
2593
|
+
components: { UiDataTable },
|
|
2594
|
+
setup() {
|
|
2595
|
+
return { columns: basicColumns, data: a11yTestData };
|
|
2596
|
+
},
|
|
2597
|
+
template: `
|
|
2598
|
+
<section class="flex flex-col gap-6 p-4">
|
|
2599
|
+
<div>
|
|
2600
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
2601
|
+
Accessibility
|
|
2602
|
+
</h2>
|
|
2603
|
+
</div>
|
|
2604
|
+
|
|
2605
|
+
<div class="flex flex-col gap-6">
|
|
2606
|
+
<div class="flex flex-col gap-2">
|
|
2607
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2608
|
+
Give every column a clear, unique header
|
|
2609
|
+
</h3>
|
|
2610
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2611
|
+
Column headers are exposed as <code>columnheader</code> cells and
|
|
2612
|
+
become the accessible name for the data in that column. Keep them
|
|
2613
|
+
concise and descriptive so screen-reader users can understand the
|
|
2614
|
+
table when navigating cell by cell.
|
|
2615
|
+
</p>
|
|
2616
|
+
</div>
|
|
2617
|
+
|
|
2618
|
+
<div class="flex flex-col gap-2">
|
|
2619
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2620
|
+
Label sort controls and selection checkboxes
|
|
2621
|
+
</h3>
|
|
2622
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2623
|
+
Sortable headers use <code>UiDataTableColumnHeader</code>, whose
|
|
2624
|
+
button announces the column and its current sort state (for
|
|
2625
|
+
example, "Status, sorted ascending"). Selection checkboxes need a
|
|
2626
|
+
per-row <code>aria-label</code> such as "Select row" so their
|
|
2627
|
+
purpose is clear out of context.
|
|
2628
|
+
</p>
|
|
2629
|
+
</div>
|
|
2630
|
+
|
|
2631
|
+
<div class="flex flex-col gap-2">
|
|
2632
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2633
|
+
Expandable rows
|
|
2634
|
+
</h3>
|
|
2635
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2636
|
+
Give the expand toggle a real button with an
|
|
2637
|
+
<code>aria-expanded</code> state and a label that reflects the
|
|
2638
|
+
action ("Expand row" / "Collapse row"). The expanded content is
|
|
2639
|
+
rendered in its own table row rather than overlaid, so the table
|
|
2640
|
+
structure stays valid for browsers and screen readers.
|
|
2641
|
+
</p>
|
|
2642
|
+
</div>
|
|
2643
|
+
|
|
2644
|
+
<div class="flex flex-col gap-2">
|
|
2645
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2646
|
+
Column visibility checklist
|
|
2647
|
+
</h3>
|
|
2648
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2649
|
+
The column menu exposes each column as a checkable menu item so
|
|
2650
|
+
assistive tech announces its checked state and lets users toggle
|
|
2651
|
+
columns from the keyboard. Give the trigger a clear accessible
|
|
2652
|
+
label such as "Toggle columns" since its icon alone is not
|
|
2653
|
+
self-explanatory.
|
|
2654
|
+
</p>
|
|
2655
|
+
</div>
|
|
2656
|
+
|
|
2657
|
+
<div class="flex flex-col gap-2">
|
|
2658
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2659
|
+
Row actions and filter menus
|
|
2660
|
+
</h3>
|
|
2661
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2662
|
+
Row action and filter popovers are menus: the trigger needs an
|
|
2663
|
+
accessible name (for example "Open menu" or "Toggle Filters"),
|
|
2664
|
+
opens on Enter/Space, and its items are reachable with the arrow
|
|
2665
|
+
keys and dismissed with Escape. Keep filter fields inside the
|
|
2666
|
+
popover individually labelled so each control makes sense on its
|
|
2667
|
+
own.
|
|
2668
|
+
</p>
|
|
2669
|
+
</div>
|
|
2670
|
+
|
|
2671
|
+
<div class="flex flex-col gap-2">
|
|
2672
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2673
|
+
Draggable columns
|
|
2674
|
+
</h3>
|
|
2675
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2676
|
+
Reordering must not rely on a pointer alone. A draggable header is
|
|
2677
|
+
focusable and can be moved with the Arrow Left / Arrow Right keys,
|
|
2678
|
+
and a focus indicator marks the column being moved so keyboard and
|
|
2679
|
+
low-vision users can follow the change.
|
|
2680
|
+
</p>
|
|
2681
|
+
</div>
|
|
2682
|
+
|
|
2683
|
+
<div class="flex flex-col gap-2">
|
|
2684
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2685
|
+
Clickable rows and pagination
|
|
2686
|
+
</h3>
|
|
2687
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2688
|
+
When rows are clickable, keep the real action on a focusable
|
|
2689
|
+
control inside the row so it is keyboard operable, and let clicks
|
|
2690
|
+
on nested buttons, links, or checkboxes take priority over the row
|
|
2691
|
+
handler. Pagination controls carry descriptive labels ("Go to
|
|
2692
|
+
next page") and announce the current page and selection count.
|
|
2693
|
+
</p>
|
|
2694
|
+
</div>
|
|
2695
|
+
|
|
2696
|
+
<div class="flex flex-col gap-2">
|
|
2697
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
2698
|
+
Enable the accessibility theme
|
|
2699
|
+
</h3>
|
|
2700
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
2701
|
+
When accessibility is required, enable our accessibility theme. It
|
|
2702
|
+
increases contrast so table text and controls meet color-contrast
|
|
2703
|
+
requirements.
|
|
2704
|
+
</p>
|
|
2705
|
+
</div>
|
|
2706
|
+
</div>
|
|
2707
|
+
|
|
2708
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
2709
|
+
<div class="flex flex-col gap-3">
|
|
2710
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
2711
|
+
Default
|
|
2712
|
+
</h3>
|
|
2713
|
+
<div class="border border-border-surface-default p-4">
|
|
2714
|
+
<UiDataTable :columns="columns" :data="data" />
|
|
2715
|
+
</div>
|
|
2716
|
+
</div>
|
|
2717
|
+
|
|
2718
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
2719
|
+
<h3 class="label-16-medium text-center text-content-on-surface-primary">
|
|
2720
|
+
Accessible
|
|
2721
|
+
</h3>
|
|
2722
|
+
<div class="border border-border-surface-default p-4">
|
|
2723
|
+
<UiDataTable :columns="columns" :data="data" />
|
|
2724
|
+
</div>
|
|
2725
|
+
</div>
|
|
2726
|
+
</div>
|
|
2727
|
+
</section>
|
|
2728
|
+
`,
|
|
2729
|
+
}),
|
|
2730
|
+
};
|
|
2731
|
+
|
|
2732
|
+
/**
|
|
2733
|
+
* The data table is fully keyboard operable: sortable headers are reachable
|
|
2734
|
+
* with `Tab` and cycle their sort direction with `Enter`.
|
|
2735
|
+
*/
|
|
2736
|
+
export const KeyboardNavigation: Story = {
|
|
2737
|
+
name: 'test - Keyboard Navigation',
|
|
2738
|
+
tags: ['!dev', '!autodocs'],
|
|
2739
|
+
parameters: {
|
|
2740
|
+
// Focus and sort state change during the play; skip the visual snapshot.
|
|
2741
|
+
chromatic: { disableSnapshot: true },
|
|
2742
|
+
docs: {
|
|
2743
|
+
description: {
|
|
2744
|
+
story:
|
|
2745
|
+
'Press `Tab` to focus a sortable column header, then `Enter` to cycle its sort direction.',
|
|
2746
|
+
},
|
|
2747
|
+
},
|
|
2748
|
+
},
|
|
2749
|
+
render: () => ({
|
|
2750
|
+
components: { UiDataTable },
|
|
2751
|
+
setup() {
|
|
2752
|
+
return { columns: sortableColumns, data: a11yTestData };
|
|
2753
|
+
},
|
|
2754
|
+
template: `<UiDataTable :columns="columns" :data="data" />`,
|
|
2755
|
+
}),
|
|
2756
|
+
play: async ({ canvasElement, step }) => {
|
|
2757
|
+
// Scenario (UiDataTable): a keyboard user Tabs to a sortable column header
|
|
2758
|
+
// and cycles its sort direction with Enter — ascending, descending, then
|
|
2759
|
+
// cleared — reordering the rows on each activation.
|
|
2760
|
+
const canvas = within(canvasElement);
|
|
2761
|
+
const statusSort = canvas.getByRole('button', { name: /^Status/ });
|
|
2762
|
+
const firstCell = () => canvas.getAllByRole('cell')[0];
|
|
2763
|
+
|
|
2764
|
+
await step(
|
|
2765
|
+
'keyboard: the first sortable header is reachable via Tab (WCAG 2.1.1 Keyboard)',
|
|
2766
|
+
async () => {
|
|
2767
|
+
await userEvent.tab();
|
|
2768
|
+
await expect(statusSort).toHaveFocus();
|
|
2769
|
+
},
|
|
2770
|
+
);
|
|
2771
|
+
|
|
2772
|
+
await step('interaction: Enter sorts the column ascending', async () => {
|
|
2773
|
+
await userEvent.keyboard('{Enter}');
|
|
2774
|
+
await expect(statusSort).toHaveAccessibleName('Status, sorted ascending');
|
|
2775
|
+
await expect(firstCell()).toHaveTextContent('failed');
|
|
2776
|
+
});
|
|
2777
|
+
|
|
2778
|
+
await step(
|
|
2779
|
+
'keyboard: Enter again toggles to descending (WCAG 2.1.1)',
|
|
2780
|
+
async () => {
|
|
2781
|
+
await userEvent.keyboard('{Enter}');
|
|
2782
|
+
await expect(statusSort).toHaveAccessibleName(
|
|
2783
|
+
'Status, sorted descending',
|
|
2784
|
+
);
|
|
2785
|
+
await expect(firstCell()).toHaveTextContent('success');
|
|
2786
|
+
},
|
|
2787
|
+
);
|
|
2788
|
+
|
|
2789
|
+
await step('interaction: a third activation clears the sort', async () => {
|
|
2790
|
+
await userEvent.keyboard('{Enter}');
|
|
2791
|
+
await expect(statusSort).toHaveAccessibleName('Status, click to sort');
|
|
2792
|
+
});
|
|
2793
|
+
},
|
|
2794
|
+
};
|
|
2795
|
+
|
|
2796
|
+
/**
|
|
2797
|
+
* Row selection: the header checkbox toggles every row on the page and each
|
|
2798
|
+
* row checkbox toggles independently.
|
|
2799
|
+
*/
|
|
2800
|
+
export const RowSelectionInteraction: Story = {
|
|
2801
|
+
name: 'test - Row Selection',
|
|
2802
|
+
tags: ['!dev', '!autodocs'],
|
|
2803
|
+
parameters: {
|
|
2804
|
+
// Selection state changes during the play; skip the visual snapshot.
|
|
2805
|
+
chromatic: { disableSnapshot: true },
|
|
2806
|
+
docs: {
|
|
2807
|
+
description: {
|
|
2808
|
+
story:
|
|
2809
|
+
'Toggle the header checkbox to select every row, then toggle a single row checkbox.',
|
|
2810
|
+
},
|
|
2811
|
+
},
|
|
2812
|
+
},
|
|
2813
|
+
render: () => ({
|
|
2814
|
+
components: { UiDataTable },
|
|
2815
|
+
setup() {
|
|
2816
|
+
return { columns: selectableColumns, data: a11yTestData };
|
|
2817
|
+
},
|
|
2818
|
+
template: `<UiDataTable :columns="columns" :data="data" />`,
|
|
2819
|
+
}),
|
|
2820
|
+
play: async ({ canvasElement, step }) => {
|
|
2821
|
+
// Scenario (UiDataTable): row checkboxes toggle independently, a partial
|
|
2822
|
+
// selection is announced as mixed on the header checkbox, and the header
|
|
2823
|
+
// checkbox selects then clears every row on the page.
|
|
2824
|
+
const canvas = within(canvasElement);
|
|
2825
|
+
const selectAll = canvas.getByRole('checkbox', { name: 'Select all' });
|
|
2826
|
+
const rowCheckboxes = canvas.getAllByRole('checkbox', {
|
|
2827
|
+
name: 'Select row',
|
|
2828
|
+
});
|
|
2829
|
+
|
|
2830
|
+
await step('interaction: rows start unselected', async () => {
|
|
2831
|
+
await expect(selectAll).toHaveAttribute('aria-checked', 'false');
|
|
2832
|
+
});
|
|
2833
|
+
|
|
2834
|
+
await step('interaction: row checkboxes toggle independently', async () => {
|
|
2835
|
+
await userEvent.click(rowCheckboxes[0]);
|
|
2836
|
+
await userEvent.click(rowCheckboxes[2]);
|
|
2837
|
+
await expect(rowCheckboxes[0]).toHaveAttribute('aria-checked', 'true');
|
|
2838
|
+
await expect(rowCheckboxes[1]).toHaveAttribute('aria-checked', 'false');
|
|
2839
|
+
await expect(rowCheckboxes[2]).toHaveAttribute('aria-checked', 'true');
|
|
2840
|
+
});
|
|
2841
|
+
|
|
2842
|
+
await step(
|
|
2843
|
+
'screen-reader: a partial selection is announced as mixed (WCAG 4.1.2)',
|
|
2844
|
+
async () => {
|
|
2845
|
+
await expect(selectAll).toHaveAttribute('aria-checked', 'mixed');
|
|
2846
|
+
},
|
|
2847
|
+
);
|
|
2848
|
+
|
|
2849
|
+
await step(
|
|
2850
|
+
'interaction: the header checkbox selects every row',
|
|
2851
|
+
async () => {
|
|
2852
|
+
await userEvent.click(selectAll);
|
|
2853
|
+
for (const checkbox of rowCheckboxes) {
|
|
2854
|
+
await expect(checkbox).toHaveAttribute('aria-checked', 'true');
|
|
2855
|
+
}
|
|
2856
|
+
},
|
|
2857
|
+
);
|
|
2858
|
+
|
|
2859
|
+
await step(
|
|
2860
|
+
'interaction: the header checkbox clears the selection',
|
|
2861
|
+
async () => {
|
|
2862
|
+
await userEvent.click(selectAll);
|
|
2863
|
+
for (const checkbox of rowCheckboxes) {
|
|
2864
|
+
await expect(checkbox).toHaveAttribute('aria-checked', 'false');
|
|
2865
|
+
}
|
|
2866
|
+
},
|
|
2867
|
+
);
|
|
2868
|
+
},
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
/**
|
|
2872
|
+
* Screen-reader semantics: the table exposes column headers, sortable headers
|
|
2873
|
+
* announce their sort state, and selection checkboxes carry accessible names.
|
|
2874
|
+
*/
|
|
2875
|
+
export const ScreenReader: Story = {
|
|
2876
|
+
name: 'test - Screen Reader',
|
|
2877
|
+
tags: ['!dev', '!autodocs'],
|
|
2878
|
+
parameters: {
|
|
2879
|
+
chromatic: { disableSnapshot: true },
|
|
2880
|
+
docs: {
|
|
2881
|
+
description: {
|
|
2882
|
+
story:
|
|
2883
|
+
'Verifies the roles, names, and sort state that assistive technology announces.',
|
|
2884
|
+
},
|
|
2885
|
+
},
|
|
2886
|
+
},
|
|
2887
|
+
render: () => ({
|
|
2888
|
+
components: { UiDataTable },
|
|
2889
|
+
setup() {
|
|
2890
|
+
return { columns: selectableColumns, data: a11yTestData };
|
|
2891
|
+
},
|
|
2892
|
+
template: `<UiDataTable :columns="columns" :data="data" />`,
|
|
2893
|
+
}),
|
|
2894
|
+
play: async ({ canvasElement, step }) => {
|
|
2895
|
+
// Scenario (UiDataTable): assistive tech finds a table with labelled column
|
|
2896
|
+
// headers, labelled selection controls, and a sort control that announces
|
|
2897
|
+
// its current state.
|
|
2898
|
+
const canvas = within(canvasElement);
|
|
2899
|
+
|
|
2900
|
+
await step(
|
|
2901
|
+
'screen-reader: exposes a table with a header for every column',
|
|
2902
|
+
async () => {
|
|
2903
|
+
await expect(canvas.getByRole('table')).toBeVisible();
|
|
2904
|
+
await expect(canvas.getAllByRole('columnheader')).toHaveLength(4);
|
|
2905
|
+
},
|
|
2906
|
+
);
|
|
2907
|
+
|
|
2908
|
+
await step(
|
|
2909
|
+
'screen-reader: selection controls have accessible names (WCAG 4.1.2)',
|
|
2910
|
+
async () => {
|
|
2911
|
+
await expect(
|
|
2912
|
+
canvas.getByRole('checkbox', { name: 'Select all' }),
|
|
2913
|
+
).toBeVisible();
|
|
2914
|
+
await expect(
|
|
2915
|
+
canvas.getAllByRole('checkbox', { name: 'Select row' }),
|
|
2916
|
+
).toHaveLength(3);
|
|
2917
|
+
},
|
|
2918
|
+
);
|
|
2919
|
+
|
|
2920
|
+
await step(
|
|
2921
|
+
'screen-reader: the sortable header announces its current sort state',
|
|
2922
|
+
async () => {
|
|
2923
|
+
const statusSort = canvas.getByRole('button', {
|
|
2924
|
+
name: 'Status, click to sort',
|
|
2925
|
+
});
|
|
2926
|
+
await expect(statusSort).toHaveAccessibleName('Status, click to sort');
|
|
2927
|
+
},
|
|
2928
|
+
);
|
|
2929
|
+
},
|
|
2930
|
+
};
|
|
2931
|
+
|
|
2932
|
+
/**
|
|
2933
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
2934
|
+
* try 400% reflow (WCAG 1.4.10); the table must stay visible and operable.
|
|
2935
|
+
*/
|
|
2936
|
+
export const ZoomMagnification: Story = {
|
|
2937
|
+
name: 'test - Zoom Magnification',
|
|
2938
|
+
tags: ['!dev', '!autodocs'],
|
|
2939
|
+
globals: { zoom: '200' },
|
|
2940
|
+
parameters: {
|
|
2941
|
+
// The accessible-reflow Chromatic mode already covers magnified snapshots.
|
|
2942
|
+
chromatic: { disableSnapshot: true },
|
|
2943
|
+
docs: {
|
|
2944
|
+
description: {
|
|
2945
|
+
story:
|
|
2946
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
2947
|
+
},
|
|
2948
|
+
},
|
|
2949
|
+
},
|
|
2950
|
+
render: () => ({
|
|
2951
|
+
components: { UiDataTable },
|
|
2952
|
+
setup() {
|
|
2953
|
+
return { columns: sortableColumns, data: a11yTestData };
|
|
2954
|
+
},
|
|
2955
|
+
template: `<UiDataTable :columns="columns" :data="data" />`,
|
|
2956
|
+
}),
|
|
2957
|
+
play: async ({ canvasElement, step }) => {
|
|
2958
|
+
// Scenario (UiDataTable): at 200% page zoom the table stays visible and its
|
|
2959
|
+
// sort controls remain operable.
|
|
2960
|
+
const canvas = within(canvasElement);
|
|
2961
|
+
|
|
2962
|
+
await step(
|
|
2963
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
2964
|
+
async () => {
|
|
2965
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
2966
|
+
},
|
|
2967
|
+
);
|
|
2968
|
+
|
|
2969
|
+
await step('zoom: the table stays visible when magnified', async () => {
|
|
2970
|
+
await expect(canvas.getByRole('table')).toBeVisible();
|
|
2971
|
+
});
|
|
2972
|
+
|
|
2973
|
+
await step('zoom: a sortable header remains operable', async () => {
|
|
2974
|
+
const statusSort = canvas.getByRole('button', { name: /^Status/ });
|
|
2975
|
+
await userEvent.click(statusSort);
|
|
2976
|
+
await expect(statusSort).toHaveAccessibleName('Status, sorted ascending');
|
|
2977
|
+
});
|
|
2978
|
+
},
|
|
2979
|
+
};
|
|
2980
|
+
|
|
2981
|
+
/**
|
|
2982
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
2983
|
+
* toolbar. The table stays operable and its controls stay keyboard focusable.
|
|
2984
|
+
*/
|
|
2985
|
+
export const MobileBreakpoint: Story = {
|
|
2986
|
+
name: 'test - Mobile Breakpoint',
|
|
2987
|
+
tags: ['!dev', '!autodocs'],
|
|
2988
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
2989
|
+
parameters: {
|
|
2990
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
2991
|
+
chromatic: { disableSnapshot: true },
|
|
2992
|
+
docs: {
|
|
2993
|
+
description: {
|
|
2994
|
+
story:
|
|
2995
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
2996
|
+
},
|
|
2997
|
+
},
|
|
2998
|
+
},
|
|
2999
|
+
render: () => ({
|
|
3000
|
+
components: { UiDataTable },
|
|
3001
|
+
setup() {
|
|
3002
|
+
return { columns: sortableColumns, data: a11yTestData };
|
|
3003
|
+
},
|
|
3004
|
+
template: `<UiDataTable :columns="columns" :data="data" />`,
|
|
3005
|
+
}),
|
|
3006
|
+
play: async ({ canvasElement, step }) => {
|
|
3007
|
+
// Scenario (UiDataTable): at the 320px mobile breakpoint the table reflows
|
|
3008
|
+
// while staying operable by pointer and keyboard.
|
|
3009
|
+
const canvas = within(canvasElement);
|
|
3010
|
+
|
|
3011
|
+
await step(
|
|
3012
|
+
'mobile: the table renders and stays operable at the 320px breakpoint (WCAG 1.4.10 Reflow)',
|
|
3013
|
+
async () => {
|
|
3014
|
+
await expect(canvas.getByRole('table')).toBeVisible();
|
|
3015
|
+
const statusSort = canvas.getByRole('button', { name: /^Status/ });
|
|
3016
|
+
await userEvent.click(statusSort);
|
|
3017
|
+
await expect(statusSort).toHaveAccessibleName(
|
|
3018
|
+
'Status, sorted ascending',
|
|
3019
|
+
);
|
|
3020
|
+
},
|
|
3021
|
+
);
|
|
3022
|
+
|
|
3023
|
+
await step(
|
|
3024
|
+
'mobile: sortable headers stay keyboard focusable when reflowed',
|
|
3025
|
+
async () => {
|
|
3026
|
+
const emailSort = canvas.getByRole('button', { name: /^Email/ });
|
|
3027
|
+
emailSort.focus();
|
|
3028
|
+
await expect(emailSort).toHaveFocus();
|
|
3029
|
+
},
|
|
3030
|
+
);
|
|
3031
|
+
},
|
|
3032
|
+
};
|