bits-ui 1.0.0-next.12 → 1.0.0-next.13

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.
@@ -76,7 +76,7 @@ class RadioGroupItemState {
76
76
  this.#root.setValue(this.#value.current);
77
77
  };
78
78
  #onkeydown = (e) => {
79
- this.#root.rovingFocusGroup.handleKeydown(this.#ref.current, e);
79
+ this.#root.rovingFocusGroup.handleKeydown(this.#ref.current, e, true);
80
80
  };
81
81
  #tabIndex = $derived.by(() => this.#root.rovingFocusGroup.getTabIndex(this.#ref.current));
82
82
  snippetProps = $derived.by(() => ({ checked: this.#isChecked }));
@@ -35,7 +35,7 @@ export type UseRovingFocusReturn = ReturnType<typeof useRovingFocus>;
35
35
  export declare function useRovingFocus(props: UseRovingFocusProps): {
36
36
  setCurrentTabStopId(id: string): void;
37
37
  getTabIndex: (node: HTMLElement | null | undefined) => 0 | -1;
38
- handleKeydown: (node: HTMLElement | null | undefined, e: KeyboardEvent) => HTMLElement | undefined;
38
+ handleKeydown: (node: HTMLElement | null | undefined, e: KeyboardEvent, both?: boolean) => HTMLElement | undefined;
39
39
  focusFirstCandidate: () => void;
40
40
  currentTabStopId: WritableBox<string | null>;
41
41
  };
@@ -28,7 +28,7 @@ export function useRovingFocus(props) {
28
28
  return;
29
29
  items[0]?.focus();
30
30
  }
31
- function handleKeydown(node, e) {
31
+ function handleKeydown(node, e, both = false) {
32
32
  const rootNode = document.getElementById(props.rootNodeId.current);
33
33
  if (!rootNode || !node)
34
34
  return;
@@ -45,6 +45,12 @@ export function useRovingFocus(props) {
45
45
  [kbd.HOME]: 0,
46
46
  [kbd.END]: items.length - 1,
47
47
  };
48
+ if (both) {
49
+ const altNextKey = nextKey === kbd.ARROW_DOWN ? kbd.ARROW_RIGHT : kbd.ARROW_DOWN;
50
+ const altPrevKey = prevKey === kbd.ARROW_UP ? kbd.ARROW_LEFT : kbd.ARROW_UP;
51
+ keyToIndex[altNextKey] = currentIndex + 1;
52
+ keyToIndex[altPrevKey] = currentIndex - 1;
53
+ }
48
54
  let itemIndex = keyToIndex[e.key];
49
55
  if (itemIndex === undefined)
50
56
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.0.0-next.12",
3
+ "version": "1.0.0-next.13",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",