Allows a user to enter data, edit data and search
Basic input field with label.
Basic input field with label and required tag.
Basic input field with label and optional tag.
Change size for the input field. Default size is medium.
Input field with no label.
Input field with validation that runs on blur
. Error state is controlled with the error
prop. Setting the error
prop to a string will render that message with default error styling. The error
slot can be used to fully customize the error message.
Error messaging will override helper text rendered in the bottom position.
Multiple line input field with expander control in lower right. Note that the pre-icon, post-icon, and info-action slots will not work properly in multi-line inputs.
Input field designed to accept numerical input. Launches the numerical keyboard on mobile devices. Does not use the type="number"
attribute as that is intended for values that are strictly "numbers" such as quantities and not values that contain numerical characters such as credit cards, security codes, month/year values, etc. Can be used in conjunction with input masking to handle formatting values like credit cards, or an input
listener can be used to format or restrict input.
Use the type="number"
attribute only for input fields that reference a numerical value, for example a quantity of something. For input fields that are composed of numerical characters but are not strictly a number value, for example a credit card number or a month/year value, use a numeric input instead. An input field with type="number"
set will only accept pure number values as input and rejects all other content, which can cause issues with a numeric identifier that has leading zeroes and may behave differently across browsers and devices.
Use type="date"
to create input fields which allow users to enter a date, either with a validated text field and/or a simple calendar UI. Note: the presentation is dependent on the browser and largely unchangeable. Use this input field for applications where consistent presentation is less important than the functional benefits.
See the MDN web docs (opens new window) for type="date"
to learn more.
Input field with link text on right. The link should describe its relationship to the input field either through its text content or an aria-label.
Input field with icon wrapped in an actionable element outside the input field on right. The actionable element should have an aria-label that explains it's relationship to the input field and what happens when you click on it.
Input field with helper or hint text below the input field. If the input is in an error state, the error messaging slot will override this text. Helper text should be used instead of the HTML placeholder
attribute to provide additional information or context about the input. Helper text is automatically linked to the input field through the aria-describedby
attribute.
Input field with helper or hint text rendered above the input field. Helper text should be used instead of the HTML placeholder
attribute to provide additional information or context about the input. Helper text is automatically linked to the input field through the aria-describedby
attribute.
Input field with icon inserted into the input field on left. Icon is decorative and not intended for any action.
Input field with icon inserted into the input field on right. Icon is decorative and not intended for any action.
Input field with icon buttons inserted to the right. Up to 2 buttons can be passed into the post-icon
slot. Each button should have the cdr-input__button
utility class applied to it. Each button should indicate it's function and relationship to the input field through either an aria-label
or a tooltip.
This component has compliance with WCAG guidelines by:
label
fieldaria-label
attribute is set to the label
valueThe HTML placeholder
attribute should not be used as it creates an inaccessible experience when the placeholder content disappears as soon as the user begins typing into the input field. Instead the helper-text-top
, helper-text-bottom
, or info
slots should be used to provide any additional information needed to complete the input.
Any additional actionable elements related to the input field, which may be external to the input component or passed in via the info
, info-action
, or post-icon
slots, should indicate their function and relationship to the input field through their text content, and aria-label
, or a tooltip.
CdrInput sets some default attributes to make it easier to construct consistent and accessible forms. These default attributes can be overridden by passing the same attribute to the CdrInput component.
For all CdrInput elements:
spellcheck
is set to false
autocorrect
is set to 'off'
autocapitalize
is set to 'off'
For CdrInput elements with type="number"
set, the following attributes are enabled to help ensure that numeric inputs behave consistently across browsers and devices:
pattern
is set to [0-9]*
, which restrictsnovalidate
is set to true
inputmode
is set to numeric
Note that the maxlength
attribute does not work in conjunction with numeric inputs as they are treated as numbers not strings. Instead, the length can be restricted using either an event listener or the min/max attributes:
<!-- restrict numeric input to 3 characters max with a listener -->
<cdr-input type="number" v-model="default" @input="() => {this.default = this.default.substring(0, 3)}"/>
<!-- restrict numeric input to 3 digit numbers -->
<cdr-input type="number" v-model="default" min="0" max="999"/>
User input should be automatically formatted to make forms easier to comprehend and use, for example by adding parentheses and a dash to a phone number or inserting a space between every four digits of a credit card number.
Input masking has not been integrated directly into Cedar, however the CdrInput component implements the same API as a plain HTML text input element and can be used in conjunction with most input masking libraries.
We recommend using v-mask (opens new window) as a local directive in any components where you need input masking, as it provides a number of benefits:
v-mask
is extremely simple and easy to understandv-mask
API is what we will implement, making it easier for you to migrate in the future<script>
import { CdrInput } from "@rei/cedar";
import { VueMaskDirective } from "v-mask";
export default {
name: "VueDirectiveExample",
components: {
CdrInput,
},
directives: {
mask: VueMaskDirective,
},
data() {
return {
defaultModel: '',
}
}
};
</script>
<template>
<cdr-input
v-model="defaultModel"
type="tel"
v-mask="'(###) ###-####'"
>
</template>
optional
prop on the input will render a text label indicating it is optionalaria-required
This component will bind any attribute that a native HTML input element (opens new window) accepts.
id
name
string
type
auto-generated
default
Requires unique ID that is mapped to the label ‘for’ attribute. If this value is not set, it will be auto-generated.
type
name
string
type
text
default
Supports HTML5 <input> types for text, email, number, password, search, date, and URL.
label
name
string
type
N/A
default
Sets the text value for the input label. Required for a11y compliance. Use ‘hideLabel’ if the label display is not desired. Required.
hideLabel
name
boolean
type
false
default
Visually hides the label element, but leaves it available to screen readers for a11y compliance.
rows
name
number
type
null
default
Sets the number of rows for the input field and converts input field to textarea if the value of the ‘rows’ prop is greater than 1.
disabled
name
boolean
type
false
default
Sets the disabled state for the input field and label styling. Also, restricts user input.
numeric
name
boolean
type
false
default
Sets default attributes for an input that should launch a numeric keyboard but is not strictly a 'number' (credit card, security code, postal code, etc.). Should be used in conjunction with the default text type input. An `input` listener can be used to fully restrict input values to numerical characters only
required
name
boolean
type
false
default
Sets aria-required on the input field and displays an asterisk next to the input label.
optional
name
boolean
type
false
default
Displays '(optional)' text next to the input label.
error
name
boolean
type
false
default
Sets the input to an error state, displays the `error` slot if one is present.
errorRole
name
string
type
status
default
Sets the `role` attribute for the embedded error state messaging.
background
name
string
type
primary
default
Set which background color the input is being rendered on. Adjusts styling to ensure accessibility. Possible options are: { ‘primary’ | ‘secondary’ }.
size
name
string
type
medium
default
Sets the input field size. Possible sizes are: { ‘medium’ | ‘large’ }. Also works with responsive breakpoints. Breakpoint values are: xs, sm, md, and lg. Examples: { 'small' | 'medium' | 'large' | 'large@sm' }
labelClass
name
string
type
N/A
default
VUE 3 ONLY - Add a custom class to the `cdr-label-standalone` div
error
name
Error messaging text that is displayed when the `error` prop is true.
info
name
Location for information link or icon markup to the right above the input field.
info-action
name
Location for icon button rendered to the right outside the input field
pre-icon
name
Location for icon markup to the left inside the input field.
post-icon
name
Location for icon markup to the right inside the input field.
helper-text-bottom
name
Location for helper or information text to the left below the input field.
helper-text-top
name
Location for helper or information text to the left above the input field.
All event listeners are passed through to the <input> element.