Skip to main content

Input Component

Figma

The glu-input component is a composite input field that supports a wide range of features, including an optional label, error messages, helper text, and prefix/suffix elements. It handles various input types such as text, currency, phone, password, date, url, search, and number. In addition, the component can be set to error, disabled, or read-only states, and it forwards any extra attributes to the underlying native <input> element. It also emits events like glChange, glFocus, and glBlur based on user interactions.

Basic Usage

Example 1: Simple Input

Result
Loading...
Live Editor
<glu-input
  label="Name"
  placeholder="Enter your name"
  helperText="This is your full name"
></glu-input>

Input with Prefix and Suffix

The component supports prefix and suffix elements that adapt based on the input type or custom properties. For example, a currency input displays a "$" prefix, a search input shows a magnifying glass icon and, if text is entered, a clear icon appears; while password inputs offer a toggle icon for visibility.

Result
Loading...
Live Editor
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
  <glu-input
    label="Amount"
    type="currency"
    placeholder="0.00"
  ></glu-input>

  <glu-input
    label="Search"
    type="search"
    placeholder="Search..."
    showClearIcon
  ></glu-input>
</div>

Error and Helper Text

If an error message is provided, the component enters an error state and displays a default error icon alongside the error text. Alternatively, you can display additional helper text below the input.

Result
Loading...
Live Editor
<glu-input
  label="Email"
  error="Invalid email address"
  helperIcon="error-icon"
  placeholder="Enter your email"
></glu-input>

Special Input Types

Password Input with Toggle

For password fields, clicking the suffix icon toggles the visibility of the password.

Result
Loading...
Live Editor
<glu-input
  label="Password"
  type="password"
  placeholder="Enter your password"
></glu-input>

Advanced Examples

Example 5: Disabled and Read-Only Inputs

Demonstrate inputs in disabled and read-only states.

Result
Loading...
Live Editor
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
  <glu-input
    label="Disabled Input"
    placeholder="Cannot type here"
    disabled
  ></glu-input>

  <glu-input
    label="Read-Only Input"
    placeholder="Read-only text"
    readOnly
    value="This is fixed"
  ></glu-input>
</div>

Example 6: Input with Both Prefix and Suffix Text

Combine prefix and suffix text to create inputs with additional context.

Result
Loading...
Live Editor
<glu-input
  label="Website"
  type="url"
  placeholder="your-site"
></glu-input>

Example 7: Phone Input

Showcase a phone input field with an appropriate prefix icon.

Result
Loading...
Live Editor
<glu-input
  label="Phone"
  type="phone"
  placeholder="(123) 456-7890"
></glu-input>

Example 8: Date Input with Picker

Utilize the date input type to trigger a date picker.

Result
Loading...
Live Editor
<glu-input
  label="Date of Birth"
  type="date"
  placeholder="YYYY-MM-DD"
></glu-input>

Example 9: Search Input with Clear Icon

A dedicated search input that displays a clear icon when text is entered.

Result
Loading...
Live Editor
<glu-input
  type="search"
  placeholder="Search for items..."
  showClearIcon
></glu-input>

Properties

PropertyAttributeDescriptionTypeDefault
disableddisabledDisables the input field, preventing user interaction.booleanfalse
errorerrorThe error message to display below the input. When non-empty, the component enters an error state and a default error icon is used.stringundefined
helperIconhelper-iconThe name of the helper icon displayed alongside the helper text. If an error exists, a default error icon is shown instead.stringundefined
helperIconVarianthelper-icon-variantSpecifies the visual variant for the helper icon. Allowed values: 'solid' or 'outline'."outline" | "solid"'outline'
helperTexthelper-textSupplemental helper text displayed below the input.stringundefined
isErroris-errorRenders the input with error styling when true.booleanfalse
labellabelOptional label text displayed above the input field.stringundefined
placeholderplaceholderPlaceholder text displayed when the input field is empty.stringundefined
prefixIconprefix-iconThe name of the prefix icon displayed on the left side of the input.stringundefined
prefixIconVariantprefix-icon-variantDefines the visual variant for the prefix icon. Allowed values: 'solid' or 'outline'."outline" | "solid"'outline'
prefixTextprefix-textOptional text displayed as a prefix adjacent to the input field.stringundefined
readOnlyread-onlyRenders the input field in read-only mode, allowing focus and selection but preventing edits.booleanfalse
showClearIconshow-clear-iconWhen true and the input type is 'search', displays a clear icon to reset the input.booleanfalse
suffixIconsuffix-iconThe name of the suffix icon displayed on the right side of the input.stringundefined
suffixIconVariantsuffix-icon-variantDefines the visual variant for the suffix icon. Allowed values: 'solid' or 'outline'."outline" | "solid"'outline'
suffixTextsuffix-textOptional text displayed as a suffix adjacent to the input field.stringundefined
typetypeDetermines the type of the input field. Supported types include 'generic', 'currency', 'phone', 'password', 'date', 'url', 'search', 'number' or any valid InputType. This setting affects both the native input type and UI behavior.InputType | "currency" | "phone"'text'
valuevalueThe current value of the input field. This property is mutable to support two-way binding.anyundefined

Events

EventDescriptionType
glBlurEmitted when the input value changes.CustomEvent<FocusEvent>
glChangeEmitted when the input value changes.CustomEvent<InputChangeEventDetail>
glFocusEmitted when the input element gains focus.CustomEvent<FocusEvent>

Dependencies

Depends on

Graph


Built with StencilJS