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/
Text Field Variants
import { TextField } from '@rmwc/textfield';
{}
<TextField label="standard..." helpText="Optional help text."/>
{}
<TextField icon="search" trailingIcon="close" label="icon..." />
{}
<TextField
label="trailingIcon..."
trailingIcon={{
icon: 'close',
onClick: () => console.log('Clear')
}}
/>
{}
<TextField outlined label="outlined..." />
{}
<TextField fullwidth placeholder="fullWidth..."/>
{}
<TextField textarea outlined fullwidth label="textarea..." rows="8"
maxLength={20}
characterCount
helpText={{
persistent: true,
validationMsg: true,
children: 'The field is required'
}}
/>
{}
<TextField disabled label="disabled..." />
{}
<TextField invalid label="Invalid..." value="#@!$" onChange={() => {}}/>
<TextField label="Validate Pattern" pattern="[A-Za-z]{3}"/>
{}
<TextField placeholder="No label"/>
HTML Input Types
A preview of how material-components-web
handles styling input types for your browser.
import { TextField, TextFieldIcon, TextFieldHelperText } from '@rmwc/textfield';
<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"/>
import { Docs } from '@rmwc/base/utils/document-component';
import * as docs from './docgen.json';
<Docs src={docs} components={['TextField', 'TextFieldIcon', 'TextFieldHelperText']} />