super-input
A lightweight element that wraps and upgrades the native <input> element.
Features
- Live text formatting e.g. phone numbers, dates, SSNs
- Custom, native validity messages uses the browser's built-in validation UI to show your message
- Auto-labeling it stitches a sibling
<label>to the<input>viaid/for - Progressively enhanced Does not replace the native input; it enhances it. Everything you know
about
<input>still applies. - Range slider ships with upgraded slider styling and functionality
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/super-input@0.1.5/dist/index.umd.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@excom/super-input@0.1.5/dist/index.css">npm install @excom/super-input<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/super-input"></script>
<link rel="stylesheet" href="/node_modules/@excom/super-input">import "@excom/super-input";@import "@excom/super-input/index.css";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
Wrap a native <input> and optionally a <label>. Nothing else is required.
API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
super-input
Attributes (5)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
auto-label
id on the <input> and associates the <label>.
autoLabel
boolean
falseinvalid-message
setCustomValidity() when the native invalid event fires, and cleared on the next keydown. Makes built-in HTML validation surface a custom message.
invalidMessage
string
nullreflect-value
current-value attribute so CSS and selectors can respond to it. Off by default because reflecting every keystroke is not free.
reflectValue
boolean
falsetext-format
x for any digit and any other character as a literal. Examples: (xxx) xxx-xxxx, xx/xx/xxxx, xxx-xx-xxxx. When set, the input value is live-formatted on every keystroke.
textFormat
string
nullcurrent-value
<input>'s value when reflect-value is set. Read-only from the app's point of view — writing it does not change the input.
currentValue
string
nullProvision (0)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events (0)
e.preventDefault() is not
synchronously called on the event.
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements (2)
Child or descendant elements are recognized by super-input and relevant to its functionality.<input> to enhance.
<label>. When auto-label is set, its for attribute is linked to the input's id.
Styles (26)
.raisedclass="raised" on <super-input> wrapping a text-like <input>.all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
--super-input-accent<color>var(--super-input-primary, blue)--super-input-bg<color>var(--v-form-element-background-color, transparent)--super-input-border-color<color>var( --v-form-element-border-color, currentColor )--super-input-border-radius<length>var(--v-border-radius, 4px)--super-input-border-width<length>var(--v-border-width, 1px)--super-input-color<color>var(--v-color, inherit)--super-input-focus-color<color>var( --v-form-element-focus-color, var(--super-input-border-color) )--super-input-font-size<length>16px--super-input-font-weight<number> | <integer>700--super-input-height<length>calc(var(--super-input-thumb-size) + 36px)--super-input-label-height<length>calc( var(--v-line-height, 1.5) * var(--super-input-font-size) )--super-input-label-margin-bottom<length>calc(21px * 0.375)--super-input-max<number>100--super-input-min<number>0--super-input-primary<color>var(--v-primary, blue)--super-input-thumb-color<color>var( --v-range-thumb-color, var(--super-input-bg) )--super-input-thumb-size<length>44px--super-input-track-height<length>2px--super-input-transition-duration<time>var(--v-transition-duration-fast, 0.15s)--super-input-transition-ease*var(--v-transition-ease-out, ease-out)--super-input-value<number>50--super-input-width<length> | <percentage>100%@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
:--super-inputsuper-input, .tag-super-input:--super-input--has-current-value[current-value], [data-current-value]:--super-input--has-reflect-value[reflect-value], [data-reflect-value]Release notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
e.preventDefault() is not
synchronously called on the event.
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
Examples
Formatting input as the user types
Set text-format to a template using x as a character placeholder.
Common templates:
- Phone (US):
(xxx) xxx-xxxx - Date:
xx/xx/xxxx - SSN:
xxx-xx-xxxx
The wrapped <input> sees the formatted value. Pair with pattern for
validation.
Custom validity messages
Set invalid-message and the browser's native validation UI will surface it
when the input fails. Use the native pattern, required, min, max, etc for validation.
Try submitting the form in the demo below with an invalid phone number.
The message is installed via setCustomValidity() on the invalid event and
cleared on the next keydown, so the input stops being marked invalid as
soon as the user tries again.
Using reflect-value
The reflect-value attribute has two primary uses:
- Is required for animating
raisedlabels without an inputplaceholderattribute - Allows you to hook into it to run your own behaviors
Here's an example with a raising label that will display an error if the user has not entered an email with an @ or . characters.
Range slider
<super-input> ships with advanced slider CSS. Add [type="range"] to the input. [reflect-value] is required for this to work natively in Chromium browsers. Safari and Firefox will need some help via Quark or JS until they support the CSS type() function. You must also set the min/max CSS variables to match the min/max on the input.
Be cautious using this feature, as it aesthetically relies on non-standard pseudo elements for the time being.