Skip to content

Commit 30b6631

Browse files
committed
initial
1 parent b260136 commit 30b6631

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ treeElement.addEventListener('u1-tree1-select', (e) => { ... });
5050

5151
## API
5252
```js
53-
el.select(); // todo!
53+
el.select();
54+
el.toggleExpand(true/false);
5455
```
5556

5657

@@ -59,4 +60,3 @@ el.select(); // todo!
5960
https://raw.githack.com/u1ui/tree1.el/main/tests/custom.html
6061
https://raw.githack.com/u1ui/tree1.el/main/tests/minimal.html
6162
https://raw.githack.com/u1ui/tree1.el/main/tests/test.html
62-

tests/custom.html

+11-13
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@
44
<meta charset="utf-8">
55
<meta name=viewport content="width=device-width">
66
<script src="../../u1/tests/test-init.js" type=module></script>
7-
<script src="../../u1/auto.js" type=module></script>
87
<title>Test</title>
98

9+
<script src="../../u1/auto.js" type=module></script>
10+
1011
<link rel=stylesheet href="https://cdn.jsdelivr.net/gh/u1ui/base.css/full.css">
1112
<link rel=stylesheet href="https://cdn.jsdelivr.net/gh/u1ui/classless.css/variables.min.css">
1213
<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">
1514
<link rel=stylesheet href="https://cdn.jsdelivr.net/gh/u1ui/classless.css/simple.min.css">
1615

1716
<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+
}
2221
</style>
2322

24-
25-
<script src="../tree1.js" type=module></script>
2623
<link rel=stylesheet href="../tree1.css">
2724

25+
<script type=module>
26+
import {tree} from '../tree1.js';
27+
customElements.define('u1-tree2', class extends tree {});
28+
</script>
29+
2830
<body>
2931

3032
<section>
@@ -38,10 +40,6 @@
3840
}
3941
</style>
4042

41-
<script type=module>
42-
import {tree} from '../tree1.js';
43-
customElements.define('u1-tree2', class extends tree {});
44-
</script>
4543

4644
<u1-tree2 aria-expanded=true>root
4745
<u1-tree2>Folder 2

tests/test.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
}
2222
</style>
2323

24-
2524
<script src="../tree1.js" type=module></script>
26-
<link rel=stylesheet href="../tree1.css">
25+
<link href="../tree1.css" rel=stylesheet>
2726

2827
<body>
2928

@@ -104,7 +103,6 @@
104103
}
105104
});
106105

107-
108106
const delaied = (fn, ms)=>{
109107
return new Promise(resolve => {
110108
setTimeout(()=>{
@@ -113,7 +111,6 @@
113111
}, ms);
114112
});
115113
}
116-
117114
</script>
118115

119116
</section>

tree1.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,18 @@ export class tree extends HTMLElement {
9090
this._markup();
9191
}
9292
_markup(){
93-
94-
//const myLevel = this?.parentNode?.tagName === this.tagName ? parseInt(this.parentNode.getAttribute('aria-level'))+1 : 0;
93+
// own level
9594
const myLevel = this.root() === this ? 1 : parseInt(this.parentNode.getAttribute('aria-level')) + 1;
9695
this.setAttribute('aria-level', myLevel);
9796
this.style.setProperty('--level', myLevel);
9897

98+
// slot subnodes
9999
for (const child of this.children) {
100100
child.tagName === this.tagName && child.setAttribute('slot', 'children');
101101
}
102102
this.setAttribute('role', this.root() === this ? 'tree' : 'treeitem');
103103

104+
// if has children, its expandable
104105
if (this.items().length && !this.hasAttribute('aria-expanded')) this.setAttribute('aria-expanded', 'false');
105106
}
106107
items(){
@@ -163,10 +164,6 @@ export class tree extends HTMLElement {
163164
return this.parentNode.tagName === this.tagName ? this.parentNode.root() : this;
164165
}
165166

166-
get selected(){
167-
console.log('used? zzz')
168-
return this.root()._selected;
169-
}
170167
select(){
171168
let old = this.root()._selected;
172169
if (old) old.setAttribute('aria-selected', 'false');

0 commit comments

Comments
 (0)