@lemonadejs/dropdown 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +42 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -305,13 +305,14 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
305
305
|
|
|
306
306
|
const setCursor = function(index) {
|
|
307
307
|
let item = self.rows[index];
|
|
308
|
+
|
|
308
309
|
if (typeof(item) !== 'undefined') {
|
|
309
310
|
// Set cursor number
|
|
310
311
|
cursor = index;
|
|
311
312
|
// Set visual indication
|
|
312
313
|
item.cursor = true;
|
|
313
314
|
// Go to the item on the scroll in case the item is not on the viewport
|
|
314
|
-
if (! item.el
|
|
315
|
+
if (! (item.el && item.el.parentNode)) {
|
|
315
316
|
// Goto method
|
|
316
317
|
self.goto(item);
|
|
317
318
|
}
|
|
@@ -373,6 +374,8 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
373
374
|
const updateLabel = function() {
|
|
374
375
|
if (value && value.length) {
|
|
375
376
|
self.input.textContent = value.filter(v => v.selected).map(i => i.text).join('; ');
|
|
377
|
+
} else {
|
|
378
|
+
self.input.textContent = '';
|
|
376
379
|
}
|
|
377
380
|
}
|
|
378
381
|
|
|
@@ -392,15 +395,17 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
392
395
|
// Width && values
|
|
393
396
|
value = [];
|
|
394
397
|
|
|
395
|
-
self.data
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
s.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
398
|
+
if (Array.isArray(self.data)) {
|
|
399
|
+
self.data.map(function (s) {
|
|
400
|
+
// Select values
|
|
401
|
+
if (newValue.indexOf(s.value) !== -1) {
|
|
402
|
+
s.selected = true;
|
|
403
|
+
value.push(s);
|
|
404
|
+
} else {
|
|
405
|
+
s.selected = false;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
404
409
|
|
|
405
410
|
// Update label
|
|
406
411
|
updateLabel();
|
|
@@ -456,8 +461,6 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
456
461
|
let v = value[value.length-1];
|
|
457
462
|
// Move to the correct position
|
|
458
463
|
if (v) {
|
|
459
|
-
// Go to the last item in the array of values
|
|
460
|
-
self.goto(v);
|
|
461
464
|
// Mark the position of the cursor to the same element
|
|
462
465
|
setCursor(self.rows.indexOf(v));
|
|
463
466
|
} else {
|
|
@@ -499,14 +502,10 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
499
502
|
}
|
|
500
503
|
}
|
|
501
504
|
|
|
502
|
-
let timer = null;
|
|
503
|
-
|
|
504
505
|
self.open = function () {
|
|
505
506
|
if (self.modal && self.modal.closed) {
|
|
506
507
|
// Open the modal
|
|
507
508
|
self.modal.closed = false;
|
|
508
|
-
// Timer
|
|
509
|
-
timer = setTimeout(() => timer = null, 400);
|
|
510
509
|
}
|
|
511
510
|
}
|
|
512
511
|
|
|
@@ -518,10 +517,6 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
518
517
|
}
|
|
519
518
|
|
|
520
519
|
self.toggle = function(e) {
|
|
521
|
-
if (timer) {
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
520
|
if (self.modal) {
|
|
526
521
|
if (self.modal.closed) {
|
|
527
522
|
self.open();
|
|
@@ -621,29 +616,35 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
621
616
|
})
|
|
622
617
|
// Key events
|
|
623
618
|
self.el.addEventListener('keydown', function(e) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
prevent = true;
|
|
638
|
-
} else {
|
|
639
|
-
if (e.keyCode === 32 && ! self.autocomplete) {
|
|
619
|
+
if (! self.modal.closed) {
|
|
620
|
+
let prevent = false;
|
|
621
|
+
if (e.key === 'ArrowUp') {
|
|
622
|
+
moveCursor(-1);
|
|
623
|
+
prevent = true;
|
|
624
|
+
} else if (e.key === 'ArrowDown') {
|
|
625
|
+
moveCursor(1);
|
|
626
|
+
prevent = true;
|
|
627
|
+
} else if (e.key === 'Home') {
|
|
628
|
+
moveCursor(-1, true);
|
|
629
|
+
} else if (e.key === 'End') {
|
|
630
|
+
moveCursor(1, true);
|
|
631
|
+
} else if (e.key === 'Enter') {
|
|
640
632
|
self.select(e, self.rows[cursor]);
|
|
633
|
+
prevent = true;
|
|
634
|
+
} else {
|
|
635
|
+
if (e.keyCode === 32 && !self.autocomplete) {
|
|
636
|
+
self.select(e, self.rows[cursor]);
|
|
637
|
+
}
|
|
641
638
|
}
|
|
642
|
-
}
|
|
643
639
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
640
|
+
if (prevent) {
|
|
641
|
+
e.preventDefault();
|
|
642
|
+
e.stopImmediatePropagation();
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
646
|
+
self.modal.closed = false;
|
|
647
|
+
}
|
|
647
648
|
}
|
|
648
649
|
});
|
|
649
650
|
|
|
@@ -721,7 +722,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
721
722
|
|
|
722
723
|
return `<div class="lm-dropdown" data-insert="{{self.insert}}" data-type="{{self.type}}" data-state="{{self.state}}" :value="self.value">
|
|
723
724
|
<div class="lm-dropdown-header">
|
|
724
|
-
<div class="lm-dropdown-input" onpaste="self.onpaste" oninput="self.search" onfocus="self.open"
|
|
725
|
+
<div class="lm-dropdown-input" onpaste="self.onpaste" oninput="self.search" onfocus="self.open" onmousedown="self.click" placeholder="{{self.placeholder}}" :ref="self.input" tabindex="0"></div>
|
|
725
726
|
<div class="lm-dropdown-add" onmousedown="self.add"></div>
|
|
726
727
|
<button onclick="self.close" class="lm-dropdown-done">Done</button>
|
|
727
728
|
</div>
|
package/package.json
CHANGED