@sit-onyx/headless 0.5.0-dev-20260112070348 → 0.5.0-dev-20260112110323

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.
@@ -33,7 +33,7 @@ export declare const _unstableCreateCalendar: (options: CreateCalendarOptions) =
33
33
  table: {
34
34
  role: string;
35
35
  onKeydown: (event: KeyboardEvent) => Promise<void>;
36
- ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement>;
36
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement | null>;
37
37
  };
38
38
  cell: import('vue').ComputedRef<(cell: {
39
39
  date: Date;
@@ -48,7 +48,7 @@ export declare const createDataGrid: <Lazy extends boolean = false>(options: Cre
48
48
  id: string;
49
49
  };
50
50
  table: import('vue').ComputedRef<{
51
- ref: import('../../utils/builder.js').HeadlessElRef<HTMLTableElement>;
51
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLTableElement | null>;
52
52
  onFocusin: (event: FocusEvent) => void;
53
53
  onKeydown: (event: KeyboardEvent) => void;
54
54
  role: string;
@@ -64,7 +64,7 @@ export declare const createDataGrid: <Lazy extends boolean = false>(options: Cre
64
64
  };
65
65
  td: import('vue').ComputedRef<({ rowId, colKey, colIndex }: TdOptions<Lazy>) => {
66
66
  tabindex: string;
67
- ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement> | undefined;
67
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement | null> | undefined;
68
68
  "data-onyx-col-key": string;
69
69
  "aria-colindex": number | undefined;
70
70
  role: string;
@@ -33,7 +33,7 @@ export declare const createMenuButton: (options: CreateMenuButtonOptions) => {
33
33
  onMouseleave?: (() => void) | undefined;
34
34
  id: string;
35
35
  onKeydown: (event: KeyboardEvent) => void;
36
- ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement>;
36
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement | null>;
37
37
  }>;
38
38
  button: import('vue').ComputedRef<{
39
39
  readonly "aria-controls": string;
@@ -46,7 +46,7 @@ export declare const createMenuButton: (options: CreateMenuButtonOptions) => {
46
46
  }>;
47
47
  menu: {
48
48
  id: string;
49
- ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement>;
49
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement | null>;
50
50
  role: string;
51
51
  "aria-labelledby": string;
52
52
  onClick: () => void;
@@ -60,11 +60,8 @@ export type CreateSliderOptions<TValue extends SliderValue = SliderValue> = {
60
60
  /**
61
61
  * Composable for creating an accessibility-compliant slider.
62
62
  * For supported keyboard shortcuts, see: https://www.w3.org/WAI/ARIA/apg/patterns/slider/
63
- *
64
- * * @experimental
65
- * @deprecated This component is still under active development and its API might change in patch releases.
66
63
  */
67
- export declare const _unstableCreateSlider: <TValue extends SliderValue>(options: CreateSliderOptions<TValue>) => import('../../utils/builder.js').HeadlessComposable<{
64
+ export declare const createSlider: <TValue extends SliderValue>(options: CreateSliderOptions<TValue>) => import('../../utils/builder.js').HeadlessComposable<{
68
65
  /**
69
66
  * Root slider container element
70
67
  */
@@ -256,7 +253,7 @@ export declare const _unstableCreateSlider: <TValue extends SliderValue>(options
256
253
  onTransitionend?: ((payload: TransitionEvent) => void) | undefined;
257
254
  onTransitionrun?: ((payload: TransitionEvent) => void) | undefined;
258
255
  onTransitionstart?: ((payload: TransitionEvent) => void) | undefined;
259
- ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement>;
256
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement | null>;
260
257
  }>;
261
258
  /**
262
259
  * Individual thumb elements for each value (span)
@@ -469,6 +466,7 @@ export declare const _unstableCreateSlider: <TValue extends SliderValue>(options
469
466
  type: string;
470
467
  step: number;
471
468
  disabled: boolean | undefined;
469
+ ref: import('../../utils/builder.js').HeadlessElRef<HTMLElement | null> | undefined;
472
470
  }>;
473
471
  /**
474
472
  * Single Mark element inside the rail
@@ -510,5 +508,6 @@ export declare const _unstableCreateSlider: <TValue extends SliderValue>(options
510
508
  marks: import('vue').ComputedRef<SliderMark[]>;
511
509
  }, {
512
510
  updateValue: (value: number, index: number) => void;
511
+ updateValueByStep: (direction: "increase" | "decrease") => void;
513
512
  }>;
514
513
  export {};
package/dist/index.js CHANGED
@@ -1,15 +1,14 @@
1
1
  import { shallowRef, computed, toValue, ref, watch, nextTick, reactive, onBeforeMount, watchEffect, onBeforeUnmount, unref, useId, toRef } from "vue";
2
2
  const createBuilder = (builder) => builder;
3
3
  function createElRef() {
4
- const elementRef = shallowRef();
4
+ const elementRef = shallowRef(null);
5
5
  return computed({
6
- set: (element) => {
7
- if (Array.isArray(element)) {
8
- elementRef.value = element.at(0);
9
- } else if (element != null && "$el" in element) {
6
+ set: (ref2) => {
7
+ const element = Array.isArray(ref2) ? ref2.at(0) : ref2;
8
+ if (element != null && "$el" in element) {
10
9
  elementRef.value = element.$el;
11
10
  } else {
12
- elementRef.value = element;
11
+ elementRef.value = element ?? null;
13
12
  }
14
13
  },
15
14
  get: () => elementRef.value
@@ -977,17 +976,23 @@ const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
977
976
  ]);
978
977
  const INCREMENT_KEYS = /* @__PURE__ */ new Set(["ArrowRight", "ArrowUp", "PageUp"]);
979
978
  const DECREMENT_KEYS = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowDown", "PageDown"]);
980
- const _unstableCreateSlider = createBuilder(
979
+ const createSlider = createBuilder(
981
980
  (options) => {
982
981
  const sliderRef = createElRef();
982
+ const firstThumbRef = createElRef();
983
+ const secondThumbRef = createElRef();
983
984
  const min = computed(() => toValue(options.min) ?? 0);
984
985
  const max = computed(() => toValue(options.max) ?? 100);
985
986
  const step = computed(() => toValue(options.step) ?? 1);
986
987
  const draggingThumbIndex = ref();
987
988
  watch(draggingThumbIndex, (newThumbIndex) => {
988
989
  if (newThumbIndex == void 0) return;
989
- Array.from(sliderRef.value.querySelectorAll('[role="slider"]')).at(newThumbIndex)?.focus();
990
+ focusThumb(newThumbIndex);
990
991
  });
992
+ const focusThumb = (index) => {
993
+ if (index === 0) firstThumbRef.value?.focus();
994
+ else if (index === 1) secondThumbRef.value?.focus();
995
+ };
991
996
  const shiftStep = computed(() => {
992
997
  const shiftStep2 = toValue(options.shiftStep);
993
998
  if (shiftStep2 != void 0) return shiftStep2;
@@ -1042,6 +1047,13 @@ const _unstableCreateSlider = createBuilder(
1042
1047
  if (areArraysEqual(normalized, normalizedValue.value)) return;
1043
1048
  options.onChange?.(newValue);
1044
1049
  };
1050
+ const updateValueByStep = (direction) => {
1051
+ const index = 0;
1052
+ const stepValue = direction === "increase" ? step.value : -step.value;
1053
+ const currentValue = normalizedValue.value[index];
1054
+ updateValue(currentValue + stepValue, index);
1055
+ focusThumb(index);
1056
+ };
1045
1057
  const getValueInPercentage = computed(() => {
1046
1058
  return (value) => {
1047
1059
  const percentage = MathUtils.valueToPercent(value, min.value, max.value);
@@ -1101,8 +1113,8 @@ const _unstableCreateSlider = createBuilder(
1101
1113
  disabled: computed(() => draggingThumbIndex.value == void 0)
1102
1114
  });
1103
1115
  const getValueFromCoordinates = (x) => {
1104
- const rect = sliderRef.value.getBoundingClientRect();
1105
- if (rect.width <= 0) return;
1116
+ const rect = sliderRef.value?.getBoundingClientRect();
1117
+ if (!rect || rect.width <= 0) return;
1106
1118
  const percent = MathUtils.clamp((x - rect.left) / rect.width, 0, 1);
1107
1119
  return MathUtils.percentToValue(percent, min.value, max.value);
1108
1120
  };
@@ -1147,6 +1159,7 @@ const _unstableCreateSlider = createBuilder(
1147
1159
  "aria-orientation": "horizontal",
1148
1160
  step: step.value,
1149
1161
  disabled: toValue(options.disabled),
1162
+ ref: data.index === 0 ? firstThumbRef : data.index === 1 ? secondThumbRef : void 0,
1150
1163
  ...toValue(options.disabled) ? void 0 : events
1151
1164
  };
1152
1165
  }),
@@ -1209,7 +1222,8 @@ const _unstableCreateSlider = createBuilder(
1209
1222
  marks
1210
1223
  },
1211
1224
  internals: {
1212
- updateValue
1225
+ updateValue,
1226
+ updateValueByStep
1213
1227
  }
1214
1228
  };
1215
1229
  }
@@ -1398,7 +1412,6 @@ export {
1398
1412
  CLOSING_KEYS,
1399
1413
  OPENING_KEYS,
1400
1414
  _unstableCreateCalendar,
1401
- _unstableCreateSlider,
1402
1415
  createBuilder,
1403
1416
  createComboBox,
1404
1417
  createElRef,
@@ -1406,6 +1419,7 @@ export {
1406
1419
  createMenuButton,
1407
1420
  createMenuItems,
1408
1421
  createNavigationMenu,
1422
+ createSlider,
1409
1423
  createTabs,
1410
1424
  createToggletip,
1411
1425
  createTooltip,
@@ -61,7 +61,7 @@ type VueTemplateRefElement<E extends Element> = E | (ComponentPublicInstance & {
61
61
  }) | null;
62
62
  type VueTemplateRef<E extends Element> = Ref<VueTemplateRefElement<E>>;
63
63
  export declare const HeadlessElRefSymbol: unique symbol;
64
- export type HeadlessElRef<E extends Element> = WritableComputedRef<E> & {
64
+ export type HeadlessElRef<E extends Element | null> = WritableComputedRef<E | null> & {
65
65
  /**
66
66
  * type differentiator
67
67
  * ensures that only `createElRef` can be used for headless element ref bindings
@@ -85,5 +85,5 @@ export type HeadlessElRef<E extends Element> = WritableComputedRef<E> & {
85
85
  * });
86
86
  * ```
87
87
  */
88
- export declare function createElRef<E extends Element>(): HeadlessElRef<E>;
88
+ export declare function createElRef<E extends Element>(): HeadlessElRef<E | null>;
89
89
  export {};
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": "0.5.0-dev-20260112070348",
4
+ "version": "0.5.0-dev-20260112110323",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",