# Input `lion-input` component is a webcomponent that enhances the functionality of the native `` element. ```js script import { html } from '@lion/core'; import { MaxLength } from '@lion/form-core'; import { loadDefaultFeedbackMessages } from '@lion/validate-messages'; import { localize } from '@lion/localize'; import './lion-input.js'; export default { title: 'Forms/Input', }; ``` ```js preview-story export const main = () => html` `; ``` ## Features - Based on [field](?path=/docs/forms-system-overview--page) - Extra visual elements can be added via `slots` - **label**: can also be provided via the `label` attribute, but the slot can be used to change the `html` and `CSS` of the label. For example add an `u-sr-only` class to the label to make it visually hidden. A label is always needed for accessibility reasons. - **help-text**: a helper text shown below the label to give extra clarification. - **prefix**: does not have an active use case yet, but the option is in place. - **suffix**: can be used for addons to the input like a calculator, datepicker or addressbook. In these cases a button with an icon is used. - **before**: does not have an active use case yet, but the option is in place. - **after**: can be used to show a currency or percentage. - Delegates attributes like `type`, `disabled`, `placeholder` and `read-only` to the native input. - Can make us of [validation](?path=/docs/forms-validation-overview--main#validate) ## How to use ### Installation ```bash npm i --save @lion/input ``` ```js import '@lion/input/lion-input.js'; ``` ## Examples ### Label Can be provided via the `label` attribute, but the slot can be used to change the `html` and `CSS` of the label. For example add an `u-sr-only` class to the label to make it (partially) visually hidden. A label is always needed for accessibility reasons. ```js preview-story export const label = () => html` `; ``` ### Help-text A helper text shown below the label to give extra clarification. Just like the `label`, a `help-text` can be provided via the `help-text` attribute, a slot can be used to change the `html` and `CSS` of the help-text. For example add an anchor with further explanation. ```js preview-story export const helpText = () => html`
Help text using html
`; ``` ### Prefilled ```js preview-story export const prefilled = () => html` `; ``` ### Read only `readonly` attribute will be delegated to the native `` to make it read-only. This field **will still be included** in the parent fieldset or form's `serializedValue`. ```js preview-story export const readOnly = () => html` `; ``` ### Disabled `disabled` attribute will be delegated to the native `` to make it disabled. This field **will not be included** in the parent fieldset or form's `serializedValue`. ```js preview-story export const disabled = () => html` `; ``` ### Prefix > Prefix slot does not have an active use case yet. ```js preview-story export const prefix = () => html`
[prefix]
`; ``` ### Suffix The suffix can be used for addons to the input like a calculator, datepicker or addressbook. In these cases a button with an icon is used. ```js preview-story export const suffix = () => html`
[suffix]
`; ``` ### Before > Before slot does not have an active use case yet. ```js preview-story export const before = () => html`
[before]
`; ``` ### After ```js preview-story export const after = () => html`
EUR
%
`; ``` ## Using validation The input can be used with [validation](?path=/docs/forms-validation-overview--page). On certain conditions, a feedback message can be shown if the input value is invalid. You can change the locale with the buttons below the field. Our default validators come with default translations already. ```js preview-story export const validation = () => { loadDefaultFeedbackMessages(); return html` `; }; ```