@aleph-alpha/ui-library 5.9.0 → 5.10.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.js +157 -4
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +3 -1
- package/dist/system/components/UiFileType/types.d.ts +2 -1
- package/dist/system/components/UiSwitch/UiSwitch.vue.d.ts +1 -0
- package/dist/system/components/UiSwitch/types.d.ts +12 -0
- package/dist/system/components/core/switch/Switch.vue.d.ts +2 -0
- package/dist/system/components/core/switch/index.d.ts +8 -0
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/scrollbar.d.ts +37 -0
- package/dist/system/lib/useAnchorFloat.d.ts +0 -2
- package/dist/system/lib/useIsTruncated.d.ts +15 -0
- package/dist/system/lib.js +15052 -14843
- package/dist/system/patterns/UiFloatActions/types.d.ts +0 -1
- package/dist/system/story-sidebar-icons.json +4 -1
- package/docs/public-docs/foundations.md +17 -15
- package/package.json +3 -3
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +54 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +84 -32
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +65 -21
- package/src/components/UiFileItem/UiFileItem.vue +17 -4
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +49 -90
- package/src/components/UiFileType/UiFileType.stories.ts +13 -2
- package/src/components/UiFileType/UiFileType.vue +8 -0
- package/src/components/UiFileType/__tests__/UiFileType.test.ts +10 -0
- package/src/components/UiFileType/types.ts +3 -1
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +4 -5
- package/src/components/UiSwitch/UiSwitch.stories.ts +658 -7
- package/src/components/UiSwitch/UiSwitch.vue +1 -0
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +48 -0
- package/src/components/UiSwitch/types.ts +13 -0
- package/src/components/UiToggleGroup/UiToggleGroup.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/switch/Switch.vue +23 -17
- package/src/components/core/switch/index.ts +36 -0
- package/src/index.ts +3 -0
- package/src/lib/scrollbar.ts +295 -0
- package/src/lib/useAnchorFloat.ts +0 -2
- package/src/lib/useIsTruncated.test.ts +174 -0
- package/src/lib/useIsTruncated.ts +75 -0
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +1162 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +552 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +5 -21
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.vue +1 -2
- package/src/patterns/UiFloatActions/types.ts +0 -1
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +132 -117
- package/src/theme/Background.stories.ts +27 -1
- package/src/theme/BorderRadius.stories.ts +5 -0
- package/src/theme/Overlay.stories.ts +12 -1
- package/src/theme/Scrollbar.stories.ts +260 -0
- package/tokens.json +224 -2
- package/src/components/UiFileItem/UiFileItem.stories.ts +0 -442
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
2
|
import type { Ref } from 'vue';
|
|
3
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
3
4
|
import { onBeforeUnmount, ref } from 'vue';
|
|
4
5
|
import { UiButton } from '@/components/UiButton';
|
|
5
6
|
import {
|
|
@@ -15,7 +16,7 @@ import { formatFileSize } from '@/components/UiFileUploadBox/file-validation';
|
|
|
15
16
|
import UiFileUpload from './UiFileUpload.vue';
|
|
16
17
|
|
|
17
18
|
const meta: Meta<typeof UiFileUpload> = {
|
|
18
|
-
title: 'Patterns/UiFileUpload',
|
|
19
|
+
title: 'Patterns/UiFileUpload/UiFileUpload',
|
|
19
20
|
component: UiFileUpload,
|
|
20
21
|
tags: ['autodocs'],
|
|
21
22
|
decorators: [
|
|
@@ -767,3 +768,553 @@ export const CustomLabels: Story = {
|
|
|
767
768
|
supported-types-label="Archives: ZIP, TAR, GZ"`),
|
|
768
769
|
),
|
|
769
770
|
};
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Accessibility guidance for the uploader and accessible theme usage.
|
|
774
|
+
*/
|
|
775
|
+
export const Accessibility: Story = {
|
|
776
|
+
render: () => ({
|
|
777
|
+
components: { UiFileItem, UiFileUpload },
|
|
778
|
+
template: `
|
|
779
|
+
<section class="flex flex-col gap-6 p-4">
|
|
780
|
+
<div>
|
|
781
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
782
|
+
Accessibility
|
|
783
|
+
</h2>
|
|
784
|
+
</div>
|
|
785
|
+
|
|
786
|
+
<div class="flex flex-col gap-6">
|
|
787
|
+
<div class="flex flex-col gap-2">
|
|
788
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
789
|
+
Enable accessibility theme
|
|
790
|
+
</h3>
|
|
791
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
792
|
+
When accessibility is required, enable our accessibility theme. This increases contrast and makes sure there are no color contrast issues.
|
|
793
|
+
</p>
|
|
794
|
+
</div>
|
|
795
|
+
|
|
796
|
+
<div class="flex flex-col gap-2">
|
|
797
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
798
|
+
Name the drop zone and every file row
|
|
799
|
+
</h3>
|
|
800
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
801
|
+
The drop zone is a labelled button, so pass <code>ariaLabel</code> whenever more than one uploader shares a screen. Give each <code>UiFileItem</code> a <code>removeLabel</code> that names its file, otherwise a list of attachments exposes several identical "Remove file" controls.
|
|
802
|
+
</p>
|
|
803
|
+
</div>
|
|
804
|
+
|
|
805
|
+
<div class="flex flex-col gap-2">
|
|
806
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
807
|
+
Announce rejected files
|
|
808
|
+
</h3>
|
|
809
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
810
|
+
Render validation failures from <code>@error</code> as a file row with <code>error</code> set. The row puts the reason in an alert region, so it is announced instead of only turning red.
|
|
811
|
+
</p>
|
|
812
|
+
</div>
|
|
813
|
+
</div>
|
|
814
|
+
|
|
815
|
+
<div class="flex flex-col gap-3">
|
|
816
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
817
|
+
Default
|
|
818
|
+
</h3>
|
|
819
|
+
<div class="flex flex-col gap-3 border border-border-surface-default p-4">
|
|
820
|
+
<UiFileUpload
|
|
821
|
+
aria-label="Attachment upload"
|
|
822
|
+
accept=".pdf,.csv"
|
|
823
|
+
supported-types-label="Supported: PDF, CSV"
|
|
824
|
+
:max-file-size-bytes="10485760"
|
|
825
|
+
/>
|
|
826
|
+
<UiFileItem
|
|
827
|
+
filename="Quarterly report.csv"
|
|
828
|
+
type-label="CSV"
|
|
829
|
+
size-label="320 KB"
|
|
830
|
+
remove-label="Remove Quarterly report.csv"
|
|
831
|
+
/>
|
|
832
|
+
<UiFileItem filename="Archive.zip" error="Unsupported file type" remove-label="Dismiss Archive.zip" />
|
|
833
|
+
</div>
|
|
834
|
+
</div>
|
|
835
|
+
|
|
836
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
837
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
838
|
+
Accessible
|
|
839
|
+
</h3>
|
|
840
|
+
<div class="flex flex-col gap-3 border border-border-surface-default p-4">
|
|
841
|
+
<UiFileUpload
|
|
842
|
+
aria-label="Attachment upload"
|
|
843
|
+
accept=".pdf,.csv"
|
|
844
|
+
supported-types-label="Supported: PDF, CSV"
|
|
845
|
+
:max-file-size-bytes="10485760"
|
|
846
|
+
/>
|
|
847
|
+
<UiFileItem
|
|
848
|
+
filename="Quarterly report.csv"
|
|
849
|
+
type-label="CSV"
|
|
850
|
+
size-label="320 KB"
|
|
851
|
+
remove-label="Remove Quarterly report.csv"
|
|
852
|
+
/>
|
|
853
|
+
<UiFileItem filename="Archive.zip" error="Unsupported file type" remove-label="Dismiss Archive.zip" />
|
|
854
|
+
</div>
|
|
855
|
+
</div>
|
|
856
|
+
</section>
|
|
857
|
+
`,
|
|
858
|
+
}),
|
|
859
|
+
tags: ['!autodocs'],
|
|
860
|
+
parameters: {
|
|
861
|
+
a11y: { test: 'off' },
|
|
862
|
+
chromatic: {
|
|
863
|
+
disableSnapshot: true,
|
|
864
|
+
},
|
|
865
|
+
docs: {
|
|
866
|
+
canvas: {
|
|
867
|
+
sourceState: 'none',
|
|
868
|
+
},
|
|
869
|
+
},
|
|
870
|
+
},
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
/*
|
|
874
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
875
|
+
* Interaction & accessibility tests (play functions)
|
|
876
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
877
|
+
* How these tests are built and reported:
|
|
878
|
+
*
|
|
879
|
+
* - Every visible story above renders the uploader inside a *closed* dialog, so
|
|
880
|
+
* there is nothing to assert until the dialog opens — which would invalidate
|
|
881
|
+
* its Chromatic snapshot. All coverage therefore lives in the hidden
|
|
882
|
+
* `test - …` stories below, which render the uploader directly; the dialog
|
|
883
|
+
* composition itself is covered by `test - Dialog Integration`.
|
|
884
|
+
* - Assertions are grouped into category-labelled `step()` calls, which are
|
|
885
|
+
* parsed statically into the per-story CI summary. Between them these stories
|
|
886
|
+
* cover every report column:
|
|
887
|
+
* • `interaction:` opening the picker, disabled guards, footer hints
|
|
888
|
+
* • `keyboard:` Tab order, Enter / Space activation (WCAG 2.1.1)
|
|
889
|
+
* • `screen-reader:` drop-zone role and name, decorative parts (WCAG 4.1.2)
|
|
890
|
+
* • `zoom:` usable at 200% page zoom (WCAG 1.4.4)
|
|
891
|
+
* • `mobile:` 320px reflow + touch-target size (WCAG 1.4.10, 2.5.8)
|
|
892
|
+
* The Accessibility column is filled automatically by the axe audit that runs
|
|
893
|
+
* on every story — never add an `a11y:` prefix.
|
|
894
|
+
* - `accept` / `maxFileSizeBytes` validation and the drag-and-drop payload need a
|
|
895
|
+
* synthetic `FileList`, not a browser gesture, so they stay in Vitest under
|
|
896
|
+
* `__tests__/UiFileUpload.test.ts`. The plays assert the operable path instead:
|
|
897
|
+
* that pointer and keyboard both reach the picker (`pickerOpen`).
|
|
898
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
899
|
+
*/
|
|
900
|
+
|
|
901
|
+
// The uploader emits native-style events and declares no handler props, so the
|
|
902
|
+
// plays bind module-level spies via the template and clear them per story.
|
|
903
|
+
const onPickerOpen = fn();
|
|
904
|
+
const onUpdateFiles = fn();
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Renders the uploader on its own — no dialog — so plays can drive it without
|
|
908
|
+
* opening an overlay first.
|
|
909
|
+
* @param args - Story args passed through to `UiFileUpload`.
|
|
910
|
+
*/
|
|
911
|
+
function renderBareUpload(args: Story['args']) {
|
|
912
|
+
return {
|
|
913
|
+
components: { UiFileUpload },
|
|
914
|
+
setup() {
|
|
915
|
+
return { args, onPickerOpen, onUpdateFiles };
|
|
916
|
+
},
|
|
917
|
+
template: `
|
|
918
|
+
<UiFileUpload
|
|
919
|
+
v-bind="args"
|
|
920
|
+
@picker-open="onPickerOpen"
|
|
921
|
+
@update:files="onUpdateFiles"
|
|
922
|
+
/>
|
|
923
|
+
`,
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* The drop zone and the choose button both open the file picker, from pointer and
|
|
929
|
+
* from keyboard. Hidden test-only story.
|
|
930
|
+
*/
|
|
931
|
+
export const KeyboardNavigation: Story = {
|
|
932
|
+
name: 'test - Keyboard Navigation',
|
|
933
|
+
tags: ['!dev', '!autodocs'],
|
|
934
|
+
args: {
|
|
935
|
+
accept: '.pdf,.csv',
|
|
936
|
+
supportedTypesLabel: 'Supported: PDF, CSV',
|
|
937
|
+
maxFileSizeBytes: 10 * 1024 * 1024,
|
|
938
|
+
},
|
|
939
|
+
parameters: {
|
|
940
|
+
// Focus moves during the play function; skip the visual snapshot so the
|
|
941
|
+
// focus ring doesn't register as a Chromatic diff.
|
|
942
|
+
chromatic: { disableSnapshot: true },
|
|
943
|
+
controls: { disable: true },
|
|
944
|
+
docs: {
|
|
945
|
+
description: {
|
|
946
|
+
story:
|
|
947
|
+
'Press `Tab` to focus the drop zone, then `Enter` or `Space` to open the picker.',
|
|
948
|
+
},
|
|
949
|
+
},
|
|
950
|
+
},
|
|
951
|
+
render: (args) => renderBareUpload(args),
|
|
952
|
+
play: async ({ canvasElement, step }) => {
|
|
953
|
+
// Scenario (UiFileUpload): a keyboard-only user reaches the drop zone, opens
|
|
954
|
+
// the picker with either activation key, and can also tab on to the explicit
|
|
955
|
+
// choose button — so the uploader never depends on drag-and-drop.
|
|
956
|
+
onPickerOpen.mockClear();
|
|
957
|
+
const canvas = within(canvasElement);
|
|
958
|
+
const zone = canvas.getByRole('button', { name: 'File upload' });
|
|
959
|
+
const choose = canvas.getByRole('button', { name: 'Choose files' });
|
|
960
|
+
|
|
961
|
+
await step(
|
|
962
|
+
'keyboard: the drop zone is the first tab stop (WCAG 2.1.1)',
|
|
963
|
+
async () => {
|
|
964
|
+
await userEvent.tab();
|
|
965
|
+
await expect(zone).toHaveFocus();
|
|
966
|
+
},
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
await step('keyboard: Enter opens the file picker', async () => {
|
|
970
|
+
await userEvent.keyboard('{Enter}');
|
|
971
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
await step('keyboard: Space opens the file picker', async () => {
|
|
975
|
+
await userEvent.keyboard(' ');
|
|
976
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(2);
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
await step(
|
|
980
|
+
'keyboard: the choose button follows the drop zone in tab order (WCAG 2.4.3)',
|
|
981
|
+
async () => {
|
|
982
|
+
await userEvent.tab();
|
|
983
|
+
await expect(choose).toHaveFocus();
|
|
984
|
+
await userEvent.keyboard('{Enter}');
|
|
985
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(3);
|
|
986
|
+
},
|
|
987
|
+
);
|
|
988
|
+
|
|
989
|
+
await step(
|
|
990
|
+
'interaction: clicking the drop zone opens the picker too',
|
|
991
|
+
async () => {
|
|
992
|
+
await userEvent.click(zone);
|
|
993
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(4);
|
|
994
|
+
},
|
|
995
|
+
);
|
|
996
|
+
},
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* When disabled, the drop zone leaves the tab order, reports itself as disabled,
|
|
1001
|
+
* and neither control opens the picker. Hidden test-only story.
|
|
1002
|
+
*/
|
|
1003
|
+
export const DisabledGuards: Story = {
|
|
1004
|
+
name: 'test - Disabled Guards',
|
|
1005
|
+
tags: ['!dev', '!autodocs'],
|
|
1006
|
+
args: {
|
|
1007
|
+
disabled: true,
|
|
1008
|
+
accept: '.pdf',
|
|
1009
|
+
supportedTypesLabel: 'PDF (disabled)',
|
|
1010
|
+
},
|
|
1011
|
+
parameters: {
|
|
1012
|
+
// The play moves focus to prove the zone is skipped.
|
|
1013
|
+
chromatic: { disableSnapshot: true },
|
|
1014
|
+
controls: { disable: true },
|
|
1015
|
+
docs: {
|
|
1016
|
+
description: {
|
|
1017
|
+
story:
|
|
1018
|
+
'A disabled uploader must be unreachable by keyboard and inert to clicks.',
|
|
1019
|
+
},
|
|
1020
|
+
},
|
|
1021
|
+
},
|
|
1022
|
+
render: (args) => renderBareUpload(args),
|
|
1023
|
+
play: async ({ canvasElement, step }) => {
|
|
1024
|
+
// Scenario (UiFileUpload): while uploads are blocked the zone must not look
|
|
1025
|
+
// operable to any input method — no tab stop, no click-through to the picker.
|
|
1026
|
+
onPickerOpen.mockClear();
|
|
1027
|
+
const canvas = within(canvasElement);
|
|
1028
|
+
const zone = canvas.getByRole('button', { name: 'File upload' });
|
|
1029
|
+
|
|
1030
|
+
await step(
|
|
1031
|
+
'screen-reader: the drop zone reports its disabled state (WCAG 4.1.2)',
|
|
1032
|
+
async () => {
|
|
1033
|
+
await expect(zone).toHaveAttribute('aria-disabled', 'true');
|
|
1034
|
+
},
|
|
1035
|
+
);
|
|
1036
|
+
|
|
1037
|
+
await step(
|
|
1038
|
+
'keyboard: the disabled drop zone is out of the tab order (WCAG 2.1.1)',
|
|
1039
|
+
async () => {
|
|
1040
|
+
await expect(zone).toHaveAttribute('tabindex', '-1');
|
|
1041
|
+
await userEvent.tab();
|
|
1042
|
+
await expect(zone).not.toHaveFocus();
|
|
1043
|
+
},
|
|
1044
|
+
);
|
|
1045
|
+
|
|
1046
|
+
await step('interaction: clicks do not open the picker', async () => {
|
|
1047
|
+
await userEvent.click(zone);
|
|
1048
|
+
await expect(onPickerOpen).not.toHaveBeenCalled();
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
await step(
|
|
1052
|
+
'interaction: the choose button is disabled and stays silent',
|
|
1053
|
+
async () => {
|
|
1054
|
+
const choose = canvas.getByRole('button', { name: 'Choose files' });
|
|
1055
|
+
await expect(choose).toBeDisabled();
|
|
1056
|
+
// A disabled UiButton sets `pointer-events: none`, which makes
|
|
1057
|
+
// `userEvent.click` throw instead of no-op; bypass the check so the
|
|
1058
|
+
// guard itself is what gets asserted.
|
|
1059
|
+
await userEvent.click(choose, { pointerEventsCheck: 0 });
|
|
1060
|
+
await expect(onPickerOpen).not.toHaveBeenCalled();
|
|
1061
|
+
},
|
|
1062
|
+
);
|
|
1063
|
+
},
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* Screen-reader semantics: the drop zone is a named button, its illustration is
|
|
1068
|
+
* decorative, the file input is hidden from assistive tech, and the footer hints
|
|
1069
|
+
* are readable text. Hidden test-only story.
|
|
1070
|
+
*/
|
|
1071
|
+
export const ScreenReader: Story = {
|
|
1072
|
+
name: 'test - Screen Reader',
|
|
1073
|
+
tags: ['!dev', '!autodocs'],
|
|
1074
|
+
args: {
|
|
1075
|
+
ariaLabel: 'Attachment upload',
|
|
1076
|
+
dropLabel: 'Drop files here',
|
|
1077
|
+
chooseLabel: 'Choose files',
|
|
1078
|
+
accept: '.pdf,.csv',
|
|
1079
|
+
supportedTypesLabel: 'Supported: PDF, CSV',
|
|
1080
|
+
maxFileSizeBytes: 1024 * 1024,
|
|
1081
|
+
maxSizeLabel: '',
|
|
1082
|
+
},
|
|
1083
|
+
parameters: {
|
|
1084
|
+
controls: { disable: true },
|
|
1085
|
+
docs: {
|
|
1086
|
+
description: {
|
|
1087
|
+
story:
|
|
1088
|
+
'Verifies the roles, names, and hidden decorations the uploader exposes.',
|
|
1089
|
+
},
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
1092
|
+
render: (args) => renderBareUpload(args),
|
|
1093
|
+
play: async ({ canvasElement, step }) => {
|
|
1094
|
+
// Scenario (UiFileUpload): assistive tech finds one named button for the drop
|
|
1095
|
+
// zone plus one for the picker, is not told about the cloud illustration or
|
|
1096
|
+
// the hidden input, and can still read the accept/size hints.
|
|
1097
|
+
const canvas = within(canvasElement);
|
|
1098
|
+
|
|
1099
|
+
await step(
|
|
1100
|
+
'screen-reader: the drop zone exposes a button role named by ariaLabel (WCAG 4.1.2)',
|
|
1101
|
+
async () => {
|
|
1102
|
+
const zone = canvas.getByRole('button', { name: 'Attachment upload' });
|
|
1103
|
+
await expect(zone).toHaveAccessibleName('Attachment upload');
|
|
1104
|
+
await expect(zone).toHaveAttribute('tabindex', '0');
|
|
1105
|
+
},
|
|
1106
|
+
);
|
|
1107
|
+
|
|
1108
|
+
await step(
|
|
1109
|
+
'screen-reader: the visible drop label and footer hints are readable text',
|
|
1110
|
+
async () => {
|
|
1111
|
+
await expect(canvas.getByText('Drop files here')).toBeVisible();
|
|
1112
|
+
await expect(canvas.getByText('Supported: PDF, CSV')).toBeVisible();
|
|
1113
|
+
// Blank `maxSizeLabel` falls back to a formatted `maxFileSizeBytes`.
|
|
1114
|
+
await expect(canvas.getByText('Max size: 1.0 MB')).toBeVisible();
|
|
1115
|
+
},
|
|
1116
|
+
);
|
|
1117
|
+
|
|
1118
|
+
await step(
|
|
1119
|
+
'screen-reader: the file input and the illustration are hidden from assistive tech',
|
|
1120
|
+
async () => {
|
|
1121
|
+
const input = canvasElement.querySelector('input[type="file"]');
|
|
1122
|
+
await expect(input).toHaveAttribute('aria-hidden', 'true');
|
|
1123
|
+
await expect(input).toHaveAttribute('tabindex', '-1');
|
|
1124
|
+
// The cloud illustration sits inside the drop zone, so it must be hidden
|
|
1125
|
+
// or it would leak into the zone's accessible name.
|
|
1126
|
+
const zone = canvas.getByRole('button', { name: 'Attachment upload' });
|
|
1127
|
+
await expect(
|
|
1128
|
+
zone.querySelector('[aria-hidden="true"]'),
|
|
1129
|
+
).toBeInTheDocument();
|
|
1130
|
+
},
|
|
1131
|
+
);
|
|
1132
|
+
},
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
1137
|
+
* try 400% reflow (WCAG 1.4.10); the drop zone must stay visible and operable.
|
|
1138
|
+
* Hidden test-only story.
|
|
1139
|
+
*/
|
|
1140
|
+
export const ZoomMagnification: Story = {
|
|
1141
|
+
name: 'test - Zoom Magnification',
|
|
1142
|
+
tags: ['!dev', '!autodocs'],
|
|
1143
|
+
globals: { zoom: '200' },
|
|
1144
|
+
args: {
|
|
1145
|
+
accept: '.pdf,.csv',
|
|
1146
|
+
supportedTypesLabel: 'Supported: PDF, CSV',
|
|
1147
|
+
},
|
|
1148
|
+
parameters: {
|
|
1149
|
+
// The accessible-reflow Chromatic mode already covers magnified snapshots.
|
|
1150
|
+
chromatic: { disableSnapshot: true },
|
|
1151
|
+
controls: { disable: true },
|
|
1152
|
+
docs: {
|
|
1153
|
+
description: {
|
|
1154
|
+
story:
|
|
1155
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
},
|
|
1159
|
+
render: (args) => renderBareUpload(args),
|
|
1160
|
+
play: async ({ canvasElement, step }) => {
|
|
1161
|
+
// Scenario (UiFileUpload): at 200% page zoom the drop zone keeps its label and
|
|
1162
|
+
// still opens the picker, so a low-vision user is not pushed into using
|
|
1163
|
+
// drag-and-drop.
|
|
1164
|
+
onPickerOpen.mockClear();
|
|
1165
|
+
const canvas = within(canvasElement);
|
|
1166
|
+
const zone = canvas.getByRole('button', { name: 'File upload' });
|
|
1167
|
+
|
|
1168
|
+
await step(
|
|
1169
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1170
|
+
async () => {
|
|
1171
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1172
|
+
},
|
|
1173
|
+
);
|
|
1174
|
+
|
|
1175
|
+
await step('zoom: the drop zone stays visible and labelled', async () => {
|
|
1176
|
+
await expect(zone).toBeVisible();
|
|
1177
|
+
await expect(canvas.getByText('Drop files here')).toBeVisible();
|
|
1178
|
+
await expect(canvas.getByText('Supported: PDF, CSV')).toBeVisible();
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
await step('zoom: the picker still opens when magnified', async () => {
|
|
1182
|
+
await userEvent.click(zone);
|
|
1183
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
1184
|
+
});
|
|
1185
|
+
},
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
1190
|
+
* toolbar. The uploader fits without sideways scrolling and both controls stay
|
|
1191
|
+
* tappable. Hidden test-only story.
|
|
1192
|
+
*/
|
|
1193
|
+
export const MobileBreakpoint: Story = {
|
|
1194
|
+
name: 'test - Mobile Breakpoint',
|
|
1195
|
+
tags: ['!dev', '!autodocs'],
|
|
1196
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1197
|
+
args: {
|
|
1198
|
+
accept: '.pdf,.csv',
|
|
1199
|
+
supportedTypesLabel: 'Supported: PDF, CSV',
|
|
1200
|
+
maxFileSizeBytes: 10 * 1024 * 1024,
|
|
1201
|
+
},
|
|
1202
|
+
parameters: {
|
|
1203
|
+
// The play activates the picker; reflow snapshots are covered by the
|
|
1204
|
+
// accessible-reflow Chromatic mode.
|
|
1205
|
+
chromatic: { disableSnapshot: true },
|
|
1206
|
+
controls: { disable: true },
|
|
1207
|
+
docs: {
|
|
1208
|
+
description: {
|
|
1209
|
+
story:
|
|
1210
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1211
|
+
},
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
render: (args) => renderBareUpload(args),
|
|
1215
|
+
play: async ({ canvasElement, step }) => {
|
|
1216
|
+
// Scenario (UiFileUpload): at 320px the drop zone and its footer reflow into
|
|
1217
|
+
// the narrow column, and both the zone and the choose button stay large
|
|
1218
|
+
// enough to tap.
|
|
1219
|
+
onPickerOpen.mockClear();
|
|
1220
|
+
const canvas = within(canvasElement);
|
|
1221
|
+
const zone = canvas.getByRole('button', { name: 'File upload' });
|
|
1222
|
+
const choose = canvas.getByRole('button', { name: 'Choose files' });
|
|
1223
|
+
|
|
1224
|
+
await step(
|
|
1225
|
+
'mobile: the uploader fits the 320px viewport without sideways scrolling (WCAG 1.4.10 Reflow)',
|
|
1226
|
+
async () => {
|
|
1227
|
+
await expect(zone).toBeVisible();
|
|
1228
|
+
await expect(zone.getBoundingClientRect().width).toBeLessThanOrEqual(
|
|
1229
|
+
window.innerWidth,
|
|
1230
|
+
);
|
|
1231
|
+
},
|
|
1232
|
+
);
|
|
1233
|
+
|
|
1234
|
+
await step(
|
|
1235
|
+
'mobile: both controls meet the minimum touch-target size (WCAG 2.5.8)',
|
|
1236
|
+
async () => {
|
|
1237
|
+
const zoneBox = zone.getBoundingClientRect();
|
|
1238
|
+
await expect(zoneBox.width).toBeGreaterThanOrEqual(24);
|
|
1239
|
+
await expect(zoneBox.height).toBeGreaterThanOrEqual(24);
|
|
1240
|
+
const chooseBox = choose.getBoundingClientRect();
|
|
1241
|
+
await expect(chooseBox.width).toBeGreaterThanOrEqual(24);
|
|
1242
|
+
await expect(chooseBox.height).toBeGreaterThanOrEqual(24);
|
|
1243
|
+
},
|
|
1244
|
+
);
|
|
1245
|
+
|
|
1246
|
+
await step('mobile: the picker still opens at 320px', async () => {
|
|
1247
|
+
await userEvent.click(choose);
|
|
1248
|
+
await expect(onPickerOpen).toHaveBeenCalledTimes(1);
|
|
1249
|
+
});
|
|
1250
|
+
},
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* The dialog composition: opening the dialog reveals the uploader, and picked
|
|
1255
|
+
* files are listed as `UiFileItem` rows in a labelled list. Hidden test-only
|
|
1256
|
+
* story.
|
|
1257
|
+
*/
|
|
1258
|
+
export const DialogIntegration: Story = {
|
|
1259
|
+
name: 'test - Dialog Integration',
|
|
1260
|
+
tags: ['!dev', '!autodocs'],
|
|
1261
|
+
parameters: {
|
|
1262
|
+
// Opening the dialog replaces the trigger-only view.
|
|
1263
|
+
chromatic: { disableSnapshot: true },
|
|
1264
|
+
controls: { disable: true },
|
|
1265
|
+
docs: {
|
|
1266
|
+
description: {
|
|
1267
|
+
story:
|
|
1268
|
+
'Covers the dialog shell used by every visible story: trigger, drop zone, and the empty file list.',
|
|
1269
|
+
},
|
|
1270
|
+
},
|
|
1271
|
+
},
|
|
1272
|
+
render: (args) => renderInDialog(args),
|
|
1273
|
+
play: async ({ canvasElement, step }) => {
|
|
1274
|
+
// Scenario (UiFileUpload): a user opens the upload dialog from a trigger and
|
|
1275
|
+
// finds the drop zone and its hints inside, with no file list until something
|
|
1276
|
+
// is picked. The dialog is portalled out of the canvas, so its content is
|
|
1277
|
+
// queried against the body.
|
|
1278
|
+
const canvas = within(canvasElement);
|
|
1279
|
+
const body = within(document.body);
|
|
1280
|
+
const trigger = canvas.getByRole('button', { name: 'Open file upload' });
|
|
1281
|
+
|
|
1282
|
+
await step(
|
|
1283
|
+
'interaction: the trigger opens a labelled dialog containing the uploader',
|
|
1284
|
+
async () => {
|
|
1285
|
+
await userEvent.click(trigger);
|
|
1286
|
+
const dialog = await body.findByRole('dialog');
|
|
1287
|
+
// The dialog fades and zooms in, and `toBeVisible` fails while the
|
|
1288
|
+
// opening keyframe still holds opacity at 0 — wait for it to settle.
|
|
1289
|
+
await waitFor(async () => {
|
|
1290
|
+
await expect(dialog).toBeVisible();
|
|
1291
|
+
});
|
|
1292
|
+
await expect(
|
|
1293
|
+
body.getByRole('button', { name: 'File upload' }),
|
|
1294
|
+
).toBeVisible();
|
|
1295
|
+
await expect(
|
|
1296
|
+
body.getByText('Supported file types: PDF, DOCX, TXT'),
|
|
1297
|
+
).toBeVisible();
|
|
1298
|
+
},
|
|
1299
|
+
);
|
|
1300
|
+
|
|
1301
|
+
await step(
|
|
1302
|
+
'interaction: no file list is rendered until a file is picked',
|
|
1303
|
+
async () => {
|
|
1304
|
+
await expect(
|
|
1305
|
+
body.queryByRole('list', { name: 'Selected files' }),
|
|
1306
|
+
).not.toBeInTheDocument();
|
|
1307
|
+
},
|
|
1308
|
+
);
|
|
1309
|
+
|
|
1310
|
+
await step(
|
|
1311
|
+
'screen-reader: the dialog is titled and its close control is labelled (WCAG 4.1.2)',
|
|
1312
|
+
async () => {
|
|
1313
|
+
await expect(body.getByText('File upload')).toBeVisible();
|
|
1314
|
+
await expect(
|
|
1315
|
+
body.getByRole('button', { name: 'Close dialog' }),
|
|
1316
|
+
).toHaveAccessibleName('Close dialog');
|
|
1317
|
+
},
|
|
1318
|
+
);
|
|
1319
|
+
},
|
|
1320
|
+
};
|
|
@@ -3,16 +3,11 @@ import { describe, expect, test } from 'vitest';
|
|
|
3
3
|
import UiFileUpload from '../UiFileUpload.vue';
|
|
4
4
|
|
|
5
5
|
describe('UiFileUpload', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
expect(getByText('Drop files here')).toBeInTheDocument();
|
|
14
|
-
expect(getByRole('button', { name: 'Choose files' })).toBeInTheDocument();
|
|
15
|
-
});
|
|
6
|
+
// Labels, roles, focus order, and the disabled guards are covered by the play
|
|
7
|
+
// stories in `UiFileUpload.stories.ts` (`test - Keyboard Navigation`,
|
|
8
|
+
// `test - Disabled Guards`, `test - Screen Reader`, `test - Mobile Breakpoint`).
|
|
9
|
+
// What stays here is validation: it needs a synthetic `FileList`/`DataTransfer`
|
|
10
|
+
// rather than a browser gesture.
|
|
16
11
|
|
|
17
12
|
test('emits dragenter and drop with DragEvent', async () => {
|
|
18
13
|
const { getByRole, emitted } = render(UiFileUpload);
|
|
@@ -93,17 +88,6 @@ describe('UiFileUpload', () => {
|
|
|
93
88
|
expect(getByText('Max size: 1.0 MB')).toBeInTheDocument();
|
|
94
89
|
});
|
|
95
90
|
|
|
96
|
-
test('when disabled, drop zone is not in tab order', () => {
|
|
97
|
-
const { container } = render(UiFileUpload, {
|
|
98
|
-
props: { disabled: true, ariaLabel: 'Attachment upload' },
|
|
99
|
-
});
|
|
100
|
-
const zone = container.querySelector(
|
|
101
|
-
'[aria-label="Attachment upload"]',
|
|
102
|
-
) as HTMLElement;
|
|
103
|
-
expect(zone).toBeTruthy();
|
|
104
|
-
expect(zone.getAttribute('tabindex')).toBe('-1');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
91
|
test('emits error for file failing accept', async () => {
|
|
108
92
|
const { container, emitted } = render(UiFileUpload, {
|
|
109
93
|
props: {
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Use the root (default `type="toolbar"`) as the container and nest child items
|
|
6
6
|
* for buttons, inputs, text labels, groups, and separators. Follows the WAI-ARIA
|
|
7
7
|
* APG toolbar pattern with roving arrow-key navigation.
|
|
8
|
-
*
|
|
9
8
|
* @component UiFloatActionItems
|
|
10
9
|
* @property {'toolbar' | 'button' | 'input' | 'text' | 'group' | 'separator'} [type='toolbar'] -
|
|
11
10
|
* Item role. Omit or use `toolbar` for the root pill container.
|
|
@@ -1366,7 +1366,6 @@ export const HoverTriggerKeyboard: Story = {
|
|
|
1366
1366
|
// Scenario (UiFloatActions): a `hover` trigger must also open on keyboard
|
|
1367
1367
|
// focus so keyboard-only users reach the same actions as pointer users.
|
|
1368
1368
|
// Tabbing to the anchor opens the teleported panel (queried on the body).
|
|
1369
|
-
const canvas = within(canvasElement);
|
|
1370
1369
|
const body = within(document.body);
|
|
1371
1370
|
const anchor = canvasElement.querySelector(
|
|
1372
1371
|
'[data-slot="float-anchor"]',
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* Use for contextual toolbars, quick actions, and inline controls that appear
|
|
6
6
|
* on hover, focus, or click. Pair with {@link UiFloatActionItems} for pill-shaped
|
|
7
7
|
* action bars. For rich panels or forms, prefer {@link UiPopover}.
|
|
8
|
-
*
|
|
9
8
|
* @component UiFloatActions
|
|
10
9
|
* @property {'hover' | 'focus' | 'click' | 'manual'} [trigger='hover'] -
|
|
11
10
|
* How the panel opens. `hover` opens on pointer hover and keyboard focus
|
|
@@ -168,8 +167,8 @@ const floatingAnimationClass = computed(() =>
|
|
|
168
167
|
<!-- Button for click/focus; focusable span for hover (text stays selectable). -->
|
|
169
168
|
<!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
|
|
170
169
|
<component
|
|
171
|
-
v-if="usesButtonAnchor || isHoverTrigger"
|
|
172
170
|
:is="usesButtonAnchor ? 'button' : 'span'"
|
|
171
|
+
v-if="usesButtonAnchor || isHoverTrigger"
|
|
173
172
|
ref="referenceRef"
|
|
174
173
|
:type="usesButtonAnchor ? 'button' : undefined"
|
|
175
174
|
:tabindex="isHoverTrigger ? 0 : undefined"
|
|
@@ -112,7 +112,6 @@ export type UiFloatActionItemsValue = string | number;
|
|
|
112
112
|
* Use the root item (`type="toolbar"`) as the container and nest child items
|
|
113
113
|
* for buttons, inputs, text labels, groups, and separators. Implements the
|
|
114
114
|
* WAI-ARIA APG toolbar pattern with roving tabindex.
|
|
115
|
-
*
|
|
116
115
|
* @category Overlays
|
|
117
116
|
* @useCases contextual toolbar, inline actions, pagination controls, filter bar
|
|
118
117
|
* @keywords float, toolbar, pill, actions, keyboard, roving focus
|