Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sour-walls-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik-ui/styled': patch
---

PATCH: The styled Input, Checkbox and Textarea components now properly handle two way data-binding and allow passing onInput$ outside and inside of forms.
13 changes: 7 additions & 6 deletions apps/website/src/routes/docs/styled/checkbox/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ qwik-ui add checkbox
import { $, type PropsOf, component$ } from '@builder.io/qwik';
import { cn } from '@qwik-ui/utils';

export const Checkbox = component$<PropsOf<'input'>>(
({ id, name, ['bind:checked']: checkedSig, checked, onInput$, ...props }) => {
export const Checkbox = component$<Partial<PropsOf<'input'> & { type?: 'checkbox' }>>(
({ id, name, ['bind:checked']: bindSig, checked, onInput$, ...props }) => {
const inputId = id || name;
return (
<input
type="checkbox"
{...props}
type="checkbox"
// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
checked={checkedSig ? checkedSig.value : checked}
onInput$={checkedSig ? $((_, el) => (checkedSig.value = el.checked)) : onInput$}
data-checked={checked || checkedSig?.value || ''}
checked={bindSig ? bindSig.value : checked}
onInput$={[bindSig && $((_, el) => (bindSig.value = el.checked)), onInput$]}
data-checked={checked || bindSig?.value || ''}
class={cn(
'peer h-4 w-4 shrink-0 border-primary text-primary accent-primary ring-offset-background focus:ring-ring focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
)}
id={inputId}
name={name}
/>
);
},
Expand Down
11 changes: 6 additions & 5 deletions apps/website/src/routes/docs/styled/input/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,27 @@ type InputProps = PropsOf<'input'> & {
};

export const Input = component$<InputProps>(
({ name, error, id, ['bind:value']: valueSig, value, onInput$, ...props }) => {
({ name, error, id, ['bind:value']: bindSig, value, onInput$, ...props }) => {
const inputId = id || name;

return (
<>
<input
{...props}
aria-errormessage={`${inputId}-error`}
aria-invaid={!!error}
aria-invalid={!!error}
// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
value={valueSig ? valueSig.value : value}
onInput$={valueSig ? $((__, el) => (valueSig.value = el.value)) : onInput$}
value={bindSig ? bindSig.value : value}
onInput$={[bindSig && $((_, el) => (bindSig.value = el.value)), onInput$]}
class={cn(
'flex h-12 w-full rounded-base border border-input bg-background px-3 py-1 text-sm text-foreground shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
)}
id={inputId}
name={name}
/>
{error && (
<div id={`${inputId}-error`} class="text-alert mt-1 text-sm">
<div id={`${inputId}-error`} class="mt-1 text-sm text-alert">
{error}
</div>
)}
Expand Down
7 changes: 4 additions & 3 deletions apps/website/src/routes/docs/styled/textarea/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ type TextareaProps = PropsOf<'textarea'> & {
};

export const Textarea = component$<TextareaProps>(
({ id, name, error, ['bind:value']: valueSig, value, onInput$, ...props }) => {
({ id, name, error, ['bind:value']: bindSig, value, onInput$, ...props }) => {
const textareaId = id || name;
return (
<>
<textarea
{...props}
// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
value={valueSig ? valueSig.value : value}
onInput$={valueSig ? $((__, el) => (valueSig.value = el.value)) : onInput$}
value={bindSig ? bindSig.value : value}
onInput$={[bindSig && $((_, el) => (bindSig.value = el.value)), onInput$]}
class={cn(
'[&::-webkit-scrollbar-track]:bg-blue flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
)}
id={textareaId}
name={name}
/>
{error && <div id={`${textareaId}-error`}>{error}</div>}
</>
Expand Down
8 changes: 4 additions & 4 deletions packages/kit-styled/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { $, type PropsOf, component$ } from '@builder.io/qwik';
import { cn } from '@qwik-ui/utils';

export const Checkbox = component$<Partial<PropsOf<'input'> & { type?: 'checkbox' }>>(
({ id, name, ['bind:checked']: checkedSig, checked, onInput$, ...props }) => {
({ id, name, ['bind:checked']: bindSig, checked, onInput$, ...props }) => {
const inputId = id || name;
return (
<input
{...props}
type="checkbox"
// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
checked={checkedSig ? checkedSig.value : checked}
onInput$={checkedSig ? $((_, el) => (checkedSig.value = el.checked)) : onInput$}
data-checked={checked || checkedSig?.value || ''}
checked={bindSig ? bindSig.value : checked}
onInput$={[bindSig && $((_, el) => (bindSig.value = el.checked)), onInput$]}
data-checked={checked || bindSig?.value || ''}
class={cn(
'peer h-4 w-4 shrink-0 border-primary text-primary accent-primary ring-offset-background focus:ring-ring focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
Expand Down
6 changes: 3 additions & 3 deletions packages/kit-styled/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type InputProps = PropsOf<'input'> & {
};

export const Input = component$<InputProps>(
({ name, error, id, ['bind:value']: valueSig, value, onInput$, ...props }) => {
({ name, error, id, ['bind:value']: bindSig, value, onInput$, ...props }) => {
const inputId = id || name;

return (
Expand All @@ -16,8 +16,8 @@ export const Input = component$<InputProps>(
aria-errormessage={`${inputId}-error`}
aria-invalid={!!error}
// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
value={valueSig ? valueSig.value : value}
onInput$={valueSig ? $((__, el) => (valueSig.value = el.value)) : onInput$}
value={bindSig ? bindSig.value : value}
onInput$={[bindSig && $((_, el) => (bindSig.value = el.value)), onInput$]}
class={cn(
'flex h-12 w-full rounded-base border border-input bg-background px-3 py-1 text-sm text-foreground shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
Expand Down
7 changes: 4 additions & 3 deletions packages/kit-styled/src/components/textarea/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ type TextareaProps = PropsOf<'textarea'> & {
};

export const Textarea = component$<TextareaProps>(
({ id, name, error, ['bind:value']: valueSig, value, onInput$, ...props }) => {
({ id, name, error, ['bind:value']: bindSig, value, onInput$, ...props }) => {
const textareaId = id || name;
return (
<>
<textarea
{...props}
// workaround to support two way data-binding on the Input component (https://github.com/QwikDev/qwik/issues/3926)
value={valueSig ? valueSig.value : value}
onInput$={valueSig ? $((__, el) => (valueSig.value = el.value)) : onInput$}
value={bindSig ? bindSig.value : value}
onInput$={[bindSig && $((_, el) => (bindSig.value = el.value)), onInput$]}
class={cn(
'[&::-webkit-scrollbar-track]:bg-blue flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
props.class,
)}
id={textareaId}
name={name}
/>
{error && <div id={`${textareaId}-error`}>{error}</div>}
</>
Expand Down