Skip to content

Commit 7b54062

Browse files
committed
fix: allow overriding checkbox type
1 parent a718121 commit 7b54062

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.changeset/proud-snakes-occur.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
Allow users to override the `type` attribute on `Checkbox.Root`

packages/bits-ui/src/lib/bits/checkbox/checkbox.svelte.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { srOnlyStyles, styleToString, useRefById } from "svelte-toolbelt";
2+
import type { HTMLButtonAttributes } from "svelte/elements";
23
import type { ReadableBoxedValues, WritableBoxedValues } from "$lib/internal/box.svelte.js";
34
import type { WithRefProps } from "$lib/internal/types.js";
45
import { getAriaChecked, getAriaRequired, getDataDisabled } from "$lib/internal/attrs.js";
@@ -13,6 +14,7 @@ type CheckboxRootStateProps = WithRefProps<
1314
required: boolean;
1415
name: string | undefined;
1516
value: string | undefined;
17+
type: HTMLButtonAttributes["type"];
1618
}> &
1719
WritableBoxedValues<{
1820
checked: boolean;
@@ -23,6 +25,7 @@ type CheckboxRootStateProps = WithRefProps<
2325
class CheckboxRootState {
2426
#id: CheckboxRootStateProps["id"];
2527
#ref: CheckboxRootStateProps["ref"];
28+
#type: CheckboxRootStateProps["type"];
2629
checked: CheckboxRootStateProps["checked"];
2730
disabled: CheckboxRootStateProps["disabled"];
2831
required: CheckboxRootStateProps["required"];
@@ -39,6 +42,7 @@ class CheckboxRootState {
3942
this.#ref = props.ref;
4043
this.#id = props.id;
4144
this.indeterminate = props.indeterminate;
45+
this.#type = props.type;
4246

4347
useRefById({
4448
id: this.#id,
@@ -74,7 +78,7 @@ class CheckboxRootState {
7478
({
7579
id: this.#id.current,
7680
role: "checkbox",
77-
type: "button",
81+
type: this.#type.current,
7882
disabled: this.disabled.current,
7983
"aria-checked": getAriaChecked(this.checked.current, this.indeterminate.current),
8084
"aria-required": getAriaRequired(this.required.current),

packages/bits-ui/src/lib/bits/checkbox/components/checkbox.svelte

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
controlledIndeterminate = false,
2121
onIndeterminateChange,
2222
child,
23+
type = "button",
2324
...restProps
2425
}: CheckboxRootProps = $props();
2526
@@ -55,6 +56,7 @@
5556
}
5657
}
5758
),
59+
type: box.with(() => type),
5860
});
5961
6062
const mergedProps = $derived(mergeProps({ ...restProps }, rootState.props));

0 commit comments

Comments
 (0)