ant-design TreeSelect: Add "labelInAriaLive"-property for better accessibility:

yyhrrdl8  于 4个月前  发布在  其他
关注(0)|答案(3)|浏览(43)

What problem does this feature solve?

If the user moves between TreeSelect options using arrow keys, the screenreader will always read out the value of the active node. It would be much better for accessibility (and more flexible), if I as a developer could decide to use labels for aria-live content instead of the values.

What does the proposed API look like?

New prop would be labelInAriaLive , and it would be false by default. This prob would then be used to decide whether to use the value or label of the selected item, when rendering the aria-live tag of the component.

Using the component with the implemented feature:

import React, { useState } from 'react';
import { TreeSelect } from 'antd';

const { TreeNode } = TreeSelect;

const Demo = () => {
  const [value, setValue] = useState(undefined);
  const onChange = () => {
    setValue(value);
  };
  return (
    <TreeSelect
      showSearch
      style={{ width: '100%' }}
      value={value}
      labelInAriaLive={true} // Here's the API change: default would be false
      dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
      placeholder="Please select"
      allowClear
      treeDefaultExpandAll
      onChange={onChange}
    >
      <TreeNode value="parent 1" title="parent 1">
        <TreeNode value="parent 1-0" title="parent 1-0">
          <TreeNode value="leaf1" title="leaf1" />
          <TreeNode value="leaf2" title="leaf2" />
        </TreeNode>
        <TreeNode value="parent 1-1" title="parent 1-1">
          <TreeNode value="leaf3" title={<b style={{ color: '#08c' }}>leaf3</b>} />
        </TreeNode>
      </TreeNode>
    </TreeSelect>
  );
};

export default Demo;
neskvpey

neskvpey2#

From antd\dist\antd.js :

return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_3__["createElement"]("div", {
    onMouseDown: onListMouseDown
  }, activeEntity && open && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_3__["createElement"]("span", {
    style: HIDDEN_STYLE,
    "aria-live": "assertive"
  }, activeEntity.node.value),
  ...

The new prop would control the last row? Instead of reading value a screen reader would read title ? This is very welcome improvement to accessibility as title is often more meaningful than value (usually some kind of ID, key, or hash).

oymdgrw7

oymdgrw73#

Looks like this feature needs to be implemented in rc-treeselect. I made a feature-request there: react-component/tree-select#412

相关问题