• [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

  • 相关阅读:
    linux 解压命令
    在xampp集成环境下使用 thinkphp 连接oracle
    输入框实现新闻列表分页显示(一)
    MyEclipse获取注册码
    Oracle数据库创建表空间
    SQL Server之存储过程
    连接Oracle数据库帮助类
    Oracle数据库的导入和导出
    创建dml触发器
    java连接数据库步骤
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12617266.html
Copyright © 2020-2023  润新知