Skip to content

Commit

Permalink
add path() methode, remove arrow if loading brings no new items
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxodin committed Jun 30, 2022
1 parent 805dcae commit 6f46221
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tree1.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ export class tree extends HTMLElement {
promise.then(data => {
this.removeAttribute('aria-live');
this.removeAttribute('aria-busy');
setTimeout(()=>{ // make unexpandable if no childs
!this.items().length && this.removeAttribute('aria-expanded');
},100);
}).catch(data=>{
console.warn('todo: u1-tree: failed to load')
console.warn('todo: u1-tree: failed to load');
});
}
}
Expand All @@ -161,7 +164,7 @@ export class tree extends HTMLElement {
this.setAttribute('aria-expanded', doit?'true':'false');
}
root(){
return this.parentNode.tagName === this.tagName ? this.parentNode.root() : this;
return this.isRoot() ? this : this.parentNode.root();
}

select(){
Expand Down Expand Up @@ -189,6 +192,15 @@ export class tree extends HTMLElement {
setFocus() {
this.activeElement = this;
}
isRoot(){
return this.parentNode.tagName !== this.tagName;
}

path(){
if (this.isRoot()) return [this];
return [this].concat(this.parentNode.path()); // as we dont cache, we dont have to make a copy
// return this.isRoot() ? [this] : [...this.parentNode.path(), this];
}
}

customElements.define('u1-tree1', tree);
Expand Down

0 comments on commit 6f46221

Please sign in to comment.