diff --git a/src/lib/holocene/checkbox.svelte b/src/lib/holocene/checkbox.svelte index d32dbdca28..a658d796cb 100644 --- a/src/lib/holocene/checkbox.svelte +++ b/src/lib/holocene/checkbox.svelte @@ -75,6 +75,9 @@ : checked ? ('checkmark' as const) : null; + + $: errorId = `${id}-error`; + $: showError = !valid && !!error;
{hintText}
diff --git a/src/lib/holocene/input/input.svelte b/src/lib/holocene/input/input.svelte index 309fef7ff1..f3d01303c3 100644 --- a/src/lib/holocene/input/input.svelte +++ b/src/lib/holocene/input/input.svelte @@ -79,6 +79,8 @@ const isDisabled = $derived(disabled || copyable); const testId = $derived(dataTestId || id); + const errorId = $derived(`${id}-error`); + const showError = $derived(error || !valid); function callFocus(input: HTMLInputElement) { if (autoFocus && input) input.focus(); @@ -134,6 +136,8 @@ {name} {spellcheck} {required} + aria-invalid={showError ? 'true' : undefined} + aria-describedby={showError && hintText ? errorId : undefined} {autocomplete} bind:value onclick={(e) => { @@ -191,10 +195,11 @@ class:hidden={!hintText && (!maxLength || isDisabled || hideCount)} > {hintText} diff --git a/src/lib/holocene/input/number-input.svelte b/src/lib/holocene/input/number-input.svelte index a21da517ff..7b6bf3e251 100644 --- a/src/lib/holocene/input/number-input.svelte +++ b/src/lib/holocene/input/number-input.svelte @@ -37,6 +37,8 @@ $: { validate(value); } + + $: errorId = `${id}-error`;