zoukankan      html  css  js  c++  java
  • [ARIA] Read error message for the focused form field by using aria-describedby

    Labeling inputs, elements, and widgets add context and clarity for assistive technology such as screen readers. Beyond adding accessible labels to elements and widgets we can also provide additional descriptions. Similar to how an aria-labelledby attribute works, an aria-describedby attribute can link the text from another element or elements to be used as a description for the given element.

    Some example use cases for using an aria-describedby are:

    • providing instructions
    • providing important usage details

    First we can add 'id' for the error message

    // src/primitives/FormInput.js
    const helperId = helperText ? `${name}-helper` : ''
    const errorId = errorText && !isValid ? `${id}-error` : ''
    ..
    // src/primitives/FormInput.js
    {
      helperText && (
        <small id={helperId} className="form-text text-muted helper-text">
          {helperText}
        </small>
      )
    }
    
    ..
    
    {
      errorText && (
        <div id={errorId} className="invalid-feedback">
          {errorText}
        </div>
      )
    }

    Then for the input field, we can use aira-describedby

    // src/primitives/FormInput.js
    <input
      id={id}
      type={type}
      name={name}
      className={inputClasses}
      onChange={onChange}
      aria-describedby={`${helperId} ${errorId}`}
    />

    All code in React syntax

  • 相关阅读:
    检查型异常(Checked Exception)与非检查型异常(Unchecked Exception)
    maven跳过单元测试-maven.test.skip和skipTests的区别
    java JFR
    Docker常用命令
    关键字group by 、 Having的 用法
    css特效
    sql
    初识Hibernate之理解持久化类
    Hibernate 搭建
    基本 SQL 之增删改查
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12617266.html
Copyright © 2011-2022 走看看