Skip to content

Commit cea938a

Browse files
committed
Improve TextInput UX
- Fixed valiation message shifting layout - Added aria labling and field highlighting - Removed redundant elements - Removed redundant classes
1 parent 35064bf commit cea938a

1 file changed

Lines changed: 38 additions & 34 deletions

File tree

src/lib/components/input/TextInput.svelte

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
oninput?: (input: string) => void | undefined;
2222
}
2323
24+
const id = $props.id();
25+
const inputId = id + '-input';
26+
const validationId = id + '-validation';
2427
let {
2528
type = 'text',
2629
label,
@@ -42,55 +45,56 @@
4245
}
4346
</script>
4447

45-
<label class="label w-full">
48+
<label for={inputId} class="label w-full">
4649
<span>{label}</span>
47-
<div class="flex flex-row items-center gap-2">
48-
<div class="input-group input-group-divider flex grow flex-row gap-2">
49-
{#if Icon}
50-
<Icon />
51-
{/if}
52-
<Input
53-
{type}
54-
class="input grow"
55-
title={label}
56-
{placeholder}
57-
{autocomplete}
58-
{value}
59-
oninput={handleInput}
60-
/>
61-
{#if button}
62-
<Button
63-
type="button"
64-
class={button.class ?? 'variant-filled-primary disabled:opacity-50'}
65-
onclick={button.onClick}
66-
disabled={button.submits &&
67-
(validationResult === null || (validationResult && !validationResult.valid))}
68-
>
69-
{#if 'Icon' in button}
70-
<button.Icon />
71-
{:else if 'text' in button}
72-
{button.text}
73-
{/if}
74-
</Button>
75-
{/if}
76-
</div>
50+
<div class="input-group input-group-divider flex grow flex-row items-center gap-2">
51+
{#if Icon}
52+
<Icon />
53+
{/if}
54+
<Input
55+
id={inputId}
56+
{type}
57+
class="input grow"
58+
title={label}
59+
{placeholder}
60+
{autocomplete}
61+
{value}
62+
oninput={handleInput}
63+
aria-invalid={validationResult ? !validationResult.valid : undefined}
64+
aria-describedby={validationResult ? validationId : undefined}
65+
/>
66+
{#if button}
67+
<Button
68+
type="button"
69+
class={button.class ?? 'variant-filled-primary disabled:opacity-50'}
70+
onclick={button.onClick}
71+
disabled={button.submits &&
72+
(validationResult === null || (validationResult && !validationResult.valid))}
73+
>
74+
{#if 'Icon' in button}
75+
<button.Icon />
76+
{:else if 'text' in button}
77+
{button.text}
78+
{/if}
79+
</Button>
80+
{/if}
7781
</div>
7882
{#if validationResult?.message}
79-
<p class="text-xs text-{GetValResColor(validationResult)} mt-0!">
83+
<p id={validationId} class="text-xs text-{GetValResColor(validationResult)} mt-0! h-4 truncate">
8084
{validationResult.message}
8185
{#if validationResult.link}
8286
<a
8387
href={validationResult.link.href}
8488
target="_blank"
8589
rel="noreferrer"
86-
class="text-xs text-blue-500 underline"
90+
class="text-blue-500 underline"
8791
>
8892
{validationResult.link.text}
8993
</a>
9094
{/if}
9195
</p>
9296
{:else}
93-
<div class="h-3"></div>
97+
<div class="h-4"></div>
9498
{/if}
9599
{#if popup}
96100
<Popover.Root>

0 commit comments

Comments
 (0)