Skip to content

Forms and inputs ​

<input>, <textarea> and <button> are native controls that lay out and style like their HTML counterparts.

html
<form class="signup">
  <fieldset>
    <legend>Account</legend>
    <label>Email</label>
    <input type="email" name="email" placeholder="you@example.com" />
    <label>Password</label>
    <input type="password" name="password" />
  </fieldset>
  <label><input type="checkbox" name="terms" /> I accept the terms</label>
  <button class="primary">Create account</button>
</form>

Input types ​

type defaults to text and can change at runtime. Every HTML type is accepted on iOS, Android and Windows:

TypeRenders as
text, searchSingle-line text field. search shows the search key on the keyboard.
email, url, tel, numberText field with the matching keyboard. On Windows, number is a number box.
passwordMasked text field.
time, datetime-local, month, weekText field with a date/time keyboard on Android, a plain text field on iOS. On Windows, time is a time picker.
dateNative date picker.
checkbox, radioNative check box and radio button.
rangeNative slider.
colorColour well that opens the system colour picker.
fileButton that opens the system file picker. accept (default */*) filters types, multiple allows several files.
button, submit, resetPush button; value is its label.

Text-like inputs and buttons are inline-block and draw default field or button chrome (padding, border, radius) that your CSS overrides.

Properties ​

PropertyMeaning
valueAlways a string, as on the web; setting null clears it. Setting the value the field already holds does nothing, so a framework that writes value back on every keystroke does not move the caret.
defaultValueThe initial value. It sets value until the user or code changes the field.
placeholderHint text. Colour it with placeholder-color (or a ::placeholder { color } rule).
checkedCheckbox and radio state.
nameFor radios, the group: checking one radio unchecks the other loaded radios with the same name.
valueAsNumber, valueAsDateNumeric and date views of the value, for range, number, date and similar types.
accept, multipleFile inputs.

WARNING

There is no disabled property yet, and no readonly, min, max or step. The disabled attribute in innerHTML disables <input>, <textarea> and <button> on every platform. On iOS and Android, setting core's isEnabled to false does the same.

Styling checkboxes and radios ​

:checked matches a checked checkbox or radio, whether code or a tap changed it:

css
.check:checked { background-color: #3d5afe; }

appearance: none removes the native control, so the element draws only its CSS box (background, border, radius) at its CSS size. Combined with :checked, that builds a fully custom control:

css
.toggle {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #888;
  border-radius: 4px;
}
.toggle:checked { background-color: #3d5afe; border-color: #3d5afe; }

Any other appearance value keeps the native control.

textarea ​

A multi-line field with value, defaultValue, placeholder, name, rows (default 2), cols (default 20) and maxLength (default -1, no limit). rows and cols give its intrinsic size; CSS width and height override them.

html
<textarea rows="4" placeholder="What happened?"></textarea>

Events ​

EventWhen
inputThe value changed: every keystroke, slider move, toggle, ...
beforeinputBefore an edit is applied (typing, paste, cut, a slider move). Call preventDefault() to reject it.
changeThe user committed a change: toggled a checkbox, picked a date, colour or file, released a slider.
focus, blurA text field gained or lost focus.
textChangeFired with every input, with value on the event, for code written against core's TextField.
ts
input.addEventListener('input', () => console.log(input.value));
checkbox.addEventListener('change', () => console.log(checkbox.checked));

form, fieldset, legend and label ​

These are block and phrasing elements for structure and styling only:

  • <form> does not submit, and type="submit" / type="reset" inputs do not act on it. Handle the button's click (or tap) and read your inputs.
  • <fieldset> and <legend> have no default border or legend placement.
  • <label> is inline text; it does not support for and tapping it does not focus or toggle an input.

Released under the Apache 2.0 License.