Skip to main content

TextField

Example

import { useState } from 'react';
import TextField from '@mavvy/m3-ui/TextField';

export function Example() {
const [value, setValue] = useState('');

const handleChange = (val) => {
setValue(val);
};

return (
<div className="flex w-full gap-x-10">
<div className="flex flex-col w-full gap-y-1.5">
<TextField
variant="filled"
icon="fullscreen"
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
size="small"
showClearButton
error={!value}
/>
<TextField
variant="filled"
value={value}
type="email"
placeholder="Place email here"
onChange={handleChange}
supportingText="Supporting Text"
prefix="wt"
suffix="kg"
showClearButton
error={!value}
/>
<TextField
variant="filled"
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
supportingText="Supporting Text"
prefix="php"
/>
<TextField
variant="filled"
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
supportingText="Supporting Text"
showClearButton
error={!value}
/>
<TextField
variant="filled"
value={value}
label="Email"
type="email"
onChange={handleChange}
contentClassName="!h-52"
multiple
error={!value}
/>

<TextField
variant="filled"
value="a@a.com"
label="Email"
type="email"
onChange={handleChange}
disabled
/>
</div>
<div className="flex flex-col w-full gap-y-1.5">
<TextField
icon="fullscreen"
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
size="small"
showClearButton
error={!value}
/>
<TextField
icon="email"
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
supportingText="Supporting Text"
prefix="$"
suffix="kg"
showClearButton
/>
<TextField
prefix="st"
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
supportingText="Supporting Text"
/>
<TextField
value={value}
label="Email"
type="email"
placeholder="Place email here"
onChange={handleChange}
supportingText="Supporting Text"
showClearButton
error={!value}
/>
<TextField
value={value}
label="Email"
type="email"
onChange={handleChange}
contentClassName="!h-52"
multiple
/>

<TextField
value="a@a.com"
label="Email"
type="email"
onChange={handleChange}
disabled
/>
</div>
</div>
);
}
fullscreen
error
wt
error
kg

Supporting Text

php

Supporting Text

error

Supporting Text

error
fullscreen
error
email
$
kg

Supporting Text

st

Supporting Text

error

Supporting Text

Props

proptypedescription
onChange(value: string|number|boolean) => voidrequired. onChange handler
labelstringtextfield label
valuestring|number|booleanvalue of the textfield
typestringHTMLInputTypeAttribute
attrsObjecthtml attributes for the input element
onKeyDown(event) => voidonKeyDown event handler
onKeyUp(event) => voidonKeyUp event handler
onFocus(event) => voidonFocus event handler
onBlur(event) => voidonBlur event handler
classNamestringclassName of the Textfield component
contentClassNamestringclassName of the container component of the input element
inputClassNamestringclassName of the input element
labelClassNamestringclassName of the label
variantoutlined|fileldTextfield variant
colorcolorcomponent color
disabledbooleanif true, component will be disabled
multiplebooleanfor input type file to handle multiple selection
placeholderstringplaceholder of the input element
iconstringicon to display
iconVariantIcon Variantvariant of the icon
iconClassNamestringclassName of the Icon component
sizeSizesize of the Textfield component
errorbooleanif true, shows an error state
supportingTextstringsupporting text below the input element
supportingTextClassNamestringclassName of the supportingText Text Component
showClearButtonbooleanif true, shows a clear button
clearIconClassNamestringclassName of the Clear IconButton
trailingIconstringicon name of the trailing icon
onClear(value: string|number|boolean) => voidon clear handler
outlineClassNamestringclassName of the outline component
prefixstringrender a prefix text
suffixstringrender a suffix text
FieldComponentFunctionRender a Field component aside from the input element
optionsanypass the options to the FieldComponent
endAdornment(props: {focused:boolean}) => JSX Componentend Adornment to render
startAdornmentRaect.ReactNodestart Adornment to render