JSPM

@rmwc/textfield

6.0.0-alpha.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1694
  • Score
    100M100P100Q190553F
  • License MIT

RMWC TextField component

Package Exports

  • @rmwc/textfield
  • @rmwc/textfield/README.md

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rmwc/textfield) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Text Fields

Text fields allow users to input, edit, and select text.

  • Module @rmwc/textfield
  • Import styles:
    • import '@material/textfield/dist/mdc.textfield.css'
    • import '@material/floating-label/dist/mdc.floating-label.css'
    • import '@material/notched-outline/dist/mdc.notched-outline.css'
    • import '@material/line-ripple/dist/mdc.line-ripple.css'
  • MDC Docs: https://material.io/develop/web/components/input-controls/text-field/

TextField Variants

<TextField label="standard..." />
<TextField outlined label="outlined..." />
<TextField fullwidth placeholder="fullWidth..." />
<TextField placeholder="No label" />
<>
  {/* Leading and trailing icons can be used.*/}
  <TextField icon="search" trailingIcon="close" label="icon..." />
  {/* If you need full control over the icon, you can pass the icon as options with your own props. Dont forget the TabIndex to make it clickable*/}
  <TextField
    label="trailingIcon..."
    trailingIcon={{
      icon: 'close',
      tabIndex: 0,
      onClick: () => console.log('Clear')
    }}
  />
</>

Textareas

You can make the TextField a textarea. Make sure to include outlined for proper styling You can optionally make help text always visible by passing an object as props with persistent set to true. Textareas can also have an optional character counter which will work with the maxLength property.

<TextField
  textarea
  outlined
  fullwidth
  label="textarea..."
  rows={8}
  maxLength={20}
  characterCount
  helpText={{
    persistent: true,
    validationMsg: true,
    children: 'The field is required'
  }}
/>

Validation

<TextField disabled label="Disabled..." />
<TextField required label="Required..." value="" />
<TextField
  invalid
  label="Invalid..."
  value="#@!$"
  onChange={() => {}}
/>
<TextField label="Validate Pattern" pattern="[A-Za-z]{3}" />

HTML Input Types

A preview of how material-components-web handles styling input types for your browser.

<>
  <TextField label="text" type="text" />
  <TextField label="color" type="color" style={{ width: '6rem' }} />
  <TextField label="date" type="date" />
  <TextField label="datetime-local" type="datetime-local" />
  <TextField label="month" type="month" />
  <TextField label="range" type="range" />
  <TextField label="time" type="time" />
  <TextField label="week" type="week" />
</>

TextField

A TextField component for accepting text input from a user.

Props

Name Type Description
characterCount undefined | false | true Shows the character count, must be used in conjunction with maxLength.
disabled undefined | false | true Makes the Textfield disabled.
fullwidth undefined | false | true Makes the TextField fullwidth.
helpText React.ReactNode | TextFieldHelperTextProps Adds help text to the field
icon RMWC.IconPropT Add a leading icon.
inputRef MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null> | (ref: HTMLInputElement | HTMLTextAreaElement | null) => void A reference to the native input or textarea.
invalid undefined | false | true Makes the TextField visually invalid. This is sometimes automatically applied in cases where required or pattern is used.
label React.ReactNode A label for the input.
outlined undefined | false | true Outline the TextField
required undefined | false | true Makes the Textfield required.
rootProps Object By default, props spread to the input. These props are for the component's root container.
textarea undefined | false | true Makes a multiline TextField.
trailingIcon RMWC.IconPropT Add a trailing icon.
type undefined | string The type of input field to render, search, number, etc
value string | number Sets the value for controlled TextFields.