@@ -10,7 +10,7 @@ import TreeNodeInput from './tree-node-input';
10
10
11
11
const { Expand } = Animate ;
12
12
const { bindCtx } = func ;
13
- const { isPromise, pickOthers } = obj ;
13
+ const { isPromise, pickOthers, pickAttrsWith } = obj ;
14
14
const isRoot = pos => / ^ 0 - ( \d ) + $ / . test ( pos ) ;
15
15
16
16
/**
@@ -70,6 +70,7 @@ export default class TreeNode extends Component {
70
70
dragOverGapBottom : PropTypes . bool ,
71
71
parentNode : PropTypes . object ,
72
72
onKeyDown : PropTypes . func ,
73
+ size : PropTypes . number ,
73
74
} ;
74
75
75
76
static defaultProps = {
@@ -78,6 +79,7 @@ export default class TreeNode extends Component {
78
79
disabled : false ,
79
80
checkboxDisabled : false ,
80
81
isLeaf : false ,
82
+ size : 1 ,
81
83
} ;
82
84
83
85
constructor ( props ) {
@@ -378,6 +380,7 @@ export default class TreeNode extends Component {
378
380
< Checkbox
379
381
aria-label = { typeof label === 'string' ? label : null }
380
382
checked = { checked }
383
+ tabIndex = { - 1 }
381
384
indeterminate = { indeterminate }
382
385
disabled = { disabled || checkboxDisabled }
383
386
onChange = { this . handleCheck }
@@ -460,12 +463,14 @@ export default class TreeNode extends Component {
460
463
root,
461
464
pos,
462
465
selected,
466
+ checked,
463
467
disabled,
464
468
expanded,
465
469
dragOver,
466
470
dragOverGapTop,
467
471
dragOverGapBottom,
468
472
_key,
473
+ size,
469
474
} = this . props ;
470
475
const {
471
476
loadData,
@@ -474,9 +479,22 @@ export default class TreeNode extends Component {
474
479
draggable : rootDraggable ,
475
480
filterTreeNode,
476
481
} = root . props ;
482
+ const { label } = this . state ;
483
+
477
484
this . showLine = ! isNodeBlock && showLine ;
485
+ const indexArr = pos . split ( '-' ) ;
486
+
487
+ const ARIA_PREFIX = 'aria-' ;
488
+ const ariaProps = pickAttrsWith ( this . props , ARIA_PREFIX ) ;
478
489
const others = pickOthers ( Object . keys ( TreeNode . propTypes ) , this . props ) ;
479
490
491
+ // remove aria keys
492
+ Object . keys ( others ) . forEach ( key => {
493
+ if ( key . match ( ARIA_PREFIX ) ) {
494
+ delete others [ key ] ;
495
+ }
496
+ } ) ;
497
+
480
498
if ( rootDraggable ) {
481
499
others . onDragEnter = this . handleDragEnter ;
482
500
others . onDragOver = this . handleDragOver ;
@@ -507,16 +525,18 @@ export default class TreeNode extends Component {
507
525
typeof isNodeBlock === 'object'
508
526
? parseInt ( isNodeBlock . indent || 24 )
509
527
: 24 ;
510
- const level = pos . split ( '-' ) . length - 2 ;
528
+ const level = indexArr . length - 2 ;
511
529
const paddingLeftProp = rtl ? 'paddingRight' : 'paddingLeft' ;
512
530
513
531
const innerStyle = isNodeBlock
514
532
? { [ paddingLeftProp ] : `${ indent * level + defaultPaddingLeft } px` }
515
533
: null ;
534
+
516
535
const innerProps = {
517
536
className : innerClassName ,
518
537
style : innerStyle ,
519
538
onKeyDown : this . handleKeyDown ,
539
+ ...ariaProps ,
520
540
} ;
521
541
if ( isNodeBlock ) {
522
542
this . addCallbacks ( innerProps ) ;
@@ -537,15 +557,20 @@ export default class TreeNode extends Component {
537
557
}
538
558
539
559
return (
540
- < li
541
- role = "treeitem"
542
- aria-selected = { selected }
543
- aria-disabled = { disabled }
544
- aria-expanded = { expanded && ! ! hasChildTree }
545
- className = { newClassName }
546
- { ...others }
547
- >
548
- < div ref = "node" { ...innerProps } >
560
+ < li role = "presentation" className = { newClassName } { ...others } >
561
+ < div
562
+ ref = "node"
563
+ role = "treeitem"
564
+ aria-selected = { selected }
565
+ aria-disabled = { disabled }
566
+ aria-checked = { checked }
567
+ aria-expanded = { expanded && ! ! hasChildTree }
568
+ aria-label = { typeof label === 'string' ? label : null }
569
+ aria-level = { level + 1 }
570
+ aria-posinset = { Number ( indexArr [ indexArr . length - 1 ] ) + 1 }
571
+ aria-setsize = { size }
572
+ { ...innerProps }
573
+ >
549
574
{ canExpand
550
575
? this . renderSwitcher ( )
551
576
: this . renderNoopSwitcher ( ) }
0 commit comments