Components

Field component

The kit:field component is the base of the Lapikit form fields. It draws the box of the field (variant, color, size, density, rounded), the snippets around the control, the clear button and the message line, and it manages the states (error, disabled, readonly, focus).

It renders no control itself: you bring your own (a select, a date picker, a custom input…), and the field gives it the attributes to stay accessible. Textfield is a kit:field with an <input>.

field.svelte
The field wraps any control: here a native select.
<script lang="ts">
	let country = $state('');
</script>

<div style="max-width: 360px;">
	<kit:field
		variant="outline"
		message="The field wraps any control: here a native select."
		persistentMessage
		clearable
		dirty={country !== ''}
		onclear={() => (country = '')}
	>
		{#snippet children(control: {
			id: string;
			'aria-describedby': string | undefined;
			'aria-invalid': true | undefined;
			disabled: boolean;
		})}
			<select
				{...control}
				bind:value={country}
				style="flex: 1; border: 0; background: none; font: inherit; color: inherit; outline: none;"
			>
				<option value="" disabled>Choose a country</option>
				<option value="fr">France</option>
				<option value="be">Belgium</option>
				<option value="ch">Switzerland</option>
			</select>
		{/snippet}
	</kit:field>
</div>

The control

The children snippet receives the attributes to spread on the control:

attributedescription
idThe id prop, or a generated one.
aria-describedbyThe id of the message line, when there is one.
aria-invalidtrue when error is set.
disabledThe disabled prop.
readonlyThe readonly prop.
<kit:field message="Help">
	{#snippet children(control)}
		<input {...control} bind:value />
	{/snippet}
</kit:field>

The field does not know the value of the control: pass dirty to show the clear button, onclear to empty the value, and counter for the text at the end of the message line.

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the component directly:

import { Field } from 'lapikit/components';

API Reference

kit:field

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
classstring | array | objectClasses of the field, with the rules of Svelte (clsx).
stylestringInline style of the field.
s-classstring | array | objectClasses of the field, merged with class.
s-styleobjectInline style as an object of property / value pairs.
idstringId of the control, generated when empty.
variantenum'filled''tonal''outline''surface''text'Visual style of the box.'filled'
sizeenum'xs''sm''md''lg''xl'Height, padding, gap, font and icon size (in rem).'md'
densityenum'dense''compact''default''comfortable''spacious'Height and padding, from -4px to +4px.'default'
roundedenum0'xs''sm''md''lg''xl''full'Border radius of the box.'md'
colorstring | false | { base?, active? }Color of the box, its use depends on the variant.
elevationElevationStateenum'0''1''2''3''4''5'Add shadow effect on the box.
errorbooleanError state: error color on the border and the message.false
errorMessagestringMessage shown when error is true.
messagestringHelper text below the field.
messagePrefixstringLeading text in the message row.
messageSuffixstringTrailing text in the message row.
counterstringTrailing text in the message row, replaces messageSuffix.
persistentMessagebooleanAlways shows the message, not only on focus.false
clearablebooleanShows a clear button.false
persistentClearbooleanAlways shows the clear button.false
dirtybooleanThe control holds a value: shows the clear button.false
onclear() => voidCalled by the clear button.
disabledbooleanDims the field, given to the control.false
readonlybooleanGiven to the control.false
prefixstringStatic text before the control.
suffixstringStatic text after the control.
prependSnippetContent outside the box, before it.
appendSnippetContent outside the box, after it.
prependInnerSnippetContent inside the box, before the control.
appendInnerSnippetContent inside the box, after the control.
childrenSnippet<[FieldControlProps]>The control, receives the attributes to spread on it.

Use kit:field to build your own form fields, or use the ready-made Textfield.