Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit e10b3ec

Browse files
RangunaMatt Goo
authored andcommitted
docs(text-field): Add HelperText Validity Usage Docs (#221)
1 parent bc41a8b commit e10b3ec

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/text-field/helper-text/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,39 @@ role | String | Sets role on HTML element.
3030
showToScreenReader | Boolean | toggles the aria-hidden property to allow element to be visible to the screen reader.
3131
validation | Boolean | If true, alters the helper text to an error message.
3232

33+
## Input Validation
34+
35+
HelperText provides validity styling by setting the `validation` prop in HelperText. Validation can be checked through the appropriate `Input` validation properties (pattern, min, max, required, step, minLength, maxLength).
36+
37+
The following snippet is an example of how to use pattern regex and check for minimum length with HelperText:
38+
``` js
39+
import React from 'react';
40+
import TextField, {HelperText, Input} from '@material/react-text-field';
41+
class MyApp extends React.Component {
42+
state = {username: ''};
43+
render() {
44+
return (
45+
<div>
46+
<TextField
47+
box
48+
label='Username'
49+
helperText={
50+
<HelperText validation>Invalid username</HelperText>
51+
}
52+
>
53+
<Input
54+
pattern='^([a-zA-Z_]+[0-9]*)$'
55+
minLength={8}
56+
value={this.state.username}
57+
onChange={(e)=>this.setState({username:e.target.value})}
58+
/>
59+
</TextField>
60+
</div>
61+
);
62+
}
63+
}
64+
```
65+
3366
## Sass Mixins
3467

3568
Sass mixins may be available to customize various aspects of the Components. Please refer to the

0 commit comments

Comments
 (0)