Skip to content

Commit

Permalink
chore: cleanup internals (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Dec 20, 2024
1 parent 2058ace commit b9255fd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class CollapsibleRootState {
open: CollapsibleRootStateProps["open"];
disabled: CollapsibleRootStateProps["disabled"];
contentNode = $state<HTMLElement | null>(null);
contentId = $state<string | undefined>(undefined);

constructor(props: CollapsibleRootStateProps) {
this.open = props.open;
Expand Down Expand Up @@ -87,7 +86,6 @@ class CollapsibleContentState {
deps: () => this.present,
onRefChange: (node) => {
this.root.contentNode = node;
this.root.contentId = node?.id;
},
});

Expand Down Expand Up @@ -206,7 +204,7 @@ class CollapsibleTriggerState {
id: this.#id.current,
type: "button",
disabled: this.#isDisabled,
"aria-controls": this.#root.contentId,
"aria-controls": this.#root.contentNode?.id,
"aria-expanded": getAriaExpanded(this.#root.open.current),
"data-state": getDataOpenClosed(this.#root.open.current),
"data-disabled": getDataDisabled(this.#isDisabled),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class LinkPreviewRootState {
containsSelection = $state(false);
timeout: number | null = null;
contentNode = $state<HTMLElement | null>(null);
contentId = $state<string | undefined>(undefined);
contentMounted = $state(false);
triggerNode = $state<HTMLElement | null>(null);
isPointerInTransit = box(false);
Expand Down Expand Up @@ -170,7 +169,7 @@ class LinkPreviewTriggerState {
"aria-haspopup": "dialog",
"aria-expanded": getAriaExpanded(this.#root.open.current),
"data-state": getDataOpenClosed(this.#root.open.current),
"aria-controls": this.#root.contentId,
"aria-controls": this.#root.contentNode?.id,
role: "button",
[TRIGGER_ATTR]: "",
onpointerenter: this.onpointerenter,
Expand Down Expand Up @@ -202,7 +201,6 @@ class LinkPreviewContentState {
ref: this.#ref,
onRefChange: (node) => {
this.root.contentNode = node;
this.root.contentId = node?.id;
},
deps: () => this.root.open.current,
});
Expand Down
27 changes: 14 additions & 13 deletions packages/bits-ui/src/lib/bits/popover/popover.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type PopoverRootStateProps = WritableBoxedValues<{
class PopoverRootState {
open: PopoverRootStateProps["open"];
contentNode = $state<HTMLElement | null>(null);
contentId = $state<string | undefined>(undefined);
triggerNode = $state<HTMLElement | null>(null);

constructor(props: PopoverRootStateProps) {
Expand Down Expand Up @@ -83,8 +82,8 @@ class PopoverTriggerState {
}

#getAriaControls() {
if (this.#root.open.current && this.#root.contentId) {
return this.#root.contentId;
if (this.#root.open.current && this.#root.contentNode?.id) {
return this.#root.contentNode?.id;
}
return undefined;
}
Expand Down Expand Up @@ -124,22 +123,24 @@ class PopoverContentState {
deps: () => this.root.open.current,
onRefChange: (node) => {
this.root.contentNode = node;
this.root.contentId = node?.id;
},
});
}

snippetProps = $derived.by(() => ({ open: this.root.open.current }));

props = $derived.by(() => ({
id: this.#id.current,
tabindex: -1,
"data-state": getDataOpenClosed(this.root.open.current),
"data-popover-content": "",
style: {
pointerEvents: "auto",
},
}));
props = $derived.by(
() =>
({
id: this.#id.current,
tabindex: -1,
"data-state": getDataOpenClosed(this.root.open.current),
"data-popover-content": "",
style: {
pointerEvents: "auto",
},
}) as const
);
}

type PopoverCloseStateProps = WithRefProps;
Expand Down
12 changes: 6 additions & 6 deletions packages/bits-ui/src/lib/bits/tabs/tabs.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,25 @@ class TabsTriggerState {
this.#root.setValue(this.#value.current);
}

onfocus = (_: BitsFocusEvent) => {
onfocus(_: BitsFocusEvent) {
if (this.#root.activationMode.current !== "automatic" || this.#isDisabled) return;
this.#activate();
};
}

onclick = (_: BitsMouseEvent) => {
onclick(_: BitsMouseEvent) {
if (this.#isDisabled) return;
this.#activate();
};
}

onkeydown = (e: BitsKeyboardEvent) => {
onkeydown(e: BitsKeyboardEvent) {
if (this.#isDisabled) return;
if (e.key === kbd.SPACE || e.key === kbd.ENTER) {
e.preventDefault();
this.#activate();
return;
}
this.#root.rovingFocusGroup.handleKeydown(this.#ref.current, e);
};
}

props = $derived.by(
() =>
Expand Down

0 comments on commit b9255fd

Please sign in to comment.