Skip to content

Commit 6267a73

Browse files
authored
Merge pull request #765 from maiieul/input-name-to-id-prop
refactor(styled input/checkbox/textarea): improve handling of name/id props
2 parents f47619e + acaedf2 commit 6267a73

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { PropsOf, component$ } from '@builder.io/qwik';
22
import { cn } from '@qwik-ui/utils';
33

4-
export const Checkbox = component$<PropsOf<'input'>>(({ name, ...props }) => {
4+
export const Checkbox = component$<PropsOf<'input'>>(({ id, name, ...props }) => {
5+
const inputId = id || name;
56
return (
67
<input
78
type="checkbox"
@@ -10,8 +11,7 @@ export const Checkbox = component$<PropsOf<'input'>>(({ name, ...props }) => {
1011
'peer 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 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
1112
props.class,
1213
)}
13-
name={name}
14-
id={name}
14+
id={inputId}
1515
/>
1616
);
1717
});

packages/kit-styled/src/components/input/input.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ export const Input = component$<InputProps>(
1212
'bind:value': valueSig,
1313
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1414
'bind:checked': checkedSig,
15+
id,
1516
...props
1617
}) => {
18+
const inputId = id || name;
1719
return (
1820
<>
1921
<input
2022
{...props}
21-
aria-errormessage={`${name}-error`}
23+
aria-errormessage={`${inputId}-error`}
2224
aria-invalid={!!error}
2325
bind:value={valueSig}
2426
class={cn(
2527
'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',
2628
props.class,
2729
)}
28-
id={name}
30+
id={inputId}
2931
/>
3032
{error && (
31-
<div id={`${name}-error`} class="text-destructive mt-1 text-sm">
33+
<div id={`${inputId}-error`} class="text-destructive mt-1 text-sm">
3234
{error}
3335
</div>
3436
)}

packages/kit-styled/src/components/textarea/textarea.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ type TextareaProps = PropsOf<'textarea'> & {
55
error?: string;
66
};
77

8-
export const Textarea = component$<TextareaProps>(({ name, error, ...props }) => {
8+
export const Textarea = component$<TextareaProps>(({ id, name, error, ...props }) => {
9+
const textareaId = id || name;
910
return (
1011
<>
1112
<textarea
@@ -14,8 +15,9 @@ export const Textarea = component$<TextareaProps>(({ name, error, ...props }) =>
1415
'[&::-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',
1516
props.class,
1617
)}
18+
id={textareaId}
1719
/>
18-
{error && <div id={`${name}-error`}>{error}</div>}
20+
{error && <div id={`${textareaId}-error`}>{error}</div>}
1921
</>
2022
);
2123
});

0 commit comments

Comments
 (0)