@sit-onyx/headless 1.0.0-alpha.10 → 1.0.0-alpha.11

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-alpha.10",
4
+ "version": "1.0.0-alpha.11",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@ const expectToClose = async (
36
36
  * Test an implementation of the combobox based on https://w3c.github.io/aria/#combobox
37
37
  */
38
38
  export const comboboxTesting = async (
39
- page: Page,
39
+ _page: Page,
40
40
  listbox: Locator,
41
41
  combobox: Locator,
42
42
  button: Locator,
@@ -1,4 +1,4 @@
1
- import { computed, ref, unref, type MaybeRef, type Ref } from "vue";
1
+ import { computed, unref, type MaybeRef, type Ref } from "vue";
2
2
  import { createBuilder } from "../../utils/builder";
3
3
  import { createId } from "../../utils/id";
4
4
  import { isPrintableCharacter, wasKeyPressed, type PressedKey } from "../../utils/keyboard";
@@ -12,8 +12,13 @@ import { useTypeAhead } from "../typeAhead";
12
12
 
13
13
  export type ComboboxAutoComplete = "none" | "list" | "both";
14
14
 
15
- const OPENING_KEYS: PressedKey[] = ["ArrowDown", "ArrowUp", " ", "Enter", "Home", "End"];
16
- const CLOSING_KEYS: PressedKey[] = ["Escape", { key: "ArrowUp", altKey: true }, "Enter", "Tab"];
15
+ export const OPENING_KEYS: PressedKey[] = ["ArrowDown", "ArrowUp", " ", "Enter", "Home", "End"];
16
+ export const CLOSING_KEYS: PressedKey[] = [
17
+ "Escape",
18
+ { key: "ArrowUp", altKey: true },
19
+ "Enter",
20
+ "Tab",
21
+ ];
17
22
  const SELECTING_KEYS_SINGLE: PressedKey[] = ["Enter", " "];
18
23
  const SELECTING_KEYS_MULTIPLE: PressedKey[] = ["Enter"];
19
24
 
@@ -117,7 +122,6 @@ export const createComboBox = createBuilder(
117
122
  onActivatePrevious,
118
123
  templateRef,
119
124
  }: CreateComboboxOptions<TValue, TAutoComplete, TMultiple>) => {
120
- const inputValid = ref(true);
121
125
  const controlsId = createId("comboBox-control");
122
126
 
123
127
  const autocomplete = computed(() => unref(autocompleteRef));
@@ -126,10 +130,6 @@ export const createComboBox = createBuilder(
126
130
 
127
131
  const handleInput = (event: Event) => {
128
132
  const inputElement = event.target as HTMLInputElement;
129
- inputValid.value = inputElement.validity.valid;
130
- if (!unref(isExpanded)) {
131
- onToggle?.();
132
- }
133
133
 
134
134
  if (autocomplete.value !== "none") {
135
135
  onAutocomplete?.(inputElement.value);
@@ -193,6 +193,10 @@ export const createComboBox = createBuilder(
193
193
  !isExpanded.value && onToggle?.();
194
194
  return typeAhead(event);
195
195
  }
196
+ if (autocomplete.value !== "none" && isPrintableCharacter(event.key)) {
197
+ !isExpanded.value && onToggle?.();
198
+ return;
199
+ }
196
200
  return handleNavigation(event);
197
201
  };
198
202
 
@@ -185,15 +185,24 @@ export const createListbox = createBuilder(
185
185
  });
186
186
  }),
187
187
  option: computed(() => {
188
- return (data: { label: string; value: TValue; disabled?: boolean; selected?: boolean }) =>
189
- ({
188
+ return (data: {
189
+ label: string;
190
+ value: TValue;
191
+ disabled?: boolean;
192
+ selected?: boolean;
193
+ }) => {
194
+ const selected = data.selected ?? false;
195
+
196
+ return {
190
197
  id: getOptionId(data.value),
191
198
  role: "option",
192
199
  "aria-label": data.label,
193
200
  "aria-disabled": data.disabled,
194
- [isMultiselect.value ? "aria-checked" : "aria-selected"]: data.selected || false,
201
+ "aria-checked": isMultiselect.value ? selected : undefined,
202
+ "aria-selected": !isMultiselect.value ? selected : undefined,
195
203
  onClick: () => !data.disabled && options.onSelect?.(data.value),
196
- }) as const;
204
+ } as const;
205
+ };
197
206
  }),
198
207
  },
199
208
  state: {