@sit-onyx/headless 1.0.0-beta.13 → 1.0.0-beta.15
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/headless",
|
|
3
3
|
"description": "Headless composables for Vue",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Schwarz IT KG",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -28,11 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@vue/compiler-dom": "3.5.13",
|
|
31
|
-
"vue": "3.5.13"
|
|
31
|
+
"vue": "3.5.13",
|
|
32
|
+
"@sit-onyx/shared": "^0.0.1-beta.0"
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "vue-tsc --build --force",
|
|
35
36
|
"test": "vitest",
|
|
36
|
-
"test:
|
|
37
|
+
"test:playwright": "playwright install && playwright test"
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -109,13 +109,13 @@ export const createListbox = createBuilder(
|
|
|
109
109
|
!isExpanded.value ||
|
|
110
110
|
options.activeOption.value == undefined ||
|
|
111
111
|
(!isFocused.value && !options.controlled)
|
|
112
|
-
)
|
|
112
|
+
) {
|
|
113
113
|
return;
|
|
114
|
-
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
116
|
+
const id = getOptionId(options.activeOption.value);
|
|
117
|
+
await nextTick();
|
|
118
|
+
document.getElementById(id)?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
const typeAhead = useTypeAhead((inputString) => options.onTypeAhead?.(inputString));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { ref } from "vue";
|
|
2
|
+
import { ref, type Ref } from "vue";
|
|
3
3
|
import { createMenuButton } from "./createMenuButton";
|
|
4
4
|
|
|
5
5
|
const items = Array.from({ length: 10 }, (_, index) => {
|
|
@@ -10,10 +10,11 @@ const items = Array.from({ length: 10 }, (_, index) => {
|
|
|
10
10
|
const activeItem = ref<string>();
|
|
11
11
|
const isExpanded = ref(false);
|
|
12
12
|
const onToggle = () => (isExpanded.value = !isExpanded.value);
|
|
13
|
+
const trigger: Readonly<Ref<"click" | "hover">> = ref("hover");
|
|
13
14
|
|
|
14
15
|
const {
|
|
15
16
|
elements: { root, button, menu, menuItem, listItem },
|
|
16
|
-
} = createMenuButton({ isExpanded, onToggle });
|
|
17
|
+
} = createMenuButton({ isExpanded, onToggle, trigger });
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
20
|
<template>
|
|
@@ -5,6 +5,7 @@ import { useGlobalEventListener } from "../helpers/useGlobalListener";
|
|
|
5
5
|
|
|
6
6
|
type CreateMenuButtonOptions = {
|
|
7
7
|
isExpanded: Readonly<Ref<boolean>>;
|
|
8
|
+
trigger: Readonly<Ref<"hover" | "click">>;
|
|
8
9
|
onToggle: () => void;
|
|
9
10
|
};
|
|
10
11
|
|
|
@@ -105,13 +106,25 @@ export const createMenuButton = createBuilder((options: CreateMenuButtonOptions)
|
|
|
105
106
|
}
|
|
106
107
|
};
|
|
107
108
|
|
|
109
|
+
const triggerEvents = () => {
|
|
110
|
+
if (options.trigger.value === "click") {
|
|
111
|
+
return {
|
|
112
|
+
onClick: () => setExpanded(true),
|
|
113
|
+
};
|
|
114
|
+
} else {
|
|
115
|
+
return {
|
|
116
|
+
onMouseenter: () => setExpanded(true),
|
|
117
|
+
onMouseleave: () => setExpanded(false, true),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
108
122
|
return {
|
|
109
123
|
elements: {
|
|
110
124
|
root: {
|
|
111
125
|
id: rootId,
|
|
112
126
|
onKeydown: handleKeydown,
|
|
113
|
-
|
|
114
|
-
onMouseleave: () => setExpanded(false, true),
|
|
127
|
+
...triggerEvents(),
|
|
115
128
|
onFocusout: (event) => {
|
|
116
129
|
// if focus receiving element is not part of the menu button, then close
|
|
117
130
|
if (
|