Skip to content

feat: improve a11y #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.storybook
.vscode
*.iml
*.log
.doc/
Expand Down
1 change: 1 addition & 0 deletions src/NodeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ const NodeList = React.forwardRef<NodeListRef, NodeListProps<any>>((props, ref)
itemHeight={itemHeight}
prefixCls={`${prefixCls}-list`}
ref={listRef}
role="tree"
onVisibleChange={originList => {
// The best match is using `fullList` - `originList` = `restList`
// and check the `restList` to see if has the MOTION_KEY node
Expand Down
1 change: 0 additions & 1 deletion src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,6 @@ class Tree<TreeDataType extends DataNode | BasicDataNode = DataNode> extends Rea
}}
>
<div
role="tree"
className={classNames(prefixCls, className, rootClassName, {
[`${prefixCls}-show-line`]: showLine,
[`${prefixCls}-focused`]: focused,
Expand Down
9 changes: 7 additions & 2 deletions src/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
// ====================== Render: Checkbox ======================
// Checkbox
renderCheckbox = () => {
const { checked, halfChecked, disableCheckbox } = this.props;
const { checked, halfChecked, disableCheckbox, title } = this.props;
const {
context: { prefixCls },
} = this.props;
Expand All @@ -374,6 +374,10 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
(disabled || disableCheckbox) && `${prefixCls}-checkbox-disabled`,
)}
onClick={this.onCheck}
role="checkbox"
aria-checked={halfChecked ? 'mixed' : checked}
aria-disabled={disabled || disableCheckbox}
aria-label={`Select ${typeof title === 'string' ? title : 'tree node'}`}
>
{$custom}
</span>
Expand Down Expand Up @@ -545,6 +549,8 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
return (
<div
ref={domRef}
role="treeitem"
aria-expanded={isLeaf ? undefined : expanded}
className={classNames(className, `${prefixCls}-treenode`, {
[`${prefixCls}-treenode-disabled`]: disabled,
[`${prefixCls}-treenode-switcher-${expanded ? 'open' : 'close'}`]: !isLeaf,
Expand All @@ -567,7 +573,6 @@ class InternalTreeNode extends React.Component<InternalTreeNodeProps, TreeNodeSt
style={style}
// Draggable config
draggable={draggableWithoutDisabled}
aria-grabbed={dragging}
onDragStart={draggableWithoutDisabled ? this.onDragStart : undefined}
// Drop config
onDragEnter={mergedDraggable ? this.onDragEnter : undefined}
Expand Down
Loading