@aleph-alpha/ui-library 5.4.0 → 5.6.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.
Files changed (59) hide show
  1. package/config.d.ts +9 -0
  2. package/config.js +12 -3
  3. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
  4. package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
  5. package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
  6. package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
  7. package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
  8. package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
  9. package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
  10. package/dist/system/components/core/button-group/index.d.ts +8 -0
  11. package/dist/system/components/index.d.ts +1 -0
  12. package/dist/system/lib.js +8878 -8692
  13. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
  14. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
  15. package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
  16. package/dist/system/story-sidebar-icons.json +8 -1
  17. package/package.json +5 -3
  18. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
  19. package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
  20. package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
  21. package/src/components/UiButton/UiButton.stories.ts +9 -9
  22. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
  23. package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
  24. package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
  25. package/src/components/UiButtonGroup/index.ts +2 -0
  26. package/src/components/UiButtonGroup/types.ts +21 -0
  27. package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
  28. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
  29. package/src/components/UiField/UiField.stories.ts +608 -1
  30. package/src/components/UiField/UiFieldDescription.vue +7 -2
  31. package/src/components/UiInput/UiInput.stories.ts +336 -2
  32. package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
  33. package/src/components/UiItem/UiItem.stories.ts +236 -1
  34. package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
  35. package/src/components/UiSelect/UiSelect.stories.ts +769 -0
  36. package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
  37. package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
  38. package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
  39. package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
  40. package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
  41. package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
  42. package/src/components/core/button-group/ButtonGroup.vue +24 -0
  43. package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
  44. package/src/components/core/button-group/ButtonGroupText.vue +33 -0
  45. package/src/components/core/button-group/index.ts +25 -0
  46. package/src/components/core/checkbox/Checkbox.vue +0 -1
  47. package/src/components/core/select/SelectTrigger.vue +1 -1
  48. package/src/components/core/tabs/TabsTrigger.vue +1 -1
  49. package/src/components/index.ts +1 -0
  50. package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
  51. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  52. package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
  53. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
  54. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
  55. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
  56. package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
  57. package/src/patterns/UiFloatActions/types.ts +28 -1
  58. package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
  59. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
@@ -57,48 +57,70 @@ describe('UiFloatActionItems', () => {
57
57
  expect(onClick).toHaveBeenCalledTimes(1);
58
58
  });
59
59
 
60
- test('renders input item with accessible label', () => {
60
+ test('marks the active item and emits update:modelValue when v-model is used', async () => {
61
+ const onUpdate = vi.fn();
61
62
  const { getByRole } = render({
62
63
  components: { UiFloatActionItems },
64
+ setup() {
65
+ return { onUpdate };
66
+ },
63
67
  template: `
64
- <UiFloatActionItems aria-label="Search actions">
65
- <UiFloatActionItems
66
- type="input"
67
- aria-label="Search"
68
- placeholder="Filter..."
69
- />
68
+ <UiFloatActionItems
69
+ aria-label="View"
70
+ model-value="grid"
71
+ @update:model-value="onUpdate"
72
+ >
73
+ <UiFloatActionItems type="button" value="grid" aria-label="Grid">Grid</UiFloatActionItems>
74
+ <UiFloatActionItems type="button" value="list" aria-label="List">List</UiFloatActionItems>
70
75
  </UiFloatActionItems>
71
76
  `,
72
77
  });
73
78
 
74
- expect(getByRole('textbox', { name: 'Search' })).toHaveAttribute(
75
- 'placeholder',
76
- 'Filter...',
77
- );
79
+ const grid = getByRole('button', { name: 'Grid' });
80
+ const list = getByRole('button', { name: 'List' });
81
+
82
+ expect(grid).toHaveAttribute('aria-pressed', 'true');
83
+ expect(list).toHaveAttribute('aria-pressed', 'false');
84
+
85
+ await list.click();
86
+ expect(onUpdate).toHaveBeenCalledWith('list');
78
87
  });
79
88
 
80
- test('moves focus with arrow keys inside toolbar', async () => {
81
- const { getByRole } = render({
89
+ test('renders no active indicator or pressed state without v-model', () => {
90
+ const { getByRole, container } = render({
82
91
  components: { UiFloatActionItems },
83
92
  template: `
84
93
  <UiFloatActionItems aria-label="Actions">
85
- <UiFloatActionItems type="button" aria-label="Edit">Edit</UiFloatActionItems>
86
- <UiFloatActionItems type="button" aria-label="Copy">Copy</UiFloatActionItems>
94
+ <UiFloatActionItems type="button" value="grid" aria-label="Grid">Grid</UiFloatActionItems>
87
95
  </UiFloatActionItems>
88
96
  `,
89
97
  });
90
98
 
91
- const toolbar = getByRole('toolbar', { name: 'Actions' });
92
- const editButton = getByRole('button', { name: 'Edit' });
93
- const copyButton = getByRole('button', { name: 'Copy' });
99
+ expect(getByRole('button', { name: 'Grid' })).not.toHaveAttribute(
100
+ 'aria-pressed',
101
+ );
102
+ expect(
103
+ container.querySelector('[data-slot="float-item-indicator"]'),
104
+ ).toBeNull();
105
+ });
94
106
 
95
- editButton.focus();
96
- expect(document.activeElement).toBe(editButton);
107
+ test('renders input item with accessible label', () => {
108
+ const { getByRole } = render({
109
+ components: { UiFloatActionItems },
110
+ template: `
111
+ <UiFloatActionItems aria-label="Search actions">
112
+ <UiFloatActionItems
113
+ type="input"
114
+ aria-label="Search"
115
+ placeholder="Filter..."
116
+ />
117
+ </UiFloatActionItems>
118
+ `,
119
+ });
97
120
 
98
- toolbar.dispatchEvent(
99
- new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }),
121
+ expect(getByRole('textbox', { name: 'Search' })).toHaveAttribute(
122
+ 'placeholder',
123
+ 'Filter...',
100
124
  );
101
-
102
- expect(document.activeElement).toBe(copyButton);
103
125
  });
104
126
  });
@@ -1,9 +1,18 @@
1
1
  import type { InjectionKey, Ref } from 'vue';
2
+ import type { UiFloatActionItemsValue } from './types';
3
+
4
+ /** Metadata a child item shares with the toolbar when it registers. */
5
+ export interface FloatActionItemRegistration {
6
+ /** Live getter for the item's root element (used to position the indicator). */
7
+ el: () => HTMLElement | null;
8
+ /** Live getter for the item's `value`, if it is a selectable item. */
9
+ value: () => UiFloatActionItemsValue | undefined;
10
+ }
2
11
 
3
12
  /** Shared toolbar state used to coordinate roving-tabindex focus across items. */
4
13
  export interface FloatActionItemContext {
5
14
  /** Registers a focusable item so the toolbar can manage roving tabindex. */
6
- registerItem: (id: symbol) => void;
15
+ registerItem: (id: symbol, registration: FloatActionItemRegistration) => void;
7
16
  /** Removes an item from roving-tabindex tracking. */
8
17
  unregisterItem: (id: symbol) => void;
9
18
  /** Marks an item as the active (tabbable) one when it receives focus. */
@@ -12,6 +21,12 @@ export interface FloatActionItemContext {
12
21
  getTabIndex: (id: symbol) => number;
13
22
  /** Keyboard navigation direction for the toolbar. */
14
23
  orientation: Ref<'horizontal' | 'vertical'>;
24
+ /** Whether the toolbar is a `v-model`-driven single-select control. */
25
+ hasModel: Ref<boolean>;
26
+ /** Currently selected value when the toolbar is `v-model`-driven. */
27
+ modelValue: Ref<UiFloatActionItemsValue | undefined>;
28
+ /** Selects a value, emitting `update:modelValue` from the toolbar. */
29
+ select: (value: UiFloatActionItemsValue) => void;
15
30
  }
16
31
 
17
32
  export const FLOAT_ACTION_ITEM_CONTEXT: InjectionKey<FloatActionItemContext> =
@@ -102,6 +102,9 @@ export type UiFloatActionItemsType =
102
102
  /** Arrow-key navigation direction for toolbar roving focus. */
103
103
  export type UiFloatActionItemsOrientation = 'horizontal' | 'vertical';
104
104
 
105
+ /** Value identifying a selectable `button` item within a toolbar. */
106
+ export type UiFloatActionItemsValue = string | number;
107
+
105
108
  /**
106
109
  * Pill-shaped floating toolbar and its action items.
107
110
  *
@@ -144,12 +147,36 @@ export interface UiFloatActionItemsProps {
144
147
  * Placeholder text for `input` items.
145
148
  */
146
149
  placeholder?: string;
150
+
151
+ /**
152
+ * Selected item value for the `toolbar` container.
153
+ * Use `v-model` to turn the toolbar into a single-select control: the active
154
+ * `button` item (the one whose `value` matches) gets a sliding background
155
+ * indicator. Omit for a plain, stateless action bar.
156
+ * @example
157
+ * ```vue
158
+ * <UiFloatActionItems v-model="view" aria-label="View">
159
+ * <UiFloatActionItems type="button" value="grid" aria-label="Grid" />
160
+ * <UiFloatActionItems type="button" value="list" aria-label="List" />
161
+ * </UiFloatActionItems>
162
+ * ```
163
+ */
164
+ modelValue?: UiFloatActionItemsValue;
165
+
166
+ /**
167
+ * Value of a selectable `button` item.
168
+ * When the parent toolbar uses `v-model`, clicking this item selects its
169
+ * `value` and moves the active indicator onto it.
170
+ */
171
+ value?: UiFloatActionItemsValue;
147
172
  }
148
173
 
149
- /** Events emitted by {@link UiFloatActionItems} button items. */
174
+ /** Events emitted by {@link UiFloatActionItems}. */
150
175
  export interface UiFloatActionItemsEmits {
151
176
  /** Emitted when a `button` item is activated. */
152
177
  click: [event: MouseEvent];
178
+ /** Emitted by a `toolbar` with `v-model` when the selected value changes. */
179
+ 'update:modelValue': [value: UiFloatActionItemsValue];
153
180
  }
154
181
 
155
182
  export type UiFloatActionItemsClass = HTMLAttributes['class'];
@@ -1,39 +0,0 @@
1
- import { render } from '@testing-library/vue';
2
- import { describe, expect, test } from 'vitest';
3
- import { UiFieldError } from '../index';
4
-
5
- describe('UiFieldError', () => {
6
- test('renders single error as text', () => {
7
- const { getByRole } = render(UiFieldError, {
8
- props: { errors: ['Required'] },
9
- });
10
-
11
- expect(getByRole('alert')).toHaveTextContent('Required');
12
- });
13
-
14
- test('renders an alert when errors are provided', () => {
15
- const { getByRole } = render(UiFieldError, {
16
- props: {
17
- errors: [
18
- 'Too short',
19
- { message: 'Too short' },
20
- { message: 'Invalid format' },
21
- ],
22
- },
23
- });
24
-
25
- expect(getByRole('alert')).toBeInTheDocument();
26
- });
27
-
28
- test('prefers slot content over errors rendering', () => {
29
- const { getByRole } = render(UiFieldError, {
30
- props: { errors: ['Required'] },
31
- slots: {
32
- default: 'Custom error slot',
33
- },
34
- });
35
-
36
- expect(getByRole('alert')).toHaveTextContent('Custom error slot');
37
- expect(getByRole('alert')).not.toHaveTextContent('Required');
38
- });
39
- });
@@ -1,152 +0,0 @@
1
- import { render } from '@testing-library/vue';
2
- import { describe, expect, test } from 'vitest';
3
- import { nextTick } from 'vue';
4
- import { UiFloatActions, UiFloatActionItems } from '../index';
5
-
6
- describe('UiFloatActions accessibility', () => {
7
- test('focus trigger opens panel and exposes popup semantics', async () => {
8
- const { getByRole } = render({
9
- components: { UiFloatActions, UiFloatActionItems },
10
- template: `
11
- <UiFloatActions trigger="focus" aria-label="Paragraph actions">
12
- <template #container>
13
- <span>Target paragraph</span>
14
- </template>
15
- <template #action>
16
- <UiFloatActionItems aria-label="Actions">
17
- <UiFloatActionItems type="button" aria-label="Edit">Edit</UiFloatActionItems>
18
- </UiFloatActionItems>
19
- </template>
20
- </UiFloatActions>
21
- `,
22
- });
23
-
24
- const anchor = getByRole('button', { name: 'Paragraph actions' });
25
- expect(anchor.tagName).toBe('BUTTON');
26
- expect(anchor).toHaveAttribute('aria-haspopup', 'true');
27
- expect(anchor).toHaveAttribute('aria-expanded', 'false');
28
-
29
- anchor.focus();
30
- await nextTick();
31
-
32
- expect(anchor).toHaveAttribute('aria-expanded', 'true');
33
- expect(anchor).toHaveAttribute('aria-controls');
34
- expect(getByRole('button', { name: 'Edit' })).toBeInTheDocument();
35
- expect(getByRole('toolbar', { name: 'Actions' })).toBeInTheDocument();
36
- });
37
-
38
- test('hover trigger opens panel on keyboard focus', async () => {
39
- const { getByRole, queryByText } = render({
40
- components: { UiFloatActions, UiFloatActionItems },
41
- template: `
42
- <UiFloatActions trigger="hover" aria-label="Text actions">
43
- <template #container>
44
- <span>Hover me</span>
45
- </template>
46
- <template #action>
47
- <UiFloatActionItems aria-label="Actions">
48
- <UiFloatActionItems type="button" aria-label="Copy">Copy</UiFloatActionItems>
49
- </UiFloatActionItems>
50
- </template>
51
- </UiFloatActions>
52
- `,
53
- });
54
-
55
- const anchor = getByRole('button', { name: 'Text actions' });
56
- expect(anchor).toHaveAttribute('aria-haspopup', 'true');
57
-
58
- anchor.focus();
59
- await nextTick();
60
-
61
- expect(anchor).toHaveAttribute('aria-expanded', 'true');
62
- expect(queryByText('Copy')).toBeInTheDocument();
63
- });
64
-
65
- test('focus trigger keeps focus on the anchor', async () => {
66
- const { getByRole } = render({
67
- components: { UiFloatActions, UiFloatActionItems },
68
- template: `
69
- <UiFloatActions trigger="focus" aria-label="Paragraph actions">
70
- <template #container>
71
- <span>Target paragraph</span>
72
- </template>
73
- <template #action>
74
- <UiFloatActionItems aria-label="Actions">
75
- <UiFloatActionItems type="button" aria-label="Edit">Edit</UiFloatActionItems>
76
- <UiFloatActionItems type="button" aria-label="Copy">Copy</UiFloatActionItems>
77
- </UiFloatActionItems>
78
- </template>
79
- </UiFloatActions>
80
- `,
81
- });
82
-
83
- const anchor = getByRole('button', { name: 'Paragraph actions' });
84
- anchor.focus();
85
- await nextTick();
86
-
87
- expect(document.activeElement).toBe(anchor);
88
- });
89
-
90
- test('closes on Escape and restores expanded state', async () => {
91
- const { getByRole, queryByRole } = render({
92
- components: { UiFloatActions, UiFloatActionItems },
93
- template: `
94
- <UiFloatActions trigger="focus" aria-label="Paragraph actions">
95
- <template #container>
96
- <span>Target paragraph</span>
97
- </template>
98
- <template #action>
99
- <UiFloatActionItems aria-label="Actions">
100
- <UiFloatActionItems type="button" aria-label="Copy">Copy</UiFloatActionItems>
101
- </UiFloatActionItems>
102
- </template>
103
- </UiFloatActions>
104
- `,
105
- });
106
-
107
- const anchor = getByRole('button', { name: 'Paragraph actions' });
108
- anchor.focus();
109
- await nextTick();
110
-
111
- document.dispatchEvent(
112
- new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }),
113
- );
114
- await nextTick();
115
-
116
- expect(anchor).toHaveAttribute('aria-expanded', 'false');
117
- expect(queryByRole('button', { name: 'Copy' })).not.toBeInTheDocument();
118
- });
119
-
120
- test('click trigger toggles with Enter and Space', async () => {
121
- const { getByRole, queryByRole } = render({
122
- components: { UiFloatActions, UiFloatActionItems },
123
- template: `
124
- <UiFloatActions trigger="click" aria-label="Open actions">
125
- <template #container>
126
- <span>Target</span>
127
- </template>
128
- <template #action>
129
- <UiFloatActionItems aria-label="Actions">
130
- <UiFloatActionItems type="button" aria-label="Edit">Edit</UiFloatActionItems>
131
- </UiFloatActionItems>
132
- </template>
133
- </UiFloatActions>
134
- `,
135
- });
136
-
137
- const anchor = getByRole('button', { name: 'Open actions' });
138
-
139
- anchor.focus();
140
- anchor.dispatchEvent(
141
- new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }),
142
- );
143
- await nextTick();
144
- expect(queryByRole('button', { name: 'Edit' })).toBeInTheDocument();
145
-
146
- anchor.dispatchEvent(
147
- new KeyboardEvent('keydown', { key: ' ', bubbles: true }),
148
- );
149
- await nextTick();
150
- expect(queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
151
- });
152
- });