Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryWu1234 committed Jan 5, 2025
1 parent e7e5a94 commit e6969b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContextId, QRL, type Signal } from '@builder.io/qwik';

export interface SwitchState {
'bind:checked': Signal<boolean>;
defaultChecked?: boolean;
checked?: boolean;
disabled?: boolean;
onChange$?: QRL<(checked: boolean, event: MouseEvent | KeyboardEvent) => void>;
onClick$?: QRL<(checked: boolean, event: MouseEvent | KeyboardEvent) => void>;
Expand Down
6 changes: 4 additions & 2 deletions packages/kit-headless/src/components/switch/switch-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const SwitchInput = component$<PropsOf<'input'>>((rest) => {
const context = useContext(SwitchContext);
const switchRef = useSignal<HTMLInputElement | undefined>();
const id = useId();
if (context.defaultChecked && context.bindChecked && !context.bindChecked.value) {
if (context.checked && context.bindChecked && !context.bindChecked.value) {
context.bindChecked.value = !context.bindChecked.value;
}

Expand Down Expand Up @@ -55,13 +55,15 @@ export const SwitchInput = component$<PropsOf<'input'>>((rest) => {
>
<input
{...rest}

aria-label={'switch'}
data-checked={context.bindChecked?.value ? 'true' : 'false'}
data-disabled={context.disabled ? 'true' : 'false'}
ref={context.switchRef || switchRef}
aria-describedby={`${id}-switch`}
disabled={context.disabled}
bind:checked={context.bindChecked}
checked={context.bindChecked?.value}
aria-checked={context.bindChecked ? 'true' : 'false'}
type="checkbox"
role="switch"
data-value
Expand Down

0 comments on commit e6969b1

Please sign in to comment.