This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathleafNode.tsx
More file actions
54 lines (45 loc) · 1.56 KB
/
Copy pathleafNode.tsx
File metadata and controls
54 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as React from 'react';
import { CommonNodeProps } from './commonNodeProps';
import { NodeRenderStrategy } from './nodeRenderStrategy';
import { TreeViewNavigationUtils } from './treeViewNavigationUtils';
export interface LeafNodeProps extends CommonNodeProps {
node: NodeRenderStrategy;
}
export class LeafNode extends React.Component<LeafNodeProps, {}> {
onKeyDown(event: KeyboardEvent) {
TreeViewNavigationUtils.normalizeKeyboardEventBehaviour(event);
TreeViewNavigationUtils.handleMovementKeyboardEvent(this.props.id, this.props.treeViewId, event, this.props.globals.callbacks.onAccessibleSelection);
switch (event.keyCode) {
case 32:
// Space
this.props.node.onClickBinded();
break;
default:
break;
}
}
componentDidMount() {
const { focusOnMount, id } = this.props;
if (focusOnMount) {
const self = document.querySelector(`[data-id='${id}']`) as HTMLElement;
self.focus();
}
}
private level() {
return this.props.level || 1;
}
private descendentId() {
return this.props.treeViewId + this.props.id;
}
render() {
return (
<li aria-labelledby={this.descendentId()} role='treeitem' aria-level={this.level()} aria-checked={this.props.node.isSelected()}
id={this.descendentId()} aria-selected={this.props.ariaSelected}>
<a className='picker-row' onClick={this.props.node.onClickBinded} onKeyDown={this.onKeyDown.bind(this)}
data-treeviewid={this.props.treeViewId} data-id={this.props.id} tabIndex={this.props.tabbable ? 0 : -1}
role='presentation'>
{this.props.node.element()}
</a>
</li>);
}
}