Inputs / Form Inputs - 图1

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:

  • **ListInput** / **F7ListInput** - list item input element
  • **Input** / **F7Input** - input element
  • **Label** / **F7Label** - input label element

Since Framework7 3.5.0 it is highly recommended that you only use **ListInput** component. It combines ListItem, Label and Input components in one component and provides much better and more correct input’s state handling.

Input Properties

PropTypeDefaultDescription
<ListInput> properties
idstringWrapping element ID attribute
mediastringList item media image URL
labelstringInput’s label text
inlineLabelbooleanfalseMakes label inline
floatingLabelbooleanfalseEnables floating label (affects MD theme only)
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
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.
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
defaultValuestring
number
Input value, in case of uncontrolled component
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
<Label> properties
floatingbooleanfalseEnables floating label (affects MD theme only)
inlinebooleanfalseMakes label inline
<Input> properties
wrapbooleantrueDefines should the input be wraped with “item-input-wrap” element or not. Must be disabled when using outside of List View
typestringInput type. All default HTML5 input type, and few special ones:
  • textarea - to render textarea element
  • select - to render select element
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.
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
defaultValuestring
number
Input value, in case of uncontrolled component
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

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 when 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

Input Slots

Input React component (<ListInput>) has additional slots for custom elements:

  • **default** - in case of type="select" or type="textarea" - element will be placed inside of select or textarea tags.
  • **info** - element will be inserted into container with info message
  • **error-message** - element will be inserted into container with error message
  • **label** - element will be inserted into container with input’s label
  • **input** - element will be inserted instead of input element (input prop must be also set to false)
  • **root-start** - element will be inserted in the beginning of <li> element
  • **root** / **root-end** - element will be inserted in the end of <li> element
  • **content-start** - element will be inserted in the beginning of <div class="item-content"> element
  • **content** / **content-end** - element will be inserted in the end of <div class="item-content"> element
  • **inner-start** - element will be inserted in the beginning of <div class="item-inner"> element
  • **inner** / **inner-end** - element will be inserted in the end of <div class="item-inner"> element
  • **media** - element will be inserted inside of <div class="item-media"> element

Examples

  1. <BlockTitle>Full Layout / Inline Labels</BlockTitle>
  2. <List inlineLabels noHairlinesMd>
  3. <ListInput
  4. label="Name"
  5. type="text"
  6. placeholder="Your name"
  7. clearButton
  8. >
  9. <Icon icon="demo-list-icon" slot="media"/>
  10. </ListInput>
  11. <ListInput
  12. label="Password"
  13. type="password"
  14. placeholder="Your password"
  15. clearButton
  16. >
  17. <Icon icon="demo-list-icon" slot="media"/>
  18. </ListInput>
  19. <ListInput
  20. label="E-mail"
  21. type="email"
  22. placeholder="Your e-mail"
  23. clearButton
  24. >
  25. <Icon icon="demo-list-icon" slot="media"/>
  26. </ListInput>
  27. <ListInput
  28. label="URL"
  29. type="url"
  30. placeholder="URL"
  31. clearButton
  32. >
  33. <Icon icon="demo-list-icon" slot="media"/>
  34. </ListInput>
  35. <ListInput
  36. label="Phone"
  37. type="tel"
  38. placeholder="Your phone number"
  39. clearButton
  40. >
  41. <Icon icon="demo-list-icon" slot="media"/>
  42. </ListInput>
  43. <ListInput
  44. label="Gender"
  45. type="select"
  46. defaultValue="Male"
  47. placeholder="Please choose..."
  48. >
  49. <Icon icon="demo-list-icon" slot="media"/>
  50. <option value="Male">Male</option>
  51. <option value="Female">Female</option>
  52. </ListInput>
  53. <ListInput
  54. label="Birthday"
  55. type="date"
  56. defaultValue="2014-04-30"
  57. placeholder="Please choose..."
  58. >
  59. <Icon icon="demo-list-icon" slot="media"/>
  60. </ListInput>
  61. <ListInput
  62. label="Date time"
  63. type="datetime-local"
  64. placeholder="Please choose..."
  65. >
  66. <Icon icon="demo-list-icon" slot="media"/>
  67. </ListInput>
  68. <ListInput
  69. label="Range"
  70. input={false}
  71. >
  72. <Icon icon="demo-list-icon" slot="media"/>
  73. <Range slot="input" value={50} min={0} max={100} step={1}/>
  74. </ListInput>
  75. <ListInput
  76. label="Textarea"
  77. type="textarea"
  78. placeholder="Bio"
  79. >
  80. <Icon icon="demo-list-icon" slot="media"/>
  81. </ListInput>
  82. <ListInput
  83. label="Resizable"
  84. type="textarea"
  85. resizable
  86. placeholder="Bio"
  87. >
  88. <Icon icon="demo-list-icon" slot="media"/>
  89. </ListInput>
  90. </List>
  91. <BlockTitle>Full Layout / Stacked Labels</BlockTitle>
  92. <List noHairlinesMd>
  93. <ListInput
  94. label="Name"
  95. type="text"
  96. placeholder="Your name"
  97. clearButton
  98. >
  99. <Icon icon="demo-list-icon" slot="media"/>
  100. </ListInput>
  101. <ListInput
  102. label="Password"
  103. type="password"
  104. placeholder="Your password"
  105. clearButton
  106. >
  107. <Icon icon="demo-list-icon" slot="media"/>
  108. </ListInput>
  109. <ListInput
  110. label="E-mail"
  111. type="email"
  112. placeholder="Your e-mail"
  113. clearButton
  114. >
  115. <Icon icon="demo-list-icon" slot="media"/>
  116. </ListInput>
  117. <ListInput
  118. label="URL"
  119. type="url"
  120. placeholder="URL"
  121. clearButton
  122. >
  123. <Icon icon="demo-list-icon" slot="media"/>
  124. </ListInput>
  125. <ListInput
  126. label="Phone"
  127. type="tel"
  128. placeholder="Your phone number"
  129. clearButton
  130. >
  131. <Icon icon="demo-list-icon" slot="media"/>
  132. </ListInput>
  133. <ListInput
  134. label="Gender"
  135. type="select"
  136. defaultValue="Male"
  137. placeholder="Please choose..."
  138. >
  139. <Icon icon="demo-list-icon" slot="media"/>
  140. <option value="Male">Male</option>
  141. <option value="Female">Female</option>
  142. </ListInput>
  143. <ListInput
  144. label="Birthday"
  145. type="date"
  146. defaultValue="2014-04-30"
  147. placeholder="Please choose..."
  148. >
  149. <Icon icon="demo-list-icon" slot="media"/>
  150. </ListInput>
  151. <ListInput
  152. label="Date time"
  153. type="datetime-local"
  154. placeholder="Please choose..."
  155. >
  156. <Icon icon="demo-list-icon" slot="media"/>
  157. </ListInput>
  158. <ListInput
  159. label="Range"
  160. input={false}
  161. >
  162. <Icon icon="demo-list-icon" slot="media"/>
  163. <Range slot="input" value={50} min={0} max={100} step={1}/>
  164. </ListInput>
  165. <ListInput
  166. label="Textarea"
  167. type="textarea"
  168. placeholder="Bio"
  169. >
  170. <Icon icon="demo-list-icon" slot="media"/>
  171. </ListInput>
  172. <ListInput
  173. label="Resizable"
  174. type="textarea"
  175. resizable
  176. placeholder="Bio"
  177. >
  178. <Icon icon="demo-list-icon" slot="media"/>
  179. </ListInput>
  180. </List>
  181. <BlockTitle>Floating Labels (MD-theme only)</BlockTitle>
  182. <List noHairlinesMd>
  183. <ListInput
  184. label="Name"
  185. floatingLabel
  186. type="text"
  187. placeholder="Your name"
  188. clearButton
  189. >
  190. <Icon icon="demo-list-icon" slot="media"/>
  191. </ListInput>
  192. <ListInput
  193. label="Password"
  194. floatingLabel
  195. type="password"
  196. placeholder="Your password"
  197. clearButton
  198. >
  199. <Icon icon="demo-list-icon" slot="media"/>
  200. </ListInput>
  201. <ListInput
  202. label="E-mail"
  203. floatingLabel
  204. type="email"
  205. placeholder="Your e-mail"
  206. clearButton
  207. >
  208. <Icon icon="demo-list-icon" slot="media"/>
  209. </ListInput>
  210. <ListInput
  211. label="URL"
  212. floatingLabel
  213. type="url"
  214. placeholder="URL"
  215. clearButton
  216. >
  217. <Icon icon="demo-list-icon" slot="media"/>
  218. </ListInput>
  219. <ListInput
  220. label="Phone"
  221. floatingLabel
  222. type="tel"
  223. placeholder="Your phone number"
  224. clearButton
  225. >
  226. <Icon icon="demo-list-icon" slot="media"/>
  227. </ListInput>
  228. <ListInput
  229. label="Resizable"
  230. floatingLabel
  231. type="textarea"
  232. resizable
  233. placeholder="Bio"
  234. >
  235. <Icon icon="demo-list-icon" slot="media"/>
  236. </ListInput>
  237. </List>
  238. <BlockTitle>Validation + Additional Info</BlockTitle>
  239. <List noHairlinesMd>
  240. <ListInput
  241. label="Name"
  242. type="text"
  243. placeholder="Your name"
  244. info="Default validation"
  245. required
  246. validate
  247. clearButton
  248. >
  249. <Icon icon="demo-list-icon" slot="media"/>
  250. </ListInput>
  251. <ListInput
  252. label="Fruit"
  253. type="text"
  254. placeholder="Type 'apple' or 'banana'"
  255. required
  256. validate
  257. pattern="apple|banana"
  258. clearButton
  259. >
  260. <Icon icon="demo-list-icon" slot="media"/>
  261. <span slot="info">Pattern validation (<b>apple|banana</b>)</span>
  262. </ListInput>
  263. <ListInput
  264. label="E-mail"
  265. type="email"
  266. placeholder="Your e-mail"
  267. info="Default e-mail validation"
  268. required
  269. validate
  270. clearButton
  271. >
  272. <Icon icon="demo-list-icon" slot="media"/>
  273. </ListInput>
  274. <ListInput
  275. label="URL"
  276. type="url"
  277. placeholder="Your URL"
  278. info="Default URL validation"
  279. required
  280. validate
  281. clearButton
  282. >
  283. <Icon icon="demo-list-icon" slot="media"/>
  284. </ListInput>
  285. <ListInput
  286. label="Number"
  287. type="text"
  288. placeholder="Enter number"
  289. info="With custom error message"
  290. errorMessage="Only numbers please!"
  291. required
  292. validate
  293. pattern="[0-9]*"
  294. clearButton
  295. >
  296. <Icon icon="demo-list-icon" slot="media"/>
  297. </ListInput>
  298. </List>
  299. <BlockTitle>Icon + Input</BlockTitle>
  300. <List noHairlinesMd>
  301. <ListInput
  302. type="text"
  303. placeholder="Your name"
  304. clearButton
  305. >
  306. <Icon icon="demo-list-icon" slot="media"/>
  307. </ListInput>
  308. <ListInput
  309. type="password"
  310. placeholder="Your password"
  311. clearButton
  312. >
  313. <Icon icon="demo-list-icon" slot="media"/>
  314. </ListInput>
  315. <ListInput
  316. type="email"
  317. placeholder="Your e-mail"
  318. clearButton
  319. >
  320. <Icon icon="demo-list-icon" slot="media"/>
  321. </ListInput>
  322. <ListInput
  323. type="url"
  324. placeholder="URL"
  325. clearButton
  326. >
  327. <Icon icon="demo-list-icon" slot="media"/>
  328. </ListInput>
  329. </List>
  330. <BlockTitle>Label + Input</BlockTitle>
  331. <List noHairlinesMd>
  332. <ListInput
  333. label="Name"
  334. type="text"
  335. placeholder="Your name"
  336. clearButton
  337. />
  338. <ListInput
  339. label="Password"
  340. type="password"
  341. placeholder="Your password"
  342. clearButton
  343. />
  344. <ListInput
  345. label="E-mail"
  346. type="email"
  347. placeholder="Your e-mail"
  348. clearButton
  349. />
  350. <ListInput
  351. label="URL"
  352. type="url"
  353. placeholder="URL"
  354. clearButton
  355. />
  356. </List>
  357. <BlockTitle>Only Inputs</BlockTitle>
  358. <List noHairlinesMd>
  359. <ListInput
  360. type="text"
  361. placeholder="Your name"
  362. clearButton
  363. />
  364. <ListInput
  365. type="password"
  366. placeholder="Your password"
  367. clearButton
  368. />
  369. <ListInput
  370. type="email"
  371. placeholder="Your e-mail"
  372. clearButton
  373. />
  374. <ListInput
  375. type="url"
  376. placeholder="URL"
  377. clearButton
  378. />
  379. </List>
  380. <BlockTitle>Inputs + Additional Info</BlockTitle>
  381. <List noHairlinesMd>
  382. <ListInput
  383. type="text"
  384. placeholder="Your name"
  385. info="Full name please"
  386. clearButton
  387. />
  388. <ListInput
  389. type="password"
  390. placeholder="Your password"
  391. info="8 characters minimum"
  392. clearButton
  393. />
  394. <ListInput
  395. type="email"
  396. placeholder="Your e-mail"
  397. info="Your work e-mail address"
  398. clearButton
  399. />
  400. <ListInput
  401. type="url"
  402. placeholder="URL"
  403. info="Your website URL"
  404. clearButton
  405. />
  406. </List>
  407. <BlockTitle>Only Inputs Inset</BlockTitle>
  408. <List inset>
  409. <ListInput
  410. type="text"
  411. placeholder="Your name"
  412. clearButton
  413. />
  414. <ListInput
  415. type="password"
  416. placeholder="Your password"
  417. clearButton
  418. />
  419. <ListInput
  420. type="email"
  421. placeholder="Your e-mail"
  422. clearButton
  423. />
  424. <ListInput
  425. type="url"
  426. placeholder="URL"
  427. clearButton
  428. />
  429. </List>