File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ const TextField = React.forwardRef(
2929 helper,
3030 variant = 'normal' ,
3131 size = 'default' ,
32+ labelSrOnly = false ,
3233 tag : Tag = 'div' ,
3334 ...inputProps
3435 } ,
@@ -62,7 +63,12 @@ const TextField = React.forwardRef(
6263 . from ( styles ) }
6364 { ...inputProps }
6465 />
65- < label htmlFor = { controlId } > { label } </ label >
66+ < label
67+ htmlFor = { controlId }
68+ className = { classNames . use ( labelSrOnly && 'sr-only' ) }
69+ >
70+ { label }
71+ </ label >
6672 < span id = { `${ id } -helper` } className = { styles . helper } >
6773 { helper }
6874 </ span >
@@ -76,6 +82,10 @@ TextField.propTypes = {
7682 * Label for the text field
7783 */
7884 label : PropTypes . node . isRequired ,
85+ /**
86+ * Hide label and expose it only for screen readers
87+ */
88+ labelSrOnly : PropTypes . bool ,
7989 /**
8090 * Size variation. Affects height only.
8191 */
Original file line number Diff line number Diff line change @@ -77,6 +77,19 @@ Example with disabled input:
7777/ >
7878```
7979
80+ Example with hidden label:
81+
82+ ``` jsx
83+ < TextField
84+ id= " hidden-label"
85+ name= " hidden-label"
86+ label= " Input with hidden label"
87+ labelSrOnly
88+ value= " Hidden label"
89+ variant= " success"
90+ / >
91+ ```
92+
8093### Size variations
8194
8295#### Small
You can’t perform that action at this time.
0 commit comments