File tree Expand file tree Collapse file tree 6 files changed +33
-3
lines changed Expand file tree Collapse file tree 6 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -160,9 +160,11 @@ export function DefaultContainer() {
160
160
return ;
161
161
}
162
162
if ( e . key === "Enter" ) {
163
- if ( ! tree . props . onRename ) return ;
163
+ const node = tree . focusedNode ;
164
+ if ( ! node ) return ;
165
+ if ( ! node . isEditable || ! tree . props . onRename ) return ;
164
166
setTimeout ( ( ) => {
165
- if ( tree . focusedNode ) tree . edit ( tree . focusedNode ) ;
167
+ if ( node ) tree . edit ( node ) ;
166
168
} ) ;
167
169
return ;
168
170
}
Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ export class NodeApi<T = any> {
58
58
return this . isLeaf ? false : ! this . tree . isOpen ( this . id ) ;
59
59
}
60
60
61
+ get isEditable ( ) {
62
+ return this . tree . isEditable ( this . data ) ;
63
+ }
64
+
61
65
get isEditing ( ) {
62
66
return this . tree . editingId === this . id ;
63
67
}
Original file line number Diff line number Diff line change @@ -529,6 +529,11 @@ export class TreeApi<T> {
529
529
}
530
530
}
531
531
532
+ isEditable ( data : T ) {
533
+ const check = this . props . disableEdit || ( ( ) => false ) ;
534
+ return ! utils . access ( data , check ) ?? true ;
535
+ }
536
+
532
537
isDraggable ( data : T ) {
533
538
const check = this . props . disableDrag || ( ( ) => false ) ;
534
539
return ! utils . access ( data , check ) ?? true ;
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export interface TreeProps<T> {
38
38
openByDefault ?: boolean ;
39
39
selectionFollowsFocus ?: boolean ;
40
40
disableMultiSelection ?: boolean ;
41
+ disableEdit ?: string | boolean | BoolFunc < T > ;
41
42
disableDrag ?: string | boolean | BoolFunc < T > ;
42
43
disableDrop ?: string | boolean | BoolFunc < T > ;
43
44
childrenAccessor ?: string | ( ( d : T ) => T [ ] | null ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export type GmailItem = {
6
6
name : string ;
7
7
icon : ComponentType ;
8
8
unread ?: number ;
9
+ readOnly : boolean ;
9
10
children ?: GmailItem [ ] ;
10
11
} ;
11
12
@@ -14,95 +15,111 @@ export const gmailData: GmailItem[] = [
14
15
id : "1" ,
15
16
name : "Inbox" ,
16
17
unread : 1 ,
18
+ readOnly : true ,
17
19
icon : icons . MdInbox ,
18
20
} ,
19
21
{
20
22
id : "2" ,
21
23
name : "Starred" ,
22
24
unread : 0 ,
25
+ readOnly : true ,
23
26
icon : icons . MdStarOutline ,
24
27
} ,
25
28
{
26
29
id : "3" ,
27
30
name : "Snoozed" ,
28
31
unread : 0 ,
32
+ readOnly : true ,
29
33
icon : icons . MdAccessTime ,
30
34
} ,
31
35
{
32
36
id : "4" ,
33
37
name : "Sent" ,
34
38
unread : 0 ,
39
+ readOnly : true ,
35
40
icon : icons . MdSend ,
36
41
} ,
37
42
{
38
43
id : "5" ,
39
44
name : "Drafts" ,
40
45
unread : 14 ,
46
+ readOnly : true ,
41
47
icon : icons . MdOutlineDrafts ,
42
48
} ,
43
49
{
44
50
id : "6" ,
45
51
name : "Spam" ,
46
52
unread : 54 ,
53
+ readOnly : true ,
47
54
icon : icons . MdOutlineReportGmailerrorred ,
48
55
} ,
49
56
{
50
57
id : "7" ,
51
58
name : "Important" ,
52
59
unread : 0 ,
60
+ readOnly : true ,
53
61
icon : icons . MdLabelImportantOutline ,
54
62
} ,
55
63
{
56
64
id : "8" ,
57
65
name : "Chats" ,
58
66
unread : 0 ,
67
+ readOnly : true ,
59
68
icon : icons . MdOutlineChat ,
60
69
} ,
61
70
{
62
71
id : "9" ,
63
72
name : "Scheduled" ,
64
73
unread : 0 ,
74
+ readOnly : true ,
65
75
icon : icons . MdOutlineScheduleSend ,
66
76
} ,
67
77
{
68
78
id : "10" ,
69
79
name : "All Mail" ,
70
80
unread : 0 ,
81
+ readOnly : true ,
71
82
icon : icons . MdOutlineMail ,
72
83
} ,
73
84
{
74
85
id : "11" ,
75
86
name : "Trash" ,
76
87
unread : 0 ,
88
+ readOnly : true ,
77
89
icon : icons . MdOutlineDelete ,
78
90
} ,
79
91
{
80
92
id : "12" ,
81
93
name : "Categories" ,
82
94
icon : icons . MdOutlineLabel ,
95
+ readOnly : true ,
83
96
children : [
84
97
{
85
98
id : "13" ,
86
99
name : "Social" ,
87
100
unread : 946 ,
101
+ readOnly : false ,
88
102
icon : icons . MdPeopleOutline ,
89
103
} ,
90
104
{
91
105
id : "14" ,
92
106
name : "Updates" ,
93
107
unread : 4580 ,
108
+ readOnly : false ,
94
109
icon : icons . MdOutlineInfo ,
95
110
} ,
96
111
{
97
112
id : "15" ,
98
113
name : "Forums" ,
99
114
unread : 312 ,
115
+ readOnly : false ,
100
116
icon : icons . MdChatBubbleOutline ,
101
117
} ,
102
118
{
103
119
id : "16" ,
104
120
name : "Promotions" ,
105
121
unread : 312 ,
122
+ readOnly : false ,
106
123
icon : icons . MdOutlineLocalOffer ,
107
124
} ,
108
125
] ,
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ export default function GmailSidebar() {
35
35
renderCursor = { Cursor }
36
36
searchTerm = { term }
37
37
paddingBottom = { 32 }
38
+ disableEdit = { ( data ) => data . readOnly }
38
39
>
39
40
{ Node }
40
41
</ Tree >
@@ -57,7 +58,7 @@ export default function GmailSidebar() {
57
58
< li > Drag the items around</ li >
58
59
< li > Move focus with the arrow keys</ li >
59
60
< li > Toggle folders (press spacebar)</ li >
60
- < li > Rename (press enter)</ li >
61
+ < li > Rename (press enter, only allowed on items in 'Categories' )</ li >
61
62
< li > Create a new item (press A)</ li >
62
63
< li > Create a new folder (press shift+A)</ li >
63
64
< li > Delete items (press delete)</ li >
You can’t perform that action at this time.
0 commit comments