bits-ui 2.8.10 → 2.8.12
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.
|
@@ -62,7 +62,7 @@ export declare class CheckboxRootState {
|
|
|
62
62
|
readonly attachment: RefAttachment;
|
|
63
63
|
constructor(opts: CheckboxRootStateOpts, group: CheckboxGroupState | null);
|
|
64
64
|
onkeydown(e: BitsKeyboardEvent): void;
|
|
65
|
-
onclick(
|
|
65
|
+
onclick(e: BitsMouseEvent): void;
|
|
66
66
|
readonly snippetProps: {
|
|
67
67
|
checked: boolean;
|
|
68
68
|
indeterminate: boolean;
|
|
@@ -76,7 +76,7 @@ export declare class CheckboxRootState {
|
|
|
76
76
|
readonly "aria-required": "true" | "false";
|
|
77
77
|
readonly "data-disabled": "" | undefined;
|
|
78
78
|
readonly "data-state": "checked" | "indeterminate" | "unchecked";
|
|
79
|
-
readonly onclick: (
|
|
79
|
+
readonly onclick: (e: BitsMouseEvent) => void;
|
|
80
80
|
readonly onkeydown: (e: BitsKeyboardEvent) => void;
|
|
81
81
|
};
|
|
82
82
|
}
|
|
@@ -143,9 +143,10 @@ export class CheckboxRootState {
|
|
|
143
143
|
this.opts.checked.current = !this.opts.checked.current;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
onclick(
|
|
146
|
+
onclick(e) {
|
|
147
147
|
if (this.opts.disabled.current)
|
|
148
148
|
return;
|
|
149
|
+
e.preventDefault();
|
|
149
150
|
this.#toggle();
|
|
150
151
|
}
|
|
151
152
|
snippetProps = $derived.by(() => ({
|
|
@@ -866,7 +866,7 @@ export class ContextMenuTriggerState {
|
|
|
866
866
|
this.parentMenu.onOpen();
|
|
867
867
|
}
|
|
868
868
|
oncontextmenu(e) {
|
|
869
|
-
if (this.opts.disabled.current)
|
|
869
|
+
if (e.defaultPrevented || this.opts.disabled.current)
|
|
870
870
|
return;
|
|
871
871
|
this.#clearLongPressTimer();
|
|
872
872
|
this.#handleOpen(e);
|
|
@@ -28,6 +28,7 @@ interface SelectBaseRootStateOpts extends ReadableBoxedValues<{
|
|
|
28
28
|
isCombobox: boolean;
|
|
29
29
|
}
|
|
30
30
|
declare abstract class SelectBaseRootState {
|
|
31
|
+
#private;
|
|
31
32
|
readonly opts: SelectBaseRootStateOpts;
|
|
32
33
|
touchedInput: boolean;
|
|
33
34
|
inputNode: HTMLElement | null;
|
|
@@ -44,7 +45,9 @@ declare abstract class SelectBaseRootState {
|
|
|
44
45
|
constructor(opts: SelectBaseRootStateOpts);
|
|
45
46
|
setHighlightedNode(node: HTMLElement | null, initial?: boolean): void;
|
|
46
47
|
getCandidateNodes(): HTMLElement[];
|
|
47
|
-
setHighlightedToFirstCandidate(
|
|
48
|
+
setHighlightedToFirstCandidate(options?: {
|
|
49
|
+
debounced: boolean;
|
|
50
|
+
}): void;
|
|
48
51
|
getNodeByValue(value: string): HTMLElement | null;
|
|
49
52
|
setOpen(open: boolean): void;
|
|
50
53
|
toggleOpen(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Previous, watch } from "runed";
|
|
2
|
-
import { afterSleep, afterTick, onDestroyEffect, attachRef, DOMContext, box, } from "svelte-toolbelt";
|
|
2
|
+
import { afterSleep, afterTick, onDestroyEffect, onMountEffect, attachRef, DOMContext, box, } 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";
|
|
@@ -11,6 +11,7 @@ import { getFloatingContentCSSVars } from "../../internal/floating-svelte/floati
|
|
|
11
11
|
import { DataTypeahead } from "../../internal/data-typeahead.svelte.js";
|
|
12
12
|
import { DOMTypeahead } from "../../internal/dom-typeahead.svelte.js";
|
|
13
13
|
import { OpenChangeComplete } from "../../internal/open-change-complete.js";
|
|
14
|
+
import { debounce } from "../../internal/debounce.js";
|
|
14
15
|
// prettier-ignore
|
|
15
16
|
export const INTERACTION_KEYS = [kbd.ARROW_LEFT, kbd.ESCAPE, kbd.ARROW_RIGHT, kbd.SHIFT, kbd.CAPS_LOCK, kbd.CONTROL, kbd.ALT, kbd.META, kbd.ENTER, kbd.F1, kbd.F2, kbd.F3, kbd.F4, kbd.F5, kbd.F6, kbd.F7, kbd.F8, kbd.F9, kbd.F10, kbd.F11, kbd.F12];
|
|
16
17
|
export const FIRST_KEYS = [kbd.ARROW_DOWN, kbd.PAGE_UP, kbd.HOME];
|
|
@@ -82,6 +83,7 @@ class SelectBaseRootState {
|
|
|
82
83
|
}
|
|
83
84
|
});
|
|
84
85
|
}
|
|
86
|
+
#debouncedSetHighlightedToFirstCandidate = debounce(this.setHighlightedToFirstCandidate.bind(this), 20);
|
|
85
87
|
setHighlightedNode(node, initial = false) {
|
|
86
88
|
this.highlightedNode = node;
|
|
87
89
|
if (node && (this.isUsingKeyboard || initial)) {
|
|
@@ -94,7 +96,11 @@ class SelectBaseRootState {
|
|
|
94
96
|
return [];
|
|
95
97
|
return Array.from(node.querySelectorAll(`[${this.getBitsAttr("item")}]:not([data-disabled])`));
|
|
96
98
|
}
|
|
97
|
-
setHighlightedToFirstCandidate() {
|
|
99
|
+
setHighlightedToFirstCandidate(options = { debounced: false }) {
|
|
100
|
+
if (options.debounced) {
|
|
101
|
+
this.#debouncedSetHighlightedToFirstCandidate();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
98
104
|
this.setHighlightedNode(null);
|
|
99
105
|
const candidateNodes = this.getCandidateNodes();
|
|
100
106
|
if (!candidateNodes.length)
|
|
@@ -372,7 +378,6 @@ export class SelectInputState {
|
|
|
372
378
|
}
|
|
373
379
|
oninput(e) {
|
|
374
380
|
this.root.opts.inputValue.current = e.currentTarget.value;
|
|
375
|
-
this.root.setHighlightedToFirstCandidate();
|
|
376
381
|
}
|
|
377
382
|
props = $derived.by(() => ({
|
|
378
383
|
id: this.opts.id.current,
|
|
@@ -785,6 +790,12 @@ export class SelectItemState {
|
|
|
785
790
|
this.opts = opts;
|
|
786
791
|
this.root = root;
|
|
787
792
|
this.attachment = attachRef(opts.ref);
|
|
793
|
+
onMountEffect(() => {
|
|
794
|
+
this.root.setHighlightedToFirstCandidate({ debounced: true });
|
|
795
|
+
});
|
|
796
|
+
onDestroyEffect(() => {
|
|
797
|
+
this.root.setHighlightedToFirstCandidate({ debounced: true });
|
|
798
|
+
});
|
|
788
799
|
watch([() => this.isHighlighted, () => this.prevHighlighted.current], () => {
|
|
789
800
|
if (this.isHighlighted) {
|
|
790
801
|
this.opts.onHighlight.current();
|