Skip to content

Commit 5b0af61

Browse files
committed
fix: RadioButton
1 parent c5c83dd commit 5b0af61

File tree

7 files changed

+451
-708
lines changed

7 files changed

+451
-708
lines changed

src/lib/forms/radio-button/RadioButton.svelte

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,32 @@
66
77
let { children, group = $bindable<T>(), value = $bindable<T>(), inline, pill, outline, size, color, shadow, class: className, ...restProps }: RadioButtonProps<T> = $props();
88
9+
let inputEl: HTMLInputElement;
910
let base = $derived(radioButton({ inline, checked: value == group, class: clsx(className) }));
11+
12+
function clickHandler() {
13+
inputEl?.click(); // manually trigger the click on the hidden input
14+
}
1015
</script>
1116

12-
<Button tag="label" checked={value === group} {pill} {outline} {size} {color} {shadow} class={base}>
13-
<input type="radio" bind:group {value} {...restProps} class="sr-only" />
17+
<Button
18+
tag="label"
19+
onclick={clickHandler}
20+
{pill}
21+
{outline}
22+
{size}
23+
{color}
24+
{shadow}
25+
class={base}
26+
>
27+
<input
28+
bind:this={inputEl}
29+
type="radio"
30+
class="sr-only"
31+
value={value}
32+
bind:group={group}
33+
{...restProps}
34+
/>
1435
{@render children?.()}
1536
</Button>
1637

src/routes/docs/forms/checkbox.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ If you need separate control over the label and the checkbox you can use the ver
6767
<TableHeadCell>Left column</TableHeadCell>
6868
<TableHeadCell>Right column</TableHeadCell>
6969
</TableHead>
70-
<TableBody tableBodyClass="divide-y dark:divide-gray-700">
70+
<TableBody class="divide-y dark:divide-gray-700">
7171
<TableBodyRow class="divide-x rtl:divide-x-reverse dark:divide-gray-700">
7272
<TableBodyCell><Label for="checkbox1">Default checkbox</Label></TableBodyCell>
7373
<TableBodyCell><Label for="checkbox2">Disabled checkbox</Label></TableBodyCell>

src/routes/docs/forms/radio.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Use this example of an advanced layout of radio elements where the label parent
274274
</div>
275275
</Radio>
276276
<Radio name="custom" custom>
277-
<div for="hosting-big" class="dark:peer-checked:text-primary-500 peer-checked:border-primary-600 peer-checked:text-primary-600 inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300">
277+
<div class="dark:peer-checked:text-primary-500 peer-checked:border-primary-600 peer-checked:text-primary-600 inline-flex w-full cursor-pointer items-center justify-between rounded-lg border border-gray-200 bg-white p-5 text-gray-500 hover:bg-gray-100 hover:text-gray-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-300">
278278
<div class="block">
279279
<div class="w-full text-lg font-semibold">500-1000 MB</div>
280280
<div class="w-full">Good for large websites</div>

0 commit comments

Comments
 (0)