Skip to content

Commit c14e223

Browse files
committed
improve multiselect toggle
1 parent ce4c937 commit c14e223

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/public/web-components.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -520,18 +520,23 @@ class ResourcesComponent extends HTMLElement {
520520
this.isPointerDown = false;
521521
this.onPointerUp = () => {
522522
this.isPointerDown = false;
523+
this.updateSelected();
523524
}
524525
this.onPointerEnter = (evt) => {
525526
if(evt.target.className !== 'select-option' || !this.isPointerDown) return;
526-
this.onSelectResource(evt);
527+
toggleItemSelected(evt.target);
528+
}
529+
const toggleItemSelected = item => {
530+
item.hasAttribute('data-selected') ? item.removeAttribute('data-selected') : item.setAttribute('data-selected', true);
527531
}
528532
this.onSelectOneResource = evt => {
529533
this.isPointerDown = true;
530534
shadowRoot.getElementById('resources-editor-select').focus();
531535
if(evt.target.className !== 'select-option') return;
532-
console.log(this.isControlDown)
536+
console.log('is control down --> ',this.isControlDown)
533537
if(!this.isControlDown) shadowRoot.getElementById('resources-editor-select').childNodes.forEach(item => item.removeAttribute('data-selected'));
534-
evt.target.setAttribute('data-selected', true)
538+
// evt.target.setAttribute('data-selected', true)
539+
toggleItemSelected(evt.target);
535540
this.updateSelected();
536541
}
537542
this.selectAndScrollIntoView = el => {
@@ -548,7 +553,6 @@ class ResourcesComponent extends HTMLElement {
548553
shadowRoot.getElementById('resources-editor-select').focus();
549554
}, 300)
550555
}
551-
this.isControlDown = false;
552556
this.onKeyDown = evt => {
553557
evt.preventDefault();
554558
evt.stopPropagation()
@@ -585,10 +589,6 @@ class ResourcesComponent extends HTMLElement {
585589
this.onSelectAll();
586590
}
587591
}
588-
this.onSelectResource = evt => {
589-
evt.target.toggleAttribute('data-selected');
590-
this.updateSelected();
591-
};
592592
this.onSelectAll = () => {
593593
const hasSelected = !!shadowRoot.getElementById('resources-editor-select').querySelector('[data-selected]');
594594
shadowRoot.getElementById('resources-editor-select').childNodes.forEach(item => hasSelected ? item.removeAttribute('data-selected') : item.setAttribute('data-selected', true))
@@ -726,10 +726,9 @@ class ResourcesComponent extends HTMLElement {
726726
shadowRoot
727727
.getElementById('resources-editor-select')
728728
.addEventListener('pointerup',this.onPointerUp);
729-
shadowRoot
730-
.getElementById('resources-editor-select').addEventListener('keydown', this.onKeyDown);
731-
shadowRoot
732-
.getElementById('resources-editor-select').addEventListener('keyup', this.onKeyUp);
729+
this.isControlDown = false;
730+
shadowRoot.addEventListener('keydown', this.onKeyDown);
731+
shadowRoot.addEventListener('keyup', this.onKeyUp);
733732
shadowRoot
734733
.getElementById('onRemoveButton')
735734
.removeEventListener('click', this.onRemoveResource);

0 commit comments

Comments
 (0)