Skip to content

Latest commit

 

History

History
179 lines (126 loc) · 8.18 KB

form.md

File metadata and controls

179 lines (126 loc) · 8.18 KB

Form

ui.form · parts: Form · elements: <form>

Purpose

Form is the native

. Submission, validation and state are the consumer's; the primitive only types the native form attributes.

Notes

  • One path for forms: use Form; Box no longer accepts tag="form" (it falls back to div).
  • method is whitelisted case-insensitively to get | post | dialog and printed lowercase; any other value (e.g. put) omits the attribute (the browser default get applies).
  • novalidate is a boolean attribute (present/absent). action, enctype, autocomplete, target, name, id are forwarded verbatim; empty strings are omitted.
  • No implicit role: a <form> is a landmark only when named — pass aria-label / aria-labelledby for that. Submission, validation and state stay with the consumer (onSubmit via rest props / attrs).
  • Layout with tokens and the 8+4 grid, e.g. class="grid gap-4 p-4 bg-card text-card-foreground".

Form renders a native form element; method is whitelisted (get|post|dialog).

Props

Canonical (templ, Jinja2, MiniJinja) React / Solid HTML (Svelte, Vue, WC) Type Default Kind Description
ID id id string — passthrough attr
Name name name string — passthrough attr
Action action action string — passthrough attr submission URL
Method method method "get" | "post" | "dialog" — prop HTTP method: get | post | dialog (omitted when empty)
Enctype encType enctype string — passthrough attr encoding for post (e.g. multipart/form-data)
NoValidate noValidate novalidate boolean — prop skip native constraint validation
Autocomplete autoComplete autocomplete string — passthrough attr on | off
Target target target string — passthrough attr browsing context for the response
AriaLabel aria-label aria-label string — passthrough attr
AriaLabelledBy aria-labelledby aria-labelledby string — passthrough attr
AriaDescribedBy aria-describedby aria-describedby string — passthrough attr

Also accepts: class (className in React), extra attributes (rest props in UI frameworks, Attrs in templ/Jinja2/MiniJinja, attrs in Twig/Latte; caller wins), children.

Variants

No variants: the primitive ships no visual classes; style it with token classes via class.

Children

Accepts children (default slot / children / { children... } / trusted HTML string in Twig, Latte, Jinja2, MiniJinja — see runtimes). Void tags selected via tag render no children.

ARIA

  • Computed/forwarded: aria-label, aria-labelledby, aria-describedby (omitted when empty).
  • Typed ARIA props: aria-label, aria-labelledby, aria-describedby — static values only.

Classes escape hatch

Compose the part's classes without rendering it (custom root element, no asChild outside React):

Runtime Helper
React / Solid / Vue / Svelte / WC formClasses({ ... }) from form/form.shared.ts
templ form.FormClasses(form.FormProps{...})
Twig ui8kit_classes('formClasses', { class: '…' })
Latte \UI8Kit\Latte\Classes::formClasses(['class' => '…'])
Jinja2 form_classes(p)
MiniJinja form_classes(p) (registered by ui8kit_minijinja::register)

Rendered DOM per state

Canonical renderer output (children = Content); all 10 runtimes are parity-tested to produce this DOM.

State Props HTML
defaults — <form>Content</form>
post {"Action":"/login","Method":"post","Name":"login","Autocomplete":"on","AriaLabel":"Sign in","Class":"grid gap-4 p-4 bg-card text-card-foreground"} <form class="grid gap-4 p-4 bg-card text-card-foreground" name="login" action="/login" method="post" autocomplete="on" aria-label="Sign in">Content</form>
upload {"Action":"/upload","Method":"POST","Enctype":"multipart/form-data","NoValidate":true,"Target":"_self","ID":"upload"} <form id="upload" action="/upload" method="post" enctype="multipart/form-data" novalidate target="_self">Content</form>
dialog {"Method":"dialog"} <form method="dialog">Content</form>
rejected {"Method":"put"} <form>Content</form>
Method=get {"Method":"get"} <form method="get">Content</form>
Method=post {"Method":"post"} <form method="post">Content</form>
Method=dialog {"Method":"dialog"} <form method="dialog">Content</form>
NoValidate {"NoValidate":true} <form novalidate>Content</form>

Usage

Fixture post ({"Action":"/login","Method":"post","Name":"login","Autocomplete":"on","AriaLabel":"Sign in","Class":"grid gap-4 p-4 bg-card text-card-foreground"}) — every snippet renders:

<form class="grid gap-4 p-4 bg-card text-card-foreground" name="login" action="/login" method="post" autocomplete="on" aria-label="Sign in">Content</form>

React (runtime notes)

import { Form } from "./ui/form/form";

<Form method="post" className="grid gap-4 p-4 bg-card text-card-foreground" action="/login" name="login" autoComplete="on" aria-label="Sign in">Content</Form>

Vue 3 (runtime notes)

<script setup lang="ts">
import Form from "./ui/form/Form.vue";
</script>

<template>
  <Form method="post" class="grid gap-4 p-4 bg-card text-card-foreground" action="/login" name="login" autocomplete="on" aria-label="Sign in">Content</Form>
</template>

Svelte 5 (runtime notes)

<script lang="ts">
  import Form from "./ui/form/Form.svelte";
</script>

<Form method="post" class="grid gap-4 p-4 bg-card text-card-foreground" action="/login" name="login" autocomplete="on" aria-label="Sign in">Content</Form>

SolidJS (runtime notes)

import { Form } from "./ui/form/form.solid";

<Form method="post" class="grid gap-4 p-4 bg-card text-card-foreground" action="/login" name="login" autocomplete="on" aria-label="Sign in">Content</Form>

Web Components (runtime notes)

import { renderForm } from "./ui/form/form.wc";

document.body.append(renderForm({ method: "post", class: "grid gap-4 p-4 bg-card text-card-foreground", action: "/login", name: "login", autocomplete: "on", "aria-label": "Sign in" }, "Content"));

Go templ (runtime notes)

import "github.com/ui8kit/codegen/generated/templ/ui/form"

@form.Form(form.FormProps{Action: "/login", Method: "post", Name: "login", Autocomplete: "on", AriaLabel: "Sign in", Class: "grid gap-4 p-4 bg-card text-card-foreground"}) {
	Content
}

Twig (runtime notes)

{% include 'form/Form.html.twig' with { action: '/login', method: 'post', name: 'login', autoComplete: 'on', ariaLabel: 'Sign in', class: 'grid gap-4 p-4 bg-card text-card-foreground', children: 'Content' } only %}

Latte (runtime notes)

{include 'form/Form.latte', action: '/login', method: 'post', name: 'login', autoComplete: 'on', ariaLabel: 'Sign in', class: 'grid gap-4 p-4 bg-card text-card-foreground', children: 'Content'}

Jinja2 (runtime notes)

{% with p = {'Action': '/login', 'Method': 'post', 'Name': 'login', 'Autocomplete': 'on', 'AriaLabel': 'Sign in', 'Class': 'grid gap-4 p-4 bg-card text-card-foreground'}, children = 'Content' %}{% include 'ui/form/form.html.j2' %}{% endwith %}

MiniJinja (Rust) (runtime notes)

{% import 'ui8kit.html' as ui %}
{{ ui.form({'Action': '/login', 'Method': 'post', 'Name': 'login', 'Autocomplete': 'on', 'AriaLabel': 'Sign in', 'Class': 'grid gap-4 p-4 bg-card text-card-foreground'}, children='Content') }}

Rules: contract · Index: docs