@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.
Files changed (2) hide show
  1. package/dist/index.js +42 -41
  2. 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 || ! item.el.parentNode) {
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.map(function(s) {
396
- // Select values
397
- if (newValue.indexOf(s.value) !== -1) {
398
- s.selected = true;
399
- value.push(s);
400
- } else {
401
- s.selected = false;
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
- let prevent = false;
625
- if (e.key === 'ArrowUp') {
626
- moveCursor(-1);
627
- prevent = true;
628
- } else if (e.key === 'ArrowDown') {
629
- moveCursor(1);
630
- prevent = true;
631
- } else if (e.key === 'Home') {
632
- moveCursor(-1, true);
633
- } else if (e.key === 'End') {
634
- moveCursor(1, true);
635
- } else if (e.key === 'Enter') {
636
- self.select(e, self.rows[cursor]);
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
- if (prevent) {
645
- e.preventDefault();
646
- e.stopImmediatePropagation();
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" onclick="self.click" placeholder="{{self.placeholder}}" :ref="self.input" tabindex="0"></div>
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
@@ -19,5 +19,5 @@
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "3.1.1"
22
+ "version": "3.1.3"
23
23
  }