Inputs Single and multiline text fields.
Table of contents
Usage guidelines
When to use
- Inputs should be used when there is a need for freeform text. If there are heavy restrictions on allowed content, consider using a control (radio, select, checkbox, or switch) instead.
How to use
- All inputs should have labels associated with them.
- The
<label>
element should be the first child of the<res-input>
. - You can optionally include placeholder text that includes non-critical guidance or an example of good input.
- Placeholder text can be added using the native
placeholder
attribute on the<input type="text">
. - Consider using helper text and tooltips to provide contextual information or guidance where needed. When relevant, consider linking to relevant documentation.
- Helper text can be added by inserting an element with an attribute of
slot="help"
after the native input element. - All labels, placeholders, helper text, and tooltips should be in sentence case.
Accessibility
- Placeholder text isn’t always visible and may be inaccessible on screenreaders. It should contain only additional, optional information that reinforces the label rather than replaces it.
Content guidelines
- Input labels should be nouns (e.g., Dek, Caption, Tags, Keyname).
- If the input’s purpose or behavior isn’t immediately clear from the label, include a tooltip to explain how it works.
- Do not repeat the label as placeholder text. Only use placeholder text if it helps people understand how to format their text.
- Example from embeds:
- Input label: Embed URL
- Placeholder text: https://youtu.be/KaOC9danxNo
- Tooltip text: Paste the link to a Tweet, Instagram, YouTube or other embed.
- Example from embeds:
Variations
Helper text
Use helper text to communicate additional information required for someone to properly use the input. For instance, required characters for password fields.
To use helper text, add an element with the attribute slot="help"
.
Character Count
Use a character count when there are a maximum number of characters that can be inserted.
To add a character count, add the count
attribute (and a number) directly to the res-input
element.
Inner slot
Use an inner slot when a descriptive icon needs to be added to the form field for better context.
To use inner slots, add the slot="inner-left"
or slot="inner-right"
attribute directly to a res-icon
element inside of the input component.
Outer slot
Use an outer slot when a button needs to be appended to a form field.
To use outer slots, add the slot="outer-left"
or slot="outer-right"
attribute directly to a res-button
element inside of the input component.
Inner and outer slots
Use both inner and outer slots together for more complex fields that need both actionable buttons and contextual icons.
Attributes
An asterisk next to a value denotes that it is the default value for that attribute. Unless noted otherwise, attributes should be added to the component element directly. Boolean attributes work based on their presence or absence from the component.
<res-component booleanAttribute stringAttribute="parameter">
<child-element></child-element>
</res-component>
Attribute | Type | Description |
---|---|---|
count | integer | Set character limit and show counter |
disabled | boolean | Set initial state to disabled |
error | string | Set error state along with message |
info | string | Set info state along with message |
required | boolean | Set required state |
block | boolean | Set input to block display |
use-as-res-input | boolean | Used to set a non-input child element as the input (e.g. contentEditable divs) |
API
Name | Type | Data | Description |
---|---|---|---|
disabled | property | boolean | Get/set disabled state |
required | property | boolean | Get/set required state |
error | property | string | Get/set error state (pass string to set message) |
info | property | string | Get/set info state (pass string to set message) |
count | property | integer | Get/set character limit (pass false to remove limit) |
Slots
Slot | Desc | Accepts |
---|---|---|
help | Help text for input | |
inner-left | Places an icon inside input on left side | res-icon |
inner-right | Places an icon inside input on right side | res-icon |
outer-left | Places a button next on left side of input | res-button |
outer-right | Places a button next on right side of input | res-button |
Notes
Depends on:Required DOM
Without these, the component will throw an error on render.
<input|textarea>
- Input element
Supported optional DOM
If added as children, these elements will receive specific styles and/or functionality.
<label>
- Label element
History
Version | Note |
---|---|
0.25.3 | Adds ability to add a res-select to the outer right slot |
0.21.4 | Adds variable fallbacks that satisfy updated linting rules, package upgrades cause CSS build to remove -moz-appearance property |
0.19.0 | Adds info attribute, which renders information below the input |
0.18.0 | Add min-width to icons inside inputs and error text so that they don't shrink, remove forced capitalization of input error text |
0.15.6 | Remove the inputSelector attribute from res-input in favor of using use-as-res-input attribute on the non-input element. |
0.15.5 | Add res-icon hover style (via hover attribute). Replace faux-input with inputSelector attribute for passing allowable selectors. |
0.15.0 | Add block attribute and increase line height for labels, textarea, and help text. Add faux-input attribute to allow usage of Quill div with contenteditable . |
0.14.0 | Add required attribute. |
0.12.0 | Apply new spacing scale. Remove 'smallest' size attribute from warning icons in error messages. |
0.11.0 | Tweaks to accommodate new icon set. |
0.10.0 | Color update |
0.7.0 | Web component refactor. First component to use psuedo-slots. Removed clear attribute. |
0.5.0 | Total refactor! Accepts all input types now. API much thinner since the input is fully customizable. Added clear attribute. |
0.4.0 | Allow error messages to be set via attribute. Update API to allow strings on set. Refactor how help messages, error messages, and character counts are styled. |
0.3.0 | Darker input text color. |
0.2.0 | Consistent padding to match other elements. |
0.1.0 | Initial build to spec. |