Input / Form Elements React Components

Form elements allow you to create flexible and beautiful Form layout. Form elements are just well known List View (List and List Item React components) but with few additional components.

Check out Framework7's Inputs / Form Elements for their appearance.

Input Components

There are following components included:

Input Properties

PropTypeDefaultDescription
<ListInput> properties
mediastringList item media image URL
labelstringInput's label text
floatingLabelbooleanfalseEnables floating label
outlinebooleanfalseMakes input outline
inputbooleantrueWhether it should render input element or not. Disable if you want to use custom input inside.
typestringInput type. All default HTML5 input type, and few special ones:
  • textarea - to render textarea element
  • select - to render select element
  • datepicker - to open Calendar on input focus
  • colorpicker - to open Color Picker on input focus
  • texteditor - to open Text Editor on input focus
resizablebooleanfalseMakes textarea resizable
inputStyleobjectValue of input's "style" attribute, in case you need to pass extra styles
clearButtonbooleanfalseAdds input clear button that will clear input value on click
validatebooleanfalseWhen enabled then input value will be validated on change based on passed "pattern" or based on input type. If you use custom validation and need more control on where to show/hide error message, then it is better to disable validation and use error-message together with error-message-force props.
validateOnBlurbooleanfalseWhen enabled then input will be validated on blur only.
onValidatefunctionCallback to be executed on input validation, returns boolean value indication whether the input is valid or not.
<ListInput
  type="email"
  validate
  :onValidate={(isValid) => setInputValid(isValid)}
/>
errorMessagestringCustom error message to show when input value is invalid
errorMessageForcebooleanfalseForce error message to force. Useful in case you use custom validation and want to show/hide error message when you need it
infostringCustom additional text with information about input
namestringInput name
placeholderstringInput placeholder
idstringWrapping element ID attribute
inputIdstringInput element ID attribute
valuestring
number

Input value.

If type="datepicker" then value must be passed as what Calendar accepts - Array with dates, for example value={[new Date()]}

If type="colorpicker" then value must be passed as what Color Picker accepts - Object with colors, for example value={{hex: '#ff0000'}}

If type="texteditor" then value should be HTML string

defaultValuestring
number
Input value, in case of uncontrolled component
inputmodestringValue of input's native "inputmode" attribute
sizestring
number
Value of input's native "size" attribute
patternstringValue of input's native "pattern" attribute
acceptstring
number
Value of input's native "accept" attribute
autocompletestringValue of input's native "autocomplete" attribute
autofocusbooleanfalseValue of input's native "autofocus" attribute
autosavestringValue of input's native "autosave" attribute
disabledbooleanfalseMarks input as disabled
maxstring
number
Value of input's native "max" attribute
minstring
number
Value of input's native "min" attribute
stepstring
number
Value of input's native "step" attribute
maxlengthstring
number
Value of input's native "maxlength" attribute
minlengthstring
number
Value of input's native "minlength" attribute
multiplebooleanfalseValue of input's native "multiple" attribute
readonlybooleanfalseMarks input as readonly
requiredbooleanfalseMarks input as required
tabindexstring
number
Value of input's native "tabindex" attribute
noStoreDatabooleanfalseAllows to ignore input value to be stored when using with Form Storage
ignoreStoreDatabooleanfalseSame as previous
wrapbooleantrueWhen enabled it will be wrapped in <li> element
calendarParamsobjectObject with Calendar Parameters which is used when type="datepicker"
colorPickerParamsobjectObject with Color Picker Parameters which is used when type="colorpicker"
textEditorParamsobjectObject with Text Editor Parameters which is used when type="texteditor"
<Input> properties
outlinebooleanfalseMakes input outline
wrapbooleantrueDefines should the input be wraped with <div class="input"> element or not.
typestringInput type. All default HTML5 input type, and few special ones:
  • textarea - to render textarea element
  • select - to render select element
  • datepicker - to open Calendar on input focus
  • colorpicker - to open Color Picker on input focus
  • texteditor - to open Text Editor on input focus
resizablebooleanfalseMakes textarea resizable
inputStyleobjectValue of input's "style" attribute, in case you need to pass extra styles
clearButtonbooleanfalseAdds input clear button that will clear input value on click
validatebooleanfalseWhen enabled then input value will be validated on change based on passed "pattern" or based on input type. If you use custom validation and need more control on where to show/hide error message, then it is better to disable validation and use error-message together with error-message-force props.
validateOnBlurbooleanfalseWhen enabled then input will be validated on blur only.
onValidatefunctionCallback to be executed on input validation, returns boolean value indication whether the input is valid or not.
<Input
  type="email"
  validate
  :onValidate={(isValid) => setInputValid(isValid)}
/>
errorMessagestringCustom error message to show when input value is invalid
errorMessageForcebooleanfalseForce error message to force. Useful in case you use custom validation and want to show/hide error message when you need it
infostringCustom additional text with information about input
namestringInput name
placeholderstringInput placeholder
idstringWrapping element ID attribute
inputIdstringInput element ID attribute
valuestring
number

Input value.

If type="datepicker" then value must be passed as what Calendar accepts - Array with dates, for example value={[new Date()]}

If type="colorpicker" then value must be passed as what Color Picker accepts - Object with colors, for example value={{hex: '#ff0000'}}

If type="texteditor" then value should be HTML string

defaultValuestring
number
Input value, in case of uncontrolled component
inputmodestringValue of input's native "inputmode" attribute
sizestring
number
Value of input's native "size" attribute
patternstringValue of input's native "pattern" attribute
acceptstring
number
Value of input's native "accept" attribute
autocompletestringValue of input's native "autocomplete" attribute
autofocusbooleanfalseValue of input's native "autofocus" attribute
autosavestringValue of input's native "autosave" attribute
checkedbooleanfalseMarks input as checked
disabledbooleanfalseMarks input as disabled
maxstring
number
Value of input's native "max" attribute
minstring
number
Value of input's native "min" attribute
stepstring
number
Value of input's native "step" attribute
maxlengthstring
number
Value of input's native "maxlength" attribute
minlengthstring
number
Value of input's native "minlength" attribute
multiplebooleanfalseValue of input's native "multiple" attribute
readonlybooleanfalseMarks input as readonly
requiredbooleanfalseMarks input as required
tabindexstring
number
Value of input's native "tabindex" attribute
noStoreDatabooleanfalseAllows to ignore input value to be stored when using with Form Storage
ignoreStoreDatabooleanfalseSame as previous
calendarParamsobjectObject with Calendar Parameters which is used when type="datepicker"
colorPickerParamsobjectObject with Color Picker Parameters which is used when type="colorpicker"
textEditorParamsobjectObject with Text Editor Parameters which is used when type="texteditor"

Input Events

EventArgumentsDescription
<ListInput>, <Input> events
focus(event)Fired when user focused to input.
blur(event)Fired when user lost focus from input.
input(event)Fired immediately when input value changed. Note: Input event triggers after beforeinput, keypress, keyup, keydown events.
change(event)Fired on blur if value changed.
inputClear(event)Fired when input clear button clicked
textareaResize(event)Fired if resizable textarea resized. event.detail will contain object with the initialHeight, currentHeight and scrollHeight properties
inputEmpty(event)Fired when input value becomes empty
inputNotEmpty(event)Fired when input value becomes not empty
calendarChange(value)Fired when type="datepicker" Calendar value changed. As an argument it receives array with selected dates.
colorPickerChange(value)Fired when type="colorpicker" Color Picker value changed. As an argument it receives object with Color Picker value.
textEditorChange(value)Fired when type="texteditor" Text Editor value changed. As an argument it receives Texteditor value (HTML string).

Input Slots

<ListInput> has additional slots for custom elements:

Examples

inputs.jsx
import React from 'react';
import { Navbar, Page, BlockTitle, List, Icon, ListInput, Range } from 'framework7-react';

export default () => (
  <Page>
    <Navbar title="Form Inputs" />

    <BlockTitle>Full Layout / Stacked Labels</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput label="Name" type="text" placeholder="Your name" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Password" type="password" placeholder="Your password" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="E-mail" type="email" placeholder="Your e-mail" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="URL" type="url" placeholder="URL" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Phone" type="tel" placeholder="Your phone number" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Gender" type="select" defaultValue="Male" placeholder="Please choose...">
        <Icon icon="demo-list-icon" slot="media" />
        <option value="Male">Male</option>
        <option value="Female">Female</option>
      </ListInput>

      <ListInput
        label="Birthday"
        type="date"
        defaultValue="2014-04-30"
        placeholder="Please choose..."
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Date time" type="datetime-local" placeholder="Please choose...">
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Range" input={false}>
        <Icon icon="demo-list-icon" slot="media" />
        <Range slot="input" value={50} min={0} max={100} step={1} />
      </ListInput>

      <ListInput label="Textarea" type="textarea" placeholder="Bio">
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Resizable" type="textarea" resizable placeholder="Bio">
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
    </List>

    <BlockTitle>Floating Labels</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput label="Name" floatingLabel type="text" placeholder="Your name" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput
        label="Password"
        floatingLabel
        type="password"
        placeholder="Your password"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="E-mail" floatingLabel type="email" placeholder="Your e-mail" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="URL" floatingLabel type="url" placeholder="URL" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Phone" floatingLabel type="tel" placeholder="Your phone number" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput label="Resizable" floatingLabel type="textarea" resizable placeholder="Bio">
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
    </List>

    <BlockTitle>Floating Labels + Outline Inputs</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput outline label="Name" floatingLabel type="text" placeholder="Your name" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
      <ListInput
        outline
        label="Password"
        floatingLabel
        type="password"
        placeholder="Your password"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
      <ListInput
        outline
        label="E-mail"
        floatingLabel
        type="email"
        placeholder="Your e-mail"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
      <ListInput outline label="URL" floatingLabel type="url" placeholder="URL" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
      <ListInput
        outline
        label="Phone"
        floatingLabel
        type="tel"
        placeholder="Your phone number"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
      <ListInput
        outline
        label="Bio"
        floatingLabel
        type="textarea"
        resizable
        placeholder="Bio"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
    </List>

    <BlockTitle>Validation + Additional Info</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput
        label="Name"
        type="text"
        placeholder="Your name"
        info="Default validation"
        required
        validate
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput
        label="Fruit"
        type="text"
        placeholder="Type 'apple' or 'banana'"
        required
        validate
        pattern="apple|banana"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
        <span slot="info">
          Pattern validation (<b>apple|banana</b>)
        </span>
      </ListInput>

      <ListInput
        label="E-mail"
        type="email"
        placeholder="Your e-mail"
        info="Default e-mail validation"
        required
        validate
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput
        label="URL"
        type="url"
        placeholder="Your URL"
        info="Default URL validation"
        required
        validate
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput
        label="Number"
        type="text"
        placeholder="Enter number"
        info="With custom error message"
        errorMessage="Only numbers please!"
        required
        validate
        pattern="[0-9]*"
        clearButton
      >
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
    </List>

    <BlockTitle>Icon + Input</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput type="text" placeholder="Your name" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput type="password" placeholder="Your password" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput type="email" placeholder="Your e-mail" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>

      <ListInput type="url" placeholder="URL" clearButton>
        <Icon icon="demo-list-icon" slot="media" />
      </ListInput>
    </List>

    <BlockTitle>Label + Input</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput label="Name" type="text" placeholder="Your name" clearButton />

      <ListInput label="Password" type="password" placeholder="Your password" clearButton />

      <ListInput label="E-mail" type="email" placeholder="Your e-mail" clearButton />

      <ListInput label="URL" type="url" placeholder="URL" clearButton />
    </List>

    <BlockTitle>Only Inputs</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput type="text" placeholder="Your name" clearButton />

      <ListInput type="password" placeholder="Your password" clearButton />

      <ListInput type="email" placeholder="Your e-mail" clearButton />

      <ListInput type="url" placeholder="URL" clearButton />
    </List>

    <BlockTitle>Inputs + Additional Info</BlockTitle>
    <List strongIos dividersIos insetIos>
      <ListInput type="text" placeholder="Your name" info="Full name please" clearButton />

      <ListInput
        type="password"
        placeholder="Your password"
        info="8 characters minimum"
        clearButton
      />

      <ListInput
        type="email"
        placeholder="Your e-mail"
        info="Your work e-mail address"
        clearButton
      />

      <ListInput type="url" placeholder="URL" info="Your website URL" clearButton />
    </List>
  </Page>
);