bits-ui 1.0.0-next.0 → 1.0.0-next.2

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.
@@ -9,6 +9,7 @@ import { getTabbableCandidates } from "../../internal/focus.js";
9
9
  import { createContext } from "../../internal/createContext.js";
10
10
  import { useGraceArea } from "../../internal/useGraceArea.svelte.js";
11
11
  import { onDestroyEffect } from "../../internal/onDestroyEffect.svelte.js";
12
+ import { afterSleep } from "../../internal/afterSleep.js";
12
13
  const CONTENT_ATTR = "data-link-preview-content";
13
14
  const TRIGGER_ATTR = "data-link-preview-trigger";
14
15
  class LinkPreviewRootState {
@@ -35,7 +36,7 @@ class LinkPreviewRootState {
35
36
  const handlePointerUp = () => {
36
37
  this.containsSelection = false;
37
38
  this.isPointerDownOnContent = false;
38
- sleep(1).then(() => {
39
+ afterSleep(1, () => {
39
40
  const isSelection = document.getSelection()?.toString() !== "";
40
41
  if (isSelection) {
41
42
  this.hasSelection = true;
@@ -243,6 +243,7 @@ class ListboxInputState {
243
243
  });
244
244
  }
245
245
  #onkeydown = async (e) => {
246
+ this.root.isUsingKeyboard = true;
246
247
  if (e.key === kbd.ESCAPE)
247
248
  return;
248
249
  const open = this.root.open.current;
@@ -118,6 +118,7 @@
118
118
  }}
119
119
  preventScroll={false}
120
120
  {loop}
121
+ trapFocus={false}
121
122
  >
122
123
  {#snippet popper({ props })}
123
124
  {@const finalProps = mergeProps(props, mergedProps, {
@@ -86,7 +86,9 @@ declare class MenuContentState {
86
86
  open: boolean;
87
87
  };
88
88
  props: {
89
- readonly [x: string]: string | ((e: KeyboardEvent) => void) | ((e: PointerEvent) => void);
89
+ readonly [x: string]: string | ((e: KeyboardEvent) => void) | ((e: PointerEvent) => void) | {
90
+ readonly pointerEvents: "auto";
91
+ };
90
92
  readonly id: string;
91
93
  readonly role: "menu";
92
94
  readonly "aria-orientation": "horizontal" | "vertical";
@@ -95,6 +97,10 @@ declare class MenuContentState {
95
97
  readonly onblur: (e: FocusEvent) => void;
96
98
  readonly onpointermove: (e: PointerEvent) => void;
97
99
  readonly onfocus: () => void;
100
+ readonly dir: Direction;
101
+ readonly style: {
102
+ readonly pointerEvents: "auto";
103
+ };
98
104
  };
99
105
  createItem(props: MenuItemSharedStateProps & MenuItemStateProps): MenuItemState;
100
106
  createCheckboxItem(props: MenuItemSharedStateProps & MenuItemStateProps & MenuCheckboxItemStateProps): MenuCheckboxItemState;
@@ -310,6 +310,10 @@ class MenuContentState {
310
310
  onblur: this.#onblur,
311
311
  onpointermove: this.#onpointermove,
312
312
  onfocus: this.#onfocus,
313
+ dir: this.parentMenu.root.dir.current,
314
+ style: {
315
+ pointerEvents: "auto",
316
+ },
313
317
  }));
314
318
  createItem(props) {
315
319
  const item = new MenuItemSharedState(props, this);
@@ -420,7 +424,7 @@ class MenuItemState {
420
424
  return;
421
425
  e.currentTarget.click();
422
426
  /**
423
- * We prevent default browser behaviour for selection keys as they should trigger
427
+ * We prevent default browser behavior for selection keys as they should trigger
424
428
  * a selection only:
425
429
  * - prevents space from scrolling the page.
426
430
  * - if keydown causes focus to move, prevents keydown from firing on the new target.
@@ -467,9 +471,9 @@ class MenuItemState {
467
471
  }
468
472
  class MenuSubTriggerState {
469
473
  #item;
470
- // The menu this subtrigger item belongs within
474
+ // The menu this sub-trigger item belongs within
471
475
  #content;
472
- // the menu this subtrigger item opens
476
+ // the menu this sub-trigger item opens
473
477
  #submenu;
474
478
  #openTimer = $state(null);
475
479
  constructor(item, content, submenu) {
@@ -18,6 +18,7 @@ import { clamp } from "../../internal/clamp.js";
18
18
  import { noop } from "../../internal/callbacks.js";
19
19
  import { addEventListener } from "../../internal/events.js";
20
20
  import { sleep } from "../../internal/sleep.js";
21
+ import { afterSleep } from "../../internal/afterSleep.js";
21
22
  export const OPEN_KEYS = [kbd.SPACE, kbd.ENTER, kbd.ARROW_UP, kbd.ARROW_DOWN];
22
23
  export const SELECTION_KEYS = [" ", kbd.ENTER];
23
24
  export const CONTENT_MARGIN = 10;
@@ -78,11 +79,11 @@ export class SelectRootState {
78
79
  };
79
80
  focusTriggerNode = (preventScroll = true) => {
80
81
  const node = this.triggerNode;
81
- if (node) {
82
- sleep(1).then(() => {
83
- node.focus({ preventScroll });
84
- });
85
- }
82
+ if (!node)
83
+ return;
84
+ afterSleep(1, () => {
85
+ node.focus({ preventScroll });
86
+ });
86
87
  };
87
88
  onNativeOptionAdd = (option) => {
88
89
  this.#nativeOptionsSet.set(option.current.value, option);
@@ -94,15 +95,13 @@ export class SelectRootState {
94
95
  const node = this.contentFragment;
95
96
  if (!node)
96
97
  return [];
97
- const candidates = Array.from(node.querySelectorAll(`[${ITEM_ATTR}]:not([data-disabled])`));
98
- return candidates;
98
+ return Array.from(node.querySelectorAll(`[${ITEM_ATTR}]:not([data-disabled])`));
99
99
  };
100
100
  getCandidateNodes = () => {
101
101
  const node = this.contentNode;
102
102
  if (!node)
103
103
  return [];
104
- const candidates = Array.from(node.querySelectorAll(`[${ITEM_ATTR}]:not([data-disabled])`));
105
- return candidates;
104
+ return Array.from(node.querySelectorAll(`[${ITEM_ATTR}]:not([data-disabled])`));
106
105
  };
107
106
  createTrigger(props) {
108
107
  return new SelectTriggerState(props, this);
@@ -74,7 +74,9 @@
74
74
  {customAnchor}
75
75
  >
76
76
  {#snippet content({ props: floatingProps })}
77
- <ScrollLock {preventScroll} />
77
+ {#if preventScroll}
78
+ <ScrollLock {preventScroll} />
79
+ {/if}
78
80
  <FocusScope
79
81
  {id}
80
82
  {onOpenAutoFocus}
@@ -1,13 +1,8 @@
1
1
  <script lang="ts">
2
- import { untrack } from "svelte";
3
2
  import type { ScrollLockProps } from "./index.js";
4
3
  import { useBodyScrollLock } from "../../../internal/useBodyScrollLock.svelte.js";
5
4
 
6
5
  let { preventScroll = true }: ScrollLockProps = $props();
7
6
 
8
- $effect(() => {
9
- if (preventScroll) {
10
- untrack(() => useBodyScrollLock(preventScroll));
11
- }
12
- });
7
+ useBodyScrollLock(preventScroll);
13
8
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.0.0-next.0",
3
+ "version": "1.0.0-next.2",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",