<script>
import Icon from "./Icon.svelte";
// One labelled input/textarea with its inline error (aria-invalid + aria-describedby + role=alert).
let { id, label, value = $bindable(""), error, type = "text", rows, ...rest } = $props();
</script>
<div class="field">
<label for={id}>{label}</label>
{#if rows}
<textarea {id} {rows} bind:value aria-invalid={!!error} aria-describedby={error ? `${id}-error` : undefined} required {...rest}></textarea>
{:else}
<input {id} {type} bind:value aria-invalid={!!error} aria-describedby={error ? `${id}-error` : undefined} required {...rest} />
{/if}
{#if error}<p class="error" id="{id}-error" role="alert"><Icon name="alert" />{error}</p>{/if}
</div>