bits-ui 1.3.0 → 1.3.1

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.
@@ -13,6 +13,7 @@
13
13
 
14
14
  <svelte:element
15
15
  this={href ? "a" : "button"}
16
+ data-button-root
16
17
  type={href ? undefined : type}
17
18
  href={href && !disabled ? href : undefined}
18
19
  disabled={href ? undefined : disabled}
@@ -41,7 +41,6 @@
41
41
  enabled={contentState.root.opts.open.current}
42
42
  {id}
43
43
  {preventScroll}
44
- onPlaced={() => (contentState.isPositioned = true)}
45
44
  forceMount={true}
46
45
  >
47
46
  {#snippet popper({ props, wrapperProps })}
@@ -131,10 +131,6 @@ declare class SelectTriggerState {
131
131
  constructor(opts: SelectTriggerStateProps, root: SelectRootState);
132
132
  onkeydown(e: BitsKeyboardEvent): void;
133
133
  onclick(e: BitsMouseEvent): void;
134
- /**
135
- * `pointerdown` fires before the `focus` event, so we can prevent the default
136
- * behavior of focusing the button and keep focus on the input.
137
- */
138
134
  onpointerdown(e: BitsPointerEvent): void;
139
135
  onpointerup(e: BitsPointerEvent): void;
140
136
  props: {
@@ -339,6 +335,7 @@ declare class SelectScrollDownButtonState {
339
335
  content: SelectContentState;
340
336
  root: SelectBaseRootState;
341
337
  canScrollDown: boolean;
338
+ scrollIntoViewTimer: ReturnType<typeof globalThis.setTimeout> | null;
342
339
  constructor(state: SelectScrollButtonImplState);
343
340
  /**
344
341
  * @param manual - if true, it means the function was invoked manually outside of an event
@@ -1,5 +1,5 @@
1
1
  import { Context, Previous, watch } from "runed";
2
- import { afterTick, onDestroyEffect, srOnlyStyles, styleToString, useRefById, } from "svelte-toolbelt";
2
+ import { afterSleep, afterTick, onDestroyEffect, srOnlyStyles, styleToString, useRefById, } from "svelte-toolbelt";
3
3
  import { on } from "svelte/events";
4
4
  import { backward, forward, next, prev } from "../../internal/arrays.js";
5
5
  import { getAriaExpanded, getAriaHidden, getDataDisabled, getDataOpenClosed, getDisabled, getRequired, } from "../../internal/attrs.js";
@@ -163,6 +163,11 @@ class SelectMultipleRootState extends SelectBaseRootState {
163
163
  constructor(opts) {
164
164
  super(opts);
165
165
  this.opts = opts;
166
+ $effect(() => {
167
+ if (!this.opts.open.current && this.highlightedNode) {
168
+ this.setHighlightedNode(null);
169
+ }
170
+ });
166
171
  watch(() => this.opts.open.current, () => {
167
172
  if (!this.opts.open.current)
168
173
  return;
@@ -484,6 +489,7 @@ class SelectTriggerState {
484
489
  }
485
490
  if (!this.root.isMulti && !isCurrentSelectedValue) {
486
491
  this.root.handleClose();
492
+ return;
487
493
  }
488
494
  }
489
495
  if (e.key === kbd.ARROW_UP && e.altKey) {
@@ -546,10 +552,6 @@ class SelectTriggerState {
546
552
  const currTarget = e.currentTarget;
547
553
  currTarget.focus();
548
554
  }
549
- /**
550
- * `pointerdown` fires before the `focus` event, so we can prevent the default
551
- * behavior of focusing the button and keep focus on the input.
552
- */
553
555
  onpointerdown(e) {
554
556
  if (this.root.opts.disabled.current)
555
557
  return;
@@ -566,7 +568,6 @@ class SelectTriggerState {
566
568
  if (e.button === 0 && e.ctrlKey === false) {
567
569
  if (this.root.opts.open.current === false) {
568
570
  this.#handlePointerOpen(e);
569
- e.preventDefault();
570
571
  }
571
572
  else {
572
573
  this.root.handleClose();
@@ -908,15 +909,13 @@ class SelectScrollButtonImplState {
908
909
  ...opts,
909
910
  deps: () => this.mounted,
910
911
  });
911
- watch(() => this.mounted, () => {
912
+ watch([() => this.mounted], () => {
912
913
  if (!this.mounted) {
913
914
  this.isUserScrolling = false;
914
915
  return;
915
916
  }
916
917
  if (this.isUserScrolling)
917
918
  return;
918
- const activeItem = this.root.highlightedNode;
919
- activeItem?.scrollIntoView({ block: "nearest" });
920
919
  });
921
920
  $effect(() => {
922
921
  if (this.mounted)
@@ -973,24 +972,30 @@ class SelectScrollDownButtonState {
973
972
  content;
974
973
  root;
975
974
  canScrollDown = $state(false);
975
+ scrollIntoViewTimer = null;
976
976
  constructor(state) {
977
977
  this.state = state;
978
978
  this.content = state.content;
979
979
  this.root = state.root;
980
980
  this.state.onAutoScroll = this.handleAutoScroll;
981
- watch([
982
- () => this.content.viewportNode,
983
- () => this.content.isPositioned,
984
- () => this.root.opts.open.current,
985
- ], () => {
986
- if (!this.content.viewportNode ||
987
- !this.content.isPositioned ||
988
- !this.root.opts.open.current) {
981
+ watch([() => this.content.viewportNode, () => this.content.isPositioned], () => {
982
+ if (!this.content.viewportNode || !this.content.isPositioned) {
989
983
  return;
990
984
  }
991
985
  this.handleScroll(true);
992
986
  return on(this.content.viewportNode, "scroll", () => this.handleScroll());
993
987
  });
988
+ watch(() => this.state.mounted, () => {
989
+ if (!this.state.mounted)
990
+ return;
991
+ if (this.scrollIntoViewTimer) {
992
+ clearTimeout(this.scrollIntoViewTimer);
993
+ }
994
+ this.scrollIntoViewTimer = afterSleep(5, () => {
995
+ const activeItem = this.root.highlightedNode;
996
+ activeItem?.scrollIntoView({ block: "nearest" });
997
+ });
998
+ });
994
999
  }
995
1000
  /**
996
1001
  * @param manual - if true, it means the function was invoked manually outside of an event
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",