@aleph-alpha/ui-library 5.1.0 → 5.3.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 (29) hide show
  1. package/README.md +2 -0
  2. package/dist/system/components/core/sidebar/SidebarInset.vue.d.ts +14 -1
  3. package/dist/system/index.d.ts +1 -0
  4. package/dist/system/lib/useAnchorFloat.d.ts +143 -0
  5. package/dist/system/lib.js +19421 -18919
  6. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +35 -0
  7. package/dist/system/patterns/UiFloatActions/UiFloatActions.vue.d.ts +43 -0
  8. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +16 -0
  9. package/dist/system/patterns/UiFloatActions/index.d.ts +3 -0
  10. package/dist/system/patterns/UiFloatActions/types.d.ts +127 -0
  11. package/dist/system/patterns/index.d.ts +1 -0
  12. package/package.json +12 -3
  13. package/src/components/UiButton/UiButton.stories.ts +526 -38
  14. package/src/components/core/sidebar/SidebarInset.vue +19 -2
  15. package/src/index.ts +1 -0
  16. package/src/lib/useAnchorFloat.test.ts +166 -0
  17. package/src/lib/useAnchorFloat.ts +437 -0
  18. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +321 -0
  19. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +767 -0
  20. package/src/patterns/UiFloatActions/UiFloatActions.vue +220 -0
  21. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +104 -0
  22. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +152 -0
  23. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +86 -0
  24. package/src/patterns/UiFloatActions/floatActionItemContext.ts +20 -0
  25. package/src/patterns/UiFloatActions/index.ts +3 -0
  26. package/src/patterns/UiFloatActions/types.ts +155 -0
  27. package/src/patterns/UiSidebar/UiSidebarInset.stories.ts +259 -0
  28. package/src/patterns/UiSidebar/__tests__/UiSidebarInset.test.ts +20 -0
  29. package/src/patterns/index.ts +1 -0
@@ -0,0 +1,220 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * UiFloatActions anchors floating action content to a trigger element.
4
+ *
5
+ * Use for contextual toolbars, quick actions, and inline controls that appear
6
+ * on hover, focus, or click. Pair with {@link UiFloatActionItems} for pill-shaped
7
+ * action bars. For rich panels or forms, prefer {@link UiPopover}.
8
+ *
9
+ * @component UiFloatActions
10
+ * @property {'hover' | 'focus' | 'click' | 'manual'} [trigger='hover'] -
11
+ * How the panel opens. `hover` opens on pointer hover and keyboard focus;
12
+ * `focus` opens on keyboard focus; `click` toggles on pointer or Enter/Space.
13
+ * @property {Placement} [placement='top'] -
14
+ * Preferred placement relative to the anchor. Auto-flips when space is limited.
15
+ * @property {number | AnchorFloatOffset} [offset=8] -
16
+ * Gap between the anchor and the floating panel, in pixels.
17
+ * @property {boolean} [open] -
18
+ * Controlled open state. Use `v-model:open` or omit for uncontrolled mode.
19
+ * @property {string} [ariaLabel] -
20
+ * Accessible name for the anchor when it has no visible text. Required for
21
+ * `click` and `focus` triggers without readable anchor content.
22
+ * @slot container
23
+ * The anchor element the floating panel is bound to.
24
+ * @slot action
25
+ * Floating content rendered in a teleported panel (typically a {@link UiFloatActionItems} toolbar).
26
+ * @example Hover toolbar
27
+ * ```vue
28
+ * <UiFloatActions trigger="hover" placement="top" aria-label="Paragraph actions">
29
+ * <template #container>
30
+ * <p>Select this paragraph…</p>
31
+ * </template>
32
+ * <template #action>
33
+ * <UiFloatActionItems aria-label="Actions">
34
+ * <UiFloatActionItems type="button" aria-label="Edit">
35
+ * <UiIcon name="edit" size="s" />
36
+ * </UiFloatActionItems>
37
+ * </UiFloatActionItems>
38
+ * </template>
39
+ * </UiFloatActions>
40
+ * ```
41
+ * @example Focus-only trigger
42
+ * ```vue
43
+ * <UiFloatActions trigger="focus" aria-label="Paragraph actions">
44
+ * <template #container>
45
+ * <p>Tab to reveal actions…</p>
46
+ * </template>
47
+ * <template #action>
48
+ * <UiFloatActionItems aria-label="Actions">…</UiFloatActionItems>
49
+ * </template>
50
+ * </UiFloatActions>
51
+ * ```
52
+ */
53
+ import { useAnchorFloat } from '@/lib/useAnchorFloat';
54
+ import { cn, omitClass } from '@/lib/utils';
55
+ import { computed, useAttrs, useId } from 'vue';
56
+ import type { UiFloatActionsProps } from './types';
57
+
58
+ defineOptions({
59
+ name: 'UiFloatActions',
60
+ inheritAttrs: false,
61
+ });
62
+
63
+ const props = withDefaults(defineProps<UiFloatActionsProps>(), {
64
+ trigger: 'hover',
65
+ placement: 'top',
66
+ offset: 8,
67
+ openDelay: 150,
68
+ closeDelay: 150,
69
+ dismissOnOutsideClick: true,
70
+ dismissOnEscape: true,
71
+ ariaLabel: undefined,
72
+ });
73
+
74
+ const open = defineModel<boolean>('open', { default: false });
75
+
76
+ const attrs = useAttrs();
77
+ const contentId = useId();
78
+
79
+ const {
80
+ referenceRef,
81
+ floatingRef,
82
+ side,
83
+ floatingStyles,
84
+ isPositioned,
85
+ onReferenceMouseEnter,
86
+ onReferenceMouseLeave,
87
+ onReferenceFocus,
88
+ onReferenceBlur,
89
+ onFloatingMouseEnter,
90
+ onFloatingMouseLeave,
91
+ onFloatingFocusIn,
92
+ onFloatingFocusOut,
93
+ onReferenceClick,
94
+ onReferenceKeydown,
95
+ } = useAnchorFloat({
96
+ trigger: () => props.trigger,
97
+ placement: () => props.placement,
98
+ offset: () => props.offset,
99
+ open,
100
+ openDelay: () => props.openDelay,
101
+ closeDelay: () => props.closeDelay,
102
+ dismissOnOutsideClick: () => props.dismissOnOutsideClick,
103
+ dismissOnEscape: () => props.dismissOnEscape,
104
+ });
105
+
106
+ /**
107
+ * Feature-detect the Popover API. When available the panel opts into the native
108
+ * top layer + focus-order handling; otherwise it renders as a plain teleported
109
+ * element (jsdom, legacy browsers).
110
+ */
111
+ const supportsPopover =
112
+ typeof HTMLElement !== 'undefined' &&
113
+ typeof HTMLElement.prototype.showPopover === 'function';
114
+
115
+ const isClickTrigger = computed(() => props.trigger === 'click');
116
+
117
+ /** Hover, click, and focus anchors render as a native `button` for focus ring parity. */
118
+ const usesButtonAnchor = computed(() =>
119
+ ['hover', 'click', 'focus'].includes(props.trigger),
120
+ );
121
+
122
+ const hasPopupA11y = computed(() => usesButtonAnchor.value);
123
+
124
+ /**
125
+ * Ghost button reset so the anchor inherits slot layout while matching core
126
+ * button keyboard focus: accent fill and blue focus ring.
127
+ */
128
+ const anchorClass = computed(() =>
129
+ cn(
130
+ usesButtonAnchor.value &&
131
+ 'inline-flex max-w-full cursor-default rounded-md border border-transparent bg-transparent p-0 text-left font-inherit text-inherit outline-none transition-[color,box-shadow,background-color,border-color] focus-visible:border-border-surface-focus-ring focus-visible:bg-background-accent-sofxt focus-visible:ring-ring/50 focus-visible:ring-[3px] focus-visible:[&>*]:border-border-surface-focus-ring',
132
+ isClickTrigger.value && 'cursor-pointer',
133
+ attrs.class ?? '',
134
+ ),
135
+ );
136
+
137
+ /**
138
+ * The floating element stays mounted while open so floating-ui can measure it,
139
+ * starting at `opacity-0` until positioned. We animate ONLY `opacity` (a plain
140
+ * CSS transition) — never `transform` — so the fade can't interfere with
141
+ * floating-ui's positioning and the panel fades in at rest instead of flying in
142
+ * from the viewport's top-left corner.
143
+ *
144
+ * `inset-auto m-0 border-0 bg-transparent p-0 overflow-visible` neutralize the
145
+ * User-Agent `[popover]` styles (centering inset, auto margins, and default
146
+ * chrome) so floating-ui's fixed `top`/`left` positioning stays authoritative.
147
+ */
148
+ const floatingAnimationClass = computed(() =>
149
+ cn(
150
+ 'z-50 m-0 inset-auto border-0 bg-transparent p-0 overflow-visible outline-none transition-opacity duration-200 ease-out motion-reduce:transition-none',
151
+ isPositioned.value ? 'opacity-100' : 'opacity-0',
152
+ ),
153
+ );
154
+ </script>
155
+
156
+ <template>
157
+ <span class="inline-flex">
158
+ <button
159
+ v-if="usesButtonAnchor"
160
+ ref="referenceRef"
161
+ type="button"
162
+ data-slot="float-anchor"
163
+ :aria-label="props.ariaLabel"
164
+ :aria-expanded="hasPopupA11y ? open : undefined"
165
+ :aria-haspopup="hasPopupA11y ? 'true' : undefined"
166
+ :aria-controls="hasPopupA11y && open ? contentId : undefined"
167
+ :class="anchorClass"
168
+ v-bind="omitClass(attrs)"
169
+ @mouseenter="onReferenceMouseEnter"
170
+ @mouseleave="onReferenceMouseLeave"
171
+ @focus="onReferenceFocus"
172
+ @blur="onReferenceBlur"
173
+ @click="onReferenceClick"
174
+ @keydown="onReferenceKeydown"
175
+ >
176
+ <slot name="container" />
177
+ </button>
178
+
179
+ <!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
180
+ <span
181
+ v-else
182
+ ref="referenceRef"
183
+ data-slot="float-anchor"
184
+ v-bind="attrs"
185
+ :class="attrs.class ?? ''"
186
+ @mouseenter="onReferenceMouseEnter"
187
+ @mouseleave="onReferenceMouseLeave"
188
+ @focus="onReferenceFocus"
189
+ @blur="onReferenceBlur"
190
+ @click="onReferenceClick"
191
+ @keydown="onReferenceKeydown"
192
+ >
193
+ <slot name="container" />
194
+ </span>
195
+
196
+ <Teleport to="body">
197
+ <!-- Pointer/focus handlers keep the panel open while the user interacts
198
+ with it (hover bridge + focus retention). The panel is a positioned
199
+ container, not a control, so it carries no interactive role. -->
200
+ <!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
201
+ <div
202
+ v-if="open"
203
+ :id="contentId"
204
+ ref="floatingRef"
205
+ :popover="supportsPopover ? 'manual' : undefined"
206
+ data-slot="float-content"
207
+ :data-side="side"
208
+ :data-positioned="isPositioned"
209
+ :style="floatingStyles"
210
+ :class="floatingAnimationClass"
211
+ @mouseenter="onFloatingMouseEnter"
212
+ @mouseleave="onFloatingMouseLeave"
213
+ @focusin="onFloatingFocusIn"
214
+ @focusout="onFloatingFocusOut"
215
+ >
216
+ <slot name="action" />
217
+ </div>
218
+ </Teleport>
219
+ </span>
220
+ </template>
@@ -0,0 +1,104 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { describe, expect, test, vi } from 'vitest';
3
+ import { UiFloatActionItems } from '../index';
4
+
5
+ describe('UiFloatActionItems', () => {
6
+ test('renders toolbar with accessible label', () => {
7
+ const { getByRole } = render({
8
+ components: { UiFloatActionItems },
9
+ template: `
10
+ <UiFloatActionItems aria-label="Text actions">
11
+ <UiFloatActionItems type="button" aria-label="Edit">Edit</UiFloatActionItems>
12
+ </UiFloatActionItems>
13
+ `,
14
+ });
15
+
16
+ expect(getByRole('toolbar', { name: 'Text actions' })).toBeInTheDocument();
17
+ expect(getByRole('button', { name: 'Edit' })).toBeInTheDocument();
18
+ });
19
+
20
+ test('supports text and group items', () => {
21
+ const { getByText, getByRole } = render({
22
+ components: { UiFloatActionItems },
23
+ template: `
24
+ <UiFloatActionItems aria-label="Pagination">
25
+ <UiFloatActionItems type="group">
26
+ <UiFloatActionItems type="button" aria-label="Previous">&lt;</UiFloatActionItems>
27
+ <UiFloatActionItems type="text">2/2</UiFloatActionItems>
28
+ <UiFloatActionItems type="button" aria-label="Next">&gt;</UiFloatActionItems>
29
+ </UiFloatActionItems>
30
+ </UiFloatActionItems>
31
+ `,
32
+ });
33
+
34
+ expect(getByRole('group')).toBeInTheDocument();
35
+ expect(getByText('2/2')).toBeInTheDocument();
36
+ expect(getByRole('button', { name: 'Previous' })).toBeInTheDocument();
37
+ expect(getByRole('button', { name: 'Next' })).toBeInTheDocument();
38
+ });
39
+
40
+ test('emits click from button items', async () => {
41
+ const onClick = vi.fn();
42
+ const { getByRole } = render({
43
+ components: { UiFloatActionItems },
44
+ setup() {
45
+ return { onClick };
46
+ },
47
+ template: `
48
+ <UiFloatActionItems aria-label="Actions">
49
+ <UiFloatActionItems type="button" aria-label="Copy" @click="onClick">
50
+ Copy
51
+ </UiFloatActionItems>
52
+ </UiFloatActionItems>
53
+ `,
54
+ });
55
+
56
+ await getByRole('button', { name: 'Copy' }).click();
57
+ expect(onClick).toHaveBeenCalledTimes(1);
58
+ });
59
+
60
+ test('renders input item with accessible label', () => {
61
+ const { getByRole } = render({
62
+ components: { UiFloatActionItems },
63
+ template: `
64
+ <UiFloatActionItems aria-label="Search actions">
65
+ <UiFloatActionItems
66
+ type="input"
67
+ aria-label="Search"
68
+ placeholder="Filter..."
69
+ />
70
+ </UiFloatActionItems>
71
+ `,
72
+ });
73
+
74
+ expect(getByRole('textbox', { name: 'Search' })).toHaveAttribute(
75
+ 'placeholder',
76
+ 'Filter...',
77
+ );
78
+ });
79
+
80
+ test('moves focus with arrow keys inside toolbar', async () => {
81
+ const { getByRole } = render({
82
+ components: { UiFloatActionItems },
83
+ template: `
84
+ <UiFloatActionItems aria-label="Actions">
85
+ <UiFloatActionItems type="button" aria-label="Edit">Edit</UiFloatActionItems>
86
+ <UiFloatActionItems type="button" aria-label="Copy">Copy</UiFloatActionItems>
87
+ </UiFloatActionItems>
88
+ `,
89
+ });
90
+
91
+ const toolbar = getByRole('toolbar', { name: 'Actions' });
92
+ const editButton = getByRole('button', { name: 'Edit' });
93
+ const copyButton = getByRole('button', { name: 'Copy' });
94
+
95
+ editButton.focus();
96
+ expect(document.activeElement).toBe(editButton);
97
+
98
+ toolbar.dispatchEvent(
99
+ new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }),
100
+ );
101
+
102
+ expect(document.activeElement).toBe(copyButton);
103
+ });
104
+ });
@@ -0,0 +1,152 @@
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
+ });
@@ -0,0 +1,86 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { describe, expect, test, vi } from 'vitest';
3
+ import { nextTick } from 'vue';
4
+ import { UiFloatActions, UiFloatActionItems } from '../index';
5
+
6
+ describe('UiFloatActions', () => {
7
+ test('shows action content on click trigger', async () => {
8
+ const { getByRole, queryByRole } = render({
9
+ components: { UiFloatActions, UiFloatActionItems },
10
+ template: `
11
+ <UiFloatActions trigger="click" aria-label="Open actions">
12
+ <template #container>
13
+ <span>Select text</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
+ expect(queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
25
+
26
+ await getByRole('button', { name: 'Open actions' }).click();
27
+ await nextTick();
28
+ expect(getByRole('button', { name: 'Edit' })).toBeInTheDocument();
29
+ });
30
+
31
+ test('sets aria-expanded on click trigger anchor', async () => {
32
+ const { getByRole } = render({
33
+ components: { UiFloatActions, UiFloatActionItems },
34
+ template: `
35
+ <UiFloatActions trigger="click" aria-label="Open actions">
36
+ <template #container>
37
+ <span>Target</span>
38
+ </template>
39
+ <template #action>
40
+ <UiFloatActionItems aria-label="Actions">
41
+ <UiFloatActionItems type="button" aria-label="Copy">Copy</UiFloatActionItems>
42
+ </UiFloatActionItems>
43
+ </template>
44
+ </UiFloatActions>
45
+ `,
46
+ });
47
+
48
+ const anchor = getByRole('button', { name: 'Open actions' });
49
+ expect(anchor).toHaveAttribute('aria-expanded', 'false');
50
+
51
+ await anchor.click();
52
+ await nextTick();
53
+ expect(anchor).toHaveAttribute('aria-expanded', 'true');
54
+ });
55
+
56
+ test('emits click from float item buttons', async () => {
57
+ const onClick = vi.fn();
58
+ const { getByRole, getByText } = render({
59
+ components: { UiFloatActions, UiFloatActionItems },
60
+ setup() {
61
+ return { onClick };
62
+ },
63
+ template: `
64
+ <UiFloatActions trigger="click" aria-label="Open actions">
65
+ <template #container>
66
+ <span>Target</span>
67
+ </template>
68
+ <template #action>
69
+ <UiFloatActionItems aria-label="Actions">
70
+ <UiFloatActionItems type="button" aria-label="Edit" @click="onClick">
71
+ Edit
72
+ </UiFloatActionItems>
73
+ </UiFloatActionItems>
74
+ </template>
75
+ </UiFloatActions>
76
+ `,
77
+ });
78
+
79
+ await getByRole('button', { name: 'Open actions' }).click();
80
+ await nextTick();
81
+ await getByRole('button', { name: 'Edit' }).click();
82
+
83
+ expect(onClick).toHaveBeenCalledTimes(1);
84
+ expect(getByText('Target')).toBeInTheDocument();
85
+ });
86
+ });
@@ -0,0 +1,20 @@
1
+ import type { InjectionKey, Ref } from 'vue';
2
+
3
+ /** Shared toolbar state used to coordinate roving-tabindex focus across items. */
4
+ export interface FloatActionItemContext {
5
+ /** Registers a focusable item so the toolbar can manage roving tabindex. */
6
+ registerItem: (id: symbol) => void;
7
+ /** Removes an item from roving-tabindex tracking. */
8
+ unregisterItem: (id: symbol) => void;
9
+ /** Marks an item as the active (tabbable) one when it receives focus. */
10
+ onItemFocus: (id: symbol) => void;
11
+ /** Resolves the roving tabindex (0 for active item, -1 otherwise). */
12
+ getTabIndex: (id: symbol) => number;
13
+ /** Keyboard navigation direction for the toolbar. */
14
+ orientation: Ref<'horizontal' | 'vertical'>;
15
+ }
16
+
17
+ export const FLOAT_ACTION_ITEM_CONTEXT: InjectionKey<FloatActionItemContext> =
18
+ Symbol('UiFloatActionItemsContext');
19
+
20
+ export const FLOAT_ACTION_ITEM_SELECTOR = '[data-slot="float-item-action"]';
@@ -0,0 +1,3 @@
1
+ export { default as UiFloatActions } from './UiFloatActions.vue';
2
+ export { default as UiFloatActionItems } from './UiFloatActionItems.vue';
3
+ export * from './types';