Merge pull request #728 from vector-im/dbkr/aria-describedby
Add aria-describedby associations
This commit is contained in:
		
				commit
				
					
						85b02a3589
					
				
			
		
					 1 changed files with 10 additions and 2 deletions
				
			
		| 
						 | 
					@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
 | 
				
			||||||
limitations under the License.
 | 
					limitations under the License.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import React, { ChangeEvent, FC, forwardRef, ReactNode } from "react";
 | 
					import React, { ChangeEvent, FC, forwardRef, ReactNode, useId } from "react";
 | 
				
			||||||
import classNames from "classnames";
 | 
					import classNames from "classnames";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import styles from "./Input.module.css";
 | 
					import styles from "./Input.module.css";
 | 
				
			||||||
| 
						 | 
					@ -96,6 +96,8 @@ export const InputField = forwardRef<
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    ref
 | 
					    ref
 | 
				
			||||||
  ) => {
 | 
					  ) => {
 | 
				
			||||||
 | 
					    const descriptionId = useId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <Field
 | 
					      <Field
 | 
				
			||||||
        className={classNames(
 | 
					        className={classNames(
 | 
				
			||||||
| 
						 | 
					@ -113,6 +115,7 @@ export const InputField = forwardRef<
 | 
				
			||||||
            id={id}
 | 
					            id={id}
 | 
				
			||||||
            ref={ref as React.ForwardedRef<HTMLTextAreaElement>}
 | 
					            ref={ref as React.ForwardedRef<HTMLTextAreaElement>}
 | 
				
			||||||
            disabled={disabled}
 | 
					            disabled={disabled}
 | 
				
			||||||
 | 
					            aria-describedby={descriptionId}
 | 
				
			||||||
            {...rest}
 | 
					            {...rest}
 | 
				
			||||||
          />
 | 
					          />
 | 
				
			||||||
        ) : (
 | 
					        ) : (
 | 
				
			||||||
| 
						 | 
					@ -122,6 +125,7 @@ export const InputField = forwardRef<
 | 
				
			||||||
            type={type}
 | 
					            type={type}
 | 
				
			||||||
            checked={checked}
 | 
					            checked={checked}
 | 
				
			||||||
            disabled={disabled}
 | 
					            disabled={disabled}
 | 
				
			||||||
 | 
					            aria-describedby={descriptionId}
 | 
				
			||||||
            {...rest}
 | 
					            {...rest}
 | 
				
			||||||
          />
 | 
					          />
 | 
				
			||||||
        )}
 | 
					        )}
 | 
				
			||||||
| 
						 | 
					@ -135,7 +139,11 @@ export const InputField = forwardRef<
 | 
				
			||||||
          {label}
 | 
					          {label}
 | 
				
			||||||
        </label>
 | 
					        </label>
 | 
				
			||||||
        {suffix && <span>{suffix}</span>}
 | 
					        {suffix && <span>{suffix}</span>}
 | 
				
			||||||
        {description && <p className={styles.description}>{description}</p>}
 | 
					        {description && (
 | 
				
			||||||
 | 
					          <p id={descriptionId} className={styles.description}>
 | 
				
			||||||
 | 
					            {description}
 | 
				
			||||||
 | 
					          </p>
 | 
				
			||||||
 | 
					        )}
 | 
				
			||||||
      </Field>
 | 
					      </Field>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue