File tree 4 files changed +17
-25
lines changed
4 files changed +17
-25
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ treeElement.addEventListener('u1-tree1-select', (e) => { ... });
50
50
51
51
## API
52
52
``` js
53
- el .select (); // todo!
53
+ el .select ();
54
+ el .toggleExpand (true / false );
54
55
```
55
56
56
57
@@ -59,4 +60,3 @@ el.select(); // todo!
59
60
https://raw.githack.com/u1ui/tree1.el/main/tests/custom.html
60
61
https://raw.githack.com/u1ui/tree1.el/main/tests/minimal.html
61
62
https://raw.githack.com/u1ui/tree1.el/main/tests/test.html
62
-
Original file line number Diff line number Diff line change 4
4
< meta charset ="utf-8 ">
5
5
< meta name =viewport content ="width=device-width ">
6
6
< script src ="../../u1/tests/test-init.js " type =module > </ script >
7
- < script src ="../../u1/auto.js " type =module > </ script >
8
7
< title > Test</ title >
9
8
9
+ < script src ="../../u1/auto.js " type =module > </ script >
10
+
10
11
< link rel =stylesheet href ="https://cdn.jsdelivr.net/gh/u1ui/base.css/full.css ">
11
12
< link rel =stylesheet href ="https://cdn.jsdelivr.net/gh/u1ui/classless.css/variables.min.css ">
12
13
< link rel =stylesheet href ="https://cdn.jsdelivr.net/gh/u1ui/classless.css/classless.min.css ">
13
- < link rel =stylesheet href ="https://cdn.jsdelivr.net/gh/u1ui/classless.css/more.min.css ">
14
- < link rel =stylesheet href ="https://cdn.jsdelivr.net/gh/u1ui/classless.css/aria.min.css ">
15
14
< link rel =stylesheet href ="https://cdn.jsdelivr.net/gh/u1ui/classless.css/simple.min.css ">
16
15
17
16
< style >
18
- body {
19
- place-content : initial;
20
- --u1-ico-dir : 'https://cdn.jsdelivr.net/npm/@material-icons/svg@1.0.11/svg/{icon}/baseline.svg' ;
21
- }
17
+ body {
18
+ place-content : initial;
19
+ --u1-ico-dir : 'https://cdn.jsdelivr.net/npm/@material-icons/svg@1.0.11/svg/{icon}/baseline.svg' ;
20
+ }
22
21
</ style >
23
22
24
-
25
- < script src ="../tree1.js " type =module > </ script >
26
23
< link rel =stylesheet href ="../tree1.css ">
27
24
25
+ < script type =module >
26
+ import { tree } from '../tree1.js' ;
27
+ customElements . define ( 'u1-tree2' , class extends tree { } ) ;
28
+ </ script >
29
+
28
30
< body >
29
31
30
32
< section >
38
40
}
39
41
</ style >
40
42
41
- < script type =module >
42
- import { tree } from '../tree1.js' ;
43
- customElements . define ( 'u1-tree2' , class extends tree { } ) ;
44
- </ script >
45
43
46
44
< u1-tree2 aria-expanded =true > root
47
45
< u1-tree2 > Folder 2
Original file line number Diff line number Diff line change 21
21
}
22
22
</ style >
23
23
24
-
25
24
< script src ="../tree1.js " type =module > </ script >
26
- < link rel = stylesheet href ="../tree1.css ">
25
+ < link href ="../tree1.css " rel = stylesheet >
27
26
28
27
< body >
29
28
104
103
}
105
104
} ) ;
106
105
107
-
108
106
const delaied = ( fn , ms ) => {
109
107
return new Promise ( resolve => {
110
108
setTimeout ( ( ) => {
113
111
} , ms ) ;
114
112
} ) ;
115
113
}
116
-
117
114
</ script >
118
115
119
116
</ section >
Original file line number Diff line number Diff line change @@ -90,17 +90,18 @@ export class tree extends HTMLElement {
90
90
this . _markup ( ) ;
91
91
}
92
92
_markup ( ) {
93
-
94
- //const myLevel = this?.parentNode?.tagName === this.tagName ? parseInt(this.parentNode.getAttribute('aria-level'))+1 : 0;
93
+ // own level
95
94
const myLevel = this . root ( ) === this ? 1 : parseInt ( this . parentNode . getAttribute ( 'aria-level' ) ) + 1 ;
96
95
this . setAttribute ( 'aria-level' , myLevel ) ;
97
96
this . style . setProperty ( '--level' , myLevel ) ;
98
97
98
+ // slot subnodes
99
99
for ( const child of this . children ) {
100
100
child . tagName === this . tagName && child . setAttribute ( 'slot' , 'children' ) ;
101
101
}
102
102
this . setAttribute ( 'role' , this . root ( ) === this ? 'tree' : 'treeitem' ) ;
103
103
104
+ // if has children, its expandable
104
105
if ( this . items ( ) . length && ! this . hasAttribute ( 'aria-expanded' ) ) this . setAttribute ( 'aria-expanded' , 'false' ) ;
105
106
}
106
107
items ( ) {
@@ -163,10 +164,6 @@ export class tree extends HTMLElement {
163
164
return this . parentNode . tagName === this . tagName ? this . parentNode . root ( ) : this ;
164
165
}
165
166
166
- get selected ( ) {
167
- console . log ( 'used? zzz' )
168
- return this . root ( ) . _selected ;
169
- }
170
167
select ( ) {
171
168
let old = this . root ( ) . _selected ;
172
169
if ( old ) old . setAttribute ( 'aria-selected' , 'false' ) ;
You can’t perform that action at this time.
0 commit comments