Skip to content

Commit

Permalink
Update tree1 component and test.html
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxodin committed Mar 7, 2024
1 parent e29e6b4 commit 73ef9b3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
32 changes: 27 additions & 5 deletions tests/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,24 @@
</u1-tree1>
<u1-tree1 draggable="true">
<u1-ico slot=icon icon=drag_indicator>x</u1-ico>
Draggable
<label>
Draggable
<input placeholder="same baseline">
</label>
<button>clickable</button>
</u1-tree1>

<u1-tree1>
<input type=checkbox slot=icon id="check1">
Checkbox
<u1-tree1>
<input type=checkbox slot=icon id="check2">
Checkbox
</u1-tree1>
<u1-tree1>
<input type=checkbox slot=icon id="check3">
Checkbox
</u1-tree1>
</u1-tree1>

</u1-tree1>
Expand All @@ -88,7 +105,7 @@

<section>

<u1-code element=demo editable trim></u1-code>
<u1-code element=demo editable trim> </u1-code>

<u1-code trim editable>
<style>
Expand All @@ -105,6 +122,11 @@
u1-tree1::part(row):hover {
background:#00000004;
}
u1-tree1[aria-grabbed=true] {
transition:.2s .2s;
opacity:.4;
outline-width:0 !important;
}
</style>
</u1-code>

Expand Down Expand Up @@ -138,8 +160,6 @@





<script type=module>
/* drag & drop experiment */

Expand Down Expand Up @@ -167,7 +187,8 @@
ondragstart({target, event}) {
if (target.tagName !== 'U1-TREE1') return;
dragSrcEl = target;
event.dataTransfer.effectAllowed = 'move';
dragSrcEl.setAttribute('aria-grabbed', 'true'); // deprecated, but currently the best markup?
event.dataTransfer.effectAllowed = 'move'; // needed?
},
ondragover({closest, event}) {
event.preventDefault();
Expand Down Expand Up @@ -221,6 +242,7 @@
},
ondragend() {
dropPositionIndicator.style.display = 'none';
dragSrcEl.removeAttribute('aria-grabbed');
dragSrcEl = null;
},
resetExpandTimer(item) {
Expand Down
8 changes: 6 additions & 2 deletions tree1.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ u1-tree1::part(row):focus {
u1-tree1[aria-selected=true]::part(row) {
background:#00000008;
}
u1-tree1[draggable]::part(row) {
cursor:grab;
}


u1-tree1:not(:defined) {
padding:.2em 0 0 0;
padding-block-start:.2em;
display:list-item;
list-style-position: inside;
> u1-tree1 {
padding-left:1.2em;
padding-inline-start:1.2em;

}
}
22 changes: 15 additions & 7 deletions tree1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ let css = `
[part=row] {
display:flex;
padding:.15em 0;
padding-left:calc( var(--indent) * (var(--level) - 1) );
align-items:baseline;
padding-block: .15em;
padding-inline-start:calc( var(--indent) * (var(--level) - 1) );
gap:.3em;
}
Expand All @@ -40,8 +41,9 @@ let css = `
display:flex;
align-items: center;
justify-content:center;
min-width:1.7em;
min-inline-size:1.7em;
font-weight:400;
align-self:stretch;
}
`;

Expand Down Expand Up @@ -113,15 +115,21 @@ export class tree extends HTMLElement {
}
_markup(){
// own level
const myLevel = this.root() === this ? 1 : parseInt(this.parentNode.getAttribute('aria-level')) + 1;
const root = this.root();
const myLevel = root === this ? 1 : parseInt(this.parentNode.getAttribute('aria-level')) + 1;
this.setAttribute('aria-level', myLevel);
this.style.setProperty('--level', myLevel);

// slot subnodes
for (const child of this.children) {
child.tagName === this.tagName && child.setAttribute('slot', 'children');
}
this.setAttribute('role', this.root() === this ? 'tree' : 'treeitem');
this.setAttribute('role', root === this ? 'tree' : 'treeitem');

// make it selectable if its the root and no other is selected
if (root === this && !root._activeElement) {
this.row.setAttribute('tabindex', '0');
}

// if has children, its expandable
if (!this.hasAttribute('aria-expanded')) {
Expand All @@ -142,7 +150,7 @@ export class tree extends HTMLElement {
if (item.isExpanded()) {
next = item.items().at(0);
}
if (!next) next = item.nextElementSibling;
if (!next) next = item.nextElementSibling; // todo: only next treeitem

if (!next) {
while (item.parentNode) {
Expand All @@ -162,7 +170,7 @@ export class tree extends HTMLElement {
prevFocusable(){
let item = this;
while (item) {
let next = item.previousElementSibling;
let next = item.previousElementSibling; // todo: only next treeitem
if (next) {
if (next.isExpanded()) {
next = next.items().at(-1);
Expand Down

0 comments on commit 73ef9b3

Please sign in to comment.