@aleph-alpha/ui-library 5.2.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.
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/useAnchorFloat.d.ts +143 -0
- package/dist/system/lib.js +19412 -18916
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +35 -0
- package/dist/system/patterns/UiFloatActions/UiFloatActions.vue.d.ts +43 -0
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +16 -0
- package/dist/system/patterns/UiFloatActions/index.d.ts +3 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +127 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/lib/useAnchorFloat.test.ts +166 -0
- package/src/lib/useAnchorFloat.ts +437 -0
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +321 -0
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +767 -0
- package/src/patterns/UiFloatActions/UiFloatActions.vue +220 -0
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +104 -0
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +152 -0
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +86 -0
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +20 -0
- package/src/patterns/UiFloatActions/index.ts +3 -0
- package/src/patterns/UiFloatActions/types.ts +155 -0
- package/src/patterns/index.ts +1 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UiFloatActionItemsProps } from './types';
|
|
2
|
+
declare function __VLS_template(): {
|
|
3
|
+
attrs: Partial<{}>;
|
|
4
|
+
slots: {
|
|
5
|
+
default?(_: {}): any;
|
|
6
|
+
default?(_: {}): any;
|
|
7
|
+
default?(_: {}): any;
|
|
8
|
+
default?(_: {}): any;
|
|
9
|
+
};
|
|
10
|
+
refs: {
|
|
11
|
+
itemRef: HTMLInputElement;
|
|
12
|
+
};
|
|
13
|
+
rootEl: any;
|
|
14
|
+
};
|
|
15
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
16
|
+
declare const __VLS_component: import('vue').DefineComponent<UiFloatActionItemsProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
17
|
+
click: (event: MouseEvent) => any;
|
|
18
|
+
}, string, import('vue').PublicProps, Readonly<UiFloatActionItemsProps> & Readonly<{
|
|
19
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
20
|
+
}>, {
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
orientation: import('./types').UiFloatActionItemsOrientation;
|
|
23
|
+
type: import('./types').UiFloatActionItemsType;
|
|
24
|
+
placeholder: string;
|
|
25
|
+
ariaLabel: string;
|
|
26
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
|
|
27
|
+
itemRef: HTMLInputElement;
|
|
28
|
+
}, any>;
|
|
29
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
30
|
+
export default _default;
|
|
31
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
32
|
+
new (): {
|
|
33
|
+
$slots: S;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { UiFloatActionsProps } from './types';
|
|
2
|
+
type __VLS_Props = UiFloatActionsProps;
|
|
3
|
+
type __VLS_PublicProps = {
|
|
4
|
+
'open'?: boolean;
|
|
5
|
+
} & __VLS_Props;
|
|
6
|
+
declare function __VLS_template(): {
|
|
7
|
+
attrs: Partial<{}>;
|
|
8
|
+
slots: {
|
|
9
|
+
container?(_: {}): any;
|
|
10
|
+
container?(_: {}): any;
|
|
11
|
+
action?(_: {}): any;
|
|
12
|
+
};
|
|
13
|
+
refs: {
|
|
14
|
+
referenceRef: HTMLSpanElement;
|
|
15
|
+
floatingRef: HTMLDivElement;
|
|
16
|
+
};
|
|
17
|
+
rootEl: any;
|
|
18
|
+
};
|
|
19
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
20
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
21
|
+
"update:open": (value: boolean) => any;
|
|
22
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
23
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
24
|
+
}>, {
|
|
25
|
+
ariaLabel: string;
|
|
26
|
+
offset: import('./types').UiFloatActionsOffset;
|
|
27
|
+
placement: import('./types').UiFloatActionsPlacement;
|
|
28
|
+
trigger: import('./types').UiFloatActionsTrigger;
|
|
29
|
+
openDelay: number;
|
|
30
|
+
closeDelay: number;
|
|
31
|
+
dismissOnOutsideClick: boolean;
|
|
32
|
+
dismissOnEscape: boolean;
|
|
33
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
|
|
34
|
+
referenceRef: HTMLSpanElement;
|
|
35
|
+
floatingRef: HTMLDivElement;
|
|
36
|
+
}, any>;
|
|
37
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
38
|
+
export default _default;
|
|
39
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
40
|
+
new (): {
|
|
41
|
+
$slots: S;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InjectionKey, Ref } from 'vue';
|
|
2
|
+
/** Shared toolbar state used to coordinate roving-tabindex focus across items. */
|
|
3
|
+
export interface FloatActionItemContext {
|
|
4
|
+
/** Registers a focusable item so the toolbar can manage roving tabindex. */
|
|
5
|
+
registerItem: (id: symbol) => void;
|
|
6
|
+
/** Removes an item from roving-tabindex tracking. */
|
|
7
|
+
unregisterItem: (id: symbol) => void;
|
|
8
|
+
/** Marks an item as the active (tabbable) one when it receives focus. */
|
|
9
|
+
onItemFocus: (id: symbol) => void;
|
|
10
|
+
/** Resolves the roving tabindex (0 for active item, -1 otherwise). */
|
|
11
|
+
getTabIndex: (id: symbol) => number;
|
|
12
|
+
/** Keyboard navigation direction for the toolbar. */
|
|
13
|
+
orientation: Ref<'horizontal' | 'vertical'>;
|
|
14
|
+
}
|
|
15
|
+
export declare const FLOAT_ACTION_ITEM_CONTEXT: InjectionKey<FloatActionItemContext>;
|
|
16
|
+
export declare const FLOAT_ACTION_ITEM_SELECTOR = "[data-slot=\"float-item-action\"]";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Placement } from '@floating-ui/vue';
|
|
2
|
+
import { HTMLAttributes } from 'vue';
|
|
3
|
+
import { AnchorFloatOffset, AnchorFloatTrigger } from '../../lib/useAnchorFloat';
|
|
4
|
+
export type UiFloatActionsTrigger = AnchorFloatTrigger;
|
|
5
|
+
export type UiFloatActionsPlacement = Placement;
|
|
6
|
+
export type UiFloatActionsOffset = number | AnchorFloatOffset;
|
|
7
|
+
/**
|
|
8
|
+
* Anchors floating action content to a trigger element on hover, focus, or click.
|
|
9
|
+
* Use for contextual toolbars, quick actions, and inline controls.
|
|
10
|
+
* For rich panels or forms, prefer `UiPopover`.
|
|
11
|
+
*
|
|
12
|
+
* This component is currently experimental. Its API and behavior may still change
|
|
13
|
+
* before it is considered stable.
|
|
14
|
+
* @category Overlays
|
|
15
|
+
* @useCases contextual toolbar, inline actions, hover controls, keyboard toolbar
|
|
16
|
+
* @keywords float, anchor, floating, toolbar, hover, focus, contextual, experimental
|
|
17
|
+
* @related UiFloatActionItems, UiPopover, UiTooltip, useAnchorFloat
|
|
18
|
+
*/
|
|
19
|
+
export interface UiFloatActionsProps {
|
|
20
|
+
/**
|
|
21
|
+
* How the floating panel opens.
|
|
22
|
+
* - `hover` — pointer hover and keyboard focus on a focusable `button` anchor
|
|
23
|
+
* - `focus` — keyboard focus on the `button` anchor
|
|
24
|
+
* - `click` — click or Enter/Space on the `button` anchor
|
|
25
|
+
* - `manual` — controlled via `v-model:open`
|
|
26
|
+
* @default 'hover'
|
|
27
|
+
*/
|
|
28
|
+
trigger?: UiFloatActionsTrigger;
|
|
29
|
+
/**
|
|
30
|
+
* Preferred placement relative to the anchor element.
|
|
31
|
+
* Auto-flips when there is not enough room.
|
|
32
|
+
* @default 'top'
|
|
33
|
+
*/
|
|
34
|
+
placement?: UiFloatActionsPlacement;
|
|
35
|
+
/**
|
|
36
|
+
* Distance from the anchor element, in pixels.
|
|
37
|
+
* Pass an object to set main-axis and cross-axis offsets independently.
|
|
38
|
+
* @default 8
|
|
39
|
+
*/
|
|
40
|
+
offset?: UiFloatActionsOffset;
|
|
41
|
+
/**
|
|
42
|
+
* The controlled open state of the floating panel.
|
|
43
|
+
* - Omit for uncontrolled mode (component manages state internally)
|
|
44
|
+
* - Use `v-model:open` for controlled mode
|
|
45
|
+
* @example
|
|
46
|
+
* ```vue
|
|
47
|
+
* <UiFloatActions v-model:open="isOpen">…</UiFloatActions>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
open?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Delay in ms before opening on pointer hover.
|
|
53
|
+
* Keyboard focus opens immediately regardless of this value.
|
|
54
|
+
* @default 150
|
|
55
|
+
*/
|
|
56
|
+
openDelay?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Delay in ms before closing on pointer leave.
|
|
59
|
+
* @default 150
|
|
60
|
+
*/
|
|
61
|
+
closeDelay?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Close when clicking outside the anchor and floating panel.
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
dismissOnOutsideClick?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Close when Escape is pressed and restore focus to the anchor.
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
dismissOnEscape?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Accessible label for the anchor when it has no visible text.
|
|
74
|
+
* **Required** for triggers without readable anchor content when keyboard
|
|
75
|
+
* users need a concise name (e.g. icon-only or non-descriptive anchors).
|
|
76
|
+
*/
|
|
77
|
+
ariaLabel?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Item role within a {@link UiFloatActionItems} toolbar. */
|
|
80
|
+
export type UiFloatActionItemsType = 'toolbar' | 'button' | 'input' | 'text' | 'group' | 'separator';
|
|
81
|
+
/** Arrow-key navigation direction for toolbar roving focus. */
|
|
82
|
+
export type UiFloatActionItemsOrientation = 'horizontal' | 'vertical';
|
|
83
|
+
/**
|
|
84
|
+
* Pill-shaped floating toolbar and its action items.
|
|
85
|
+
*
|
|
86
|
+
* Use the root item (`type="toolbar"`) as the container and nest child items
|
|
87
|
+
* for buttons, inputs, text labels, groups, and separators. Implements the
|
|
88
|
+
* WAI-ARIA APG toolbar pattern with roving tabindex.
|
|
89
|
+
*
|
|
90
|
+
* @category Overlays
|
|
91
|
+
* @useCases contextual toolbar, inline actions, pagination controls, filter bar
|
|
92
|
+
* @keywords float, toolbar, pill, actions, keyboard, roving focus
|
|
93
|
+
* @related UiFloatActions, useAnchorFloat
|
|
94
|
+
*/
|
|
95
|
+
export interface UiFloatActionItemsProps {
|
|
96
|
+
/**
|
|
97
|
+
* Item role within the floating toolbar.
|
|
98
|
+
* Omit or use `toolbar` for the root pill container.
|
|
99
|
+
* @default 'toolbar'
|
|
100
|
+
*/
|
|
101
|
+
type?: UiFloatActionItemsType;
|
|
102
|
+
/**
|
|
103
|
+
* Disables interaction for `button` and `input` items.
|
|
104
|
+
* @default false
|
|
105
|
+
*/
|
|
106
|
+
disabled?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Accessible label for `toolbar`, `button`, and `input` items.
|
|
109
|
+
* **Required** for those types — icon-only buttons have no visible text.
|
|
110
|
+
*/
|
|
111
|
+
ariaLabel?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Keyboard navigation direction for toolbar items (ArrowLeft/Right or Up/Down).
|
|
114
|
+
* @default 'horizontal'
|
|
115
|
+
*/
|
|
116
|
+
orientation?: UiFloatActionItemsOrientation;
|
|
117
|
+
/**
|
|
118
|
+
* Placeholder text for `input` items.
|
|
119
|
+
*/
|
|
120
|
+
placeholder?: string;
|
|
121
|
+
}
|
|
122
|
+
/** Events emitted by {@link UiFloatActionItems} button items. */
|
|
123
|
+
export interface UiFloatActionItemsEmits {
|
|
124
|
+
/** Emitted when a `button` item is activated. */
|
|
125
|
+
click: [event: MouseEvent];
|
|
126
|
+
}
|
|
127
|
+
export type UiFloatActionItemsClass = HTMLAttributes['class'];
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './components';
|
|
|
8
8
|
export * from './patterns';
|
|
9
9
|
export * from './templates';
|
|
10
10
|
export * from './lib/useDevice';
|
|
11
|
+
export * from './lib/useAnchorFloat';
|
|
11
12
|
export * from './directives';
|
|
12
13
|
export { Primitive } from 'reka-ui';
|
|
13
14
|
export type PrimitiveProps = RekaPrimitiveProps;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
import { defineComponent, nextTick, ref } from 'vue';
|
|
4
|
+
import { useAnchorFloat } from './useAnchorFloat';
|
|
5
|
+
|
|
6
|
+
const TestComponent = defineComponent({
|
|
7
|
+
props: {
|
|
8
|
+
trigger: {
|
|
9
|
+
type: String as () => 'hover' | 'click' | 'focus' | 'manual',
|
|
10
|
+
default: 'click',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
setup(props) {
|
|
14
|
+
const open = ref(false);
|
|
15
|
+
const float = useAnchorFloat({
|
|
16
|
+
trigger: () => props.trigger,
|
|
17
|
+
open,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return { open, ...float };
|
|
21
|
+
},
|
|
22
|
+
template: `
|
|
23
|
+
<div>
|
|
24
|
+
<button
|
|
25
|
+
ref="referenceRef"
|
|
26
|
+
type="button"
|
|
27
|
+
@mouseenter="onReferenceMouseEnter"
|
|
28
|
+
@mouseleave="onReferenceMouseLeave"
|
|
29
|
+
@focus="onReferenceFocus"
|
|
30
|
+
@blur="onReferenceBlur"
|
|
31
|
+
@click="onReferenceClick"
|
|
32
|
+
>
|
|
33
|
+
Anchor
|
|
34
|
+
</button>
|
|
35
|
+
<div v-if="open" ref="floatingRef">Floating</div>
|
|
36
|
+
</div>
|
|
37
|
+
`,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
vi.restoreAllMocks();
|
|
42
|
+
vi.useRealTimers();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('useAnchorFloat', () => {
|
|
46
|
+
test('opens and closes on click trigger', async () => {
|
|
47
|
+
const { getByRole, queryByText } = render(TestComponent, {
|
|
48
|
+
props: { trigger: 'click' },
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(queryByText('Floating')).not.toBeInTheDocument();
|
|
52
|
+
|
|
53
|
+
await getByRole('button', { name: 'Anchor' }).click();
|
|
54
|
+
await nextTick();
|
|
55
|
+
expect(queryByText('Floating')).toBeInTheDocument();
|
|
56
|
+
|
|
57
|
+
await getByRole('button', { name: 'Anchor' }).click();
|
|
58
|
+
await nextTick();
|
|
59
|
+
expect(queryByText('Floating')).not.toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('opens on hover trigger after delay', async () => {
|
|
63
|
+
vi.useFakeTimers();
|
|
64
|
+
|
|
65
|
+
const { getByRole, queryByText } = render(TestComponent, {
|
|
66
|
+
props: { trigger: 'hover' },
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await getByRole('button', { name: 'Anchor' }).dispatchEvent(
|
|
70
|
+
new MouseEvent('mouseenter', { bubbles: true }),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(queryByText('Floating')).not.toBeInTheDocument();
|
|
74
|
+
|
|
75
|
+
vi.advanceTimersByTime(150);
|
|
76
|
+
await nextTick();
|
|
77
|
+
|
|
78
|
+
expect(queryByText('Floating')).toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('closes on Escape when open', async () => {
|
|
82
|
+
const { getByRole, queryByText } = render(TestComponent, {
|
|
83
|
+
props: { trigger: 'click' },
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await getByRole('button', { name: 'Anchor' }).click();
|
|
87
|
+
await nextTick();
|
|
88
|
+
expect(queryByText('Floating')).toBeInTheDocument();
|
|
89
|
+
|
|
90
|
+
document.dispatchEvent(
|
|
91
|
+
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }),
|
|
92
|
+
);
|
|
93
|
+
await nextTick();
|
|
94
|
+
|
|
95
|
+
expect(queryByText('Floating')).not.toBeInTheDocument();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('opens on focus trigger when anchor receives focus', async () => {
|
|
99
|
+
const { getByRole, queryByText } = render(TestComponent, {
|
|
100
|
+
props: { trigger: 'focus' },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(queryByText('Floating')).not.toBeInTheDocument();
|
|
104
|
+
|
|
105
|
+
getByRole('button', { name: 'Anchor' }).focus();
|
|
106
|
+
await nextTick();
|
|
107
|
+
|
|
108
|
+
expect(queryByText('Floating')).toBeInTheDocument();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('opens on focus for hover trigger', async () => {
|
|
112
|
+
const { getByRole, queryByText } = render(TestComponent, {
|
|
113
|
+
props: { trigger: 'hover' },
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
getByRole('button', { name: 'Anchor' }).focus();
|
|
117
|
+
await nextTick();
|
|
118
|
+
|
|
119
|
+
expect(queryByText('Floating')).toBeInTheDocument();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('closes on blur when focus leaves anchor and floating content', async () => {
|
|
123
|
+
const { getByRole, queryByText } = render(TestComponent, {
|
|
124
|
+
props: { trigger: 'focus' },
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const anchor = getByRole('button', { name: 'Anchor' });
|
|
128
|
+
anchor.focus();
|
|
129
|
+
await nextTick();
|
|
130
|
+
expect(queryByText('Floating')).toBeInTheDocument();
|
|
131
|
+
|
|
132
|
+
anchor.blur();
|
|
133
|
+
await nextTick();
|
|
134
|
+
|
|
135
|
+
expect(queryByText('Floating')).not.toBeInTheDocument();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('supports manual open state', async () => {
|
|
139
|
+
const ManualComponent = defineComponent({
|
|
140
|
+
setup() {
|
|
141
|
+
const open = ref(false);
|
|
142
|
+
const { show, hide, referenceRef, floatingRef } = useAnchorFloat({
|
|
143
|
+
trigger: 'manual',
|
|
144
|
+
open,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return { open, show, hide, referenceRef, floatingRef };
|
|
148
|
+
},
|
|
149
|
+
template: `
|
|
150
|
+
<div>
|
|
151
|
+
<button ref="referenceRef" type="button" @click="show">Show</button>
|
|
152
|
+
<button type="button" @click="hide">Hide</button>
|
|
153
|
+
<div v-if="open" ref="floatingRef">Manual floating</div>
|
|
154
|
+
</div>
|
|
155
|
+
`,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const { getByRole, queryByText } = render(ManualComponent);
|
|
159
|
+
|
|
160
|
+
await getByRole('button', { name: 'Show' }).click();
|
|
161
|
+
expect(queryByText('Manual floating')).toBeInTheDocument();
|
|
162
|
+
|
|
163
|
+
await getByRole('button', { name: 'Hide' }).click();
|
|
164
|
+
expect(queryByText('Manual floating')).not.toBeInTheDocument();
|
|
165
|
+
});
|
|
166
|
+
});
|