Zubra UI
Code for
GitHub

text-field

A labelled text field on a native <input> (or <textarea> with rows), so it submits under its name, autofills, and validates as the browser's own (required, type="email", minlength, pattern). The message shows after the field is left, or when the form is submitted, and is linked to the field for screen readers. value is two-way.

Try it: events appear here (valuechange).

Source: text-field.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/text-field.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/text-field.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/text-field.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/text-field.json
One file, no dependencies (3.9 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/text-field.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/text-field.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/text-field.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/text-field.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/text-field.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/text-field.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/text-field.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/text-field.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/text-field.js"></script>

The compiled install writes src/components/zubra/text-field.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<text-field
  label="Email"
  description="We'll send the receipt here."
  type="email"
  name="email"
  autocomplete="email"
  placeholder="you@example.com"
></text-field>

<script type="module">
  import './components/zubra/text-field.js';

  const element = document.querySelector('text-field');
  element.required = true;
  element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>
Example.jsx
import './components/zubra/text-field.js';

const required = true;

export function TextFieldExample() {
  return (
    <text-field
      label="Email"
      description="We'll send the receipt here."
      type="email"
      name="email"
      autocomplete="email"
      placeholder="you@example.com"
      required={required}
      onvaluechange={(event) => console.log('valuechange', event.detail)}
    ></text-field>
  );
}
Example.vue
<script setup>
import './components/zubra/text-field.js';
const required = true;
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>

<template>
  <text-field
    label="Email"
    description="We'll send the receipt here."
    type="email"
    name="email"
    autocomplete="email"
    placeholder="you@example.com"
    :required.prop="required"
    @valuechange="onValuechange"
  ></text-field>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/text-field.js';
  const required = true;
</script>

<text-field
  label="Email"
  description="We'll send the receipt here."
  type="email"
  name="email"
  autocomplete="email"
  placeholder="you@example.com"
  {required}
  onvaluechange={(event) => console.log('valuechange', event.detail)}
></text-field>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/text-field.js';

@Component({
  selector: 'app-text-field-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <text-field
      label="Email"
      description="We'll send the receipt here."
      type="email"
      name="email"
      autocomplete="email"
      placeholder="you@example.com"
      [required]="required"
      (valuechange)="onValuechange($event)"
    ></text-field>
  `,
})
export class TextFieldExample {
  required = true;

  onValuechange(event: Event) {
    console.log('valuechange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuestring""
labelstring""
descriptionstring""
errorstring""
namestring""
typestring"text"
placeholderstring""
autocompletestring""
inputmodestring""
requiredbooleanfalse
disabledbooleanfalse
readonlybooleanfalse
minlengthunknownnull
maxlengthunknownnull
patternstring""
rowsnumber0
Events
EventWhen
valuechangeThe text changed; detail is the new text.

Size

1.7 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.4 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour