@lemonadejs/dropdown 3.0.8 → 3.0.10

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 CHANGED
@@ -18,7 +18,7 @@ if (!Modal && typeof (require) === 'function') {
18
18
  }(this, (function () {
19
19
 
20
20
  // Default row height
21
- let defaultRowHeight = 26;
21
+ let defaultRowHeight = 24;
22
22
 
23
23
  const lazyLoading = function(self) {
24
24
  /**
@@ -67,31 +67,51 @@ if (!Modal && typeof (require) === 'function') {
67
67
  const updateScroll = function() {
68
68
  let items = self.rows;
69
69
  if (items) {
70
+ // Before control
71
+ let before = true;
70
72
  // Total of items in the container
71
73
  let numOfItems = items.length;
72
74
  // Position from top
73
75
  let height = 0;
76
+ // Size of the adjustment
77
+ let size = 0;
74
78
  // Go through the items
75
79
  for (let j = 0; j < numOfItems; j++) {
76
- height += items[j].height || defaultRowHeight;
80
+ let h = items[j].height || defaultRowHeight;
81
+ // Height
82
+ height += h;
83
+ // Start tracking all items as before
84
+ if (items[j] === self.result[0]) {
85
+ before = false;
86
+ }
87
+ // Adjustment
88
+ if (before) {
89
+ size += h;
90
+ }
77
91
  }
78
92
  // Update height
79
93
  scroll.style.height = height + 'px';
94
+ // Adjust scroll position
95
+ return size;
80
96
  }
97
+ return false;
81
98
  }
82
99
 
83
100
  const getVisibleRows = function(reset) {
84
101
  let items = self.rows;
85
102
  if (items) {
86
- let rows = [];
103
+ let adjust;
87
104
  // Total of items in the container
88
105
  let numOfItems = items.length;
89
- // Height
90
- let height = 0;
91
- // Controls
106
+ // Get the position from top
92
107
  let y = el.scrollTop;
108
+ // Get the height
93
109
  let h = y + (el.offsetHeight || self.height);
94
110
  // Go through the items
111
+ let rows = [];
112
+ // Height
113
+ let height = 0;
114
+ // Go through all items
95
115
  for (let j = 0; j < numOfItems; j++) {
96
116
  if (items[j].visible !== false) {
97
117
  // Height
@@ -106,6 +126,7 @@ if (!Modal && typeof (require) === 'function') {
106
126
 
107
127
  // Update visible rows
108
128
  if (reset || ! compareArray(rows, self.result)) {
129
+ // Render the items
109
130
  self.result = rows;
110
131
  // Adjust scroll height
111
132
  let adjustScroll = reset;
@@ -126,7 +147,8 @@ if (!Modal && typeof (require) === 'function') {
126
147
 
127
148
  // Update scroll if the height of one element has been changed
128
149
  if (adjustScroll) {
129
- updateScroll();
150
+ // Adjust the scroll height
151
+ adjust = updateScroll();
130
152
  }
131
153
  }
132
154
 
@@ -137,6 +159,8 @@ if (!Modal && typeof (require) === 'function') {
137
159
  diff = 0;
138
160
  }
139
161
  self.container.style.top = diff + 'px';
162
+
163
+ return adjust;
140
164
  }
141
165
  }
142
166
 
@@ -151,13 +175,17 @@ if (!Modal && typeof (require) === 'function') {
151
175
  getVisibleRows(reset);
152
176
  }
153
177
 
178
+ /**
179
+ * Will adjust the items based on the scroll position offset
180
+ */
154
181
  self.adjustPosition = function(item) {
155
182
  if (item.el) {
156
- let calc = item.el.offsetTop + item.el.offsetHeight;
183
+ let h = item.el.offsetHeight;
184
+ let calc = item.el.offsetTop + h;
157
185
  if (calc > el.offsetHeight) {
158
186
  let size = calc - el.offsetHeight;
159
- if (size < defaultRowHeight) {
160
- size = defaultRowHeight;
187
+ if (size < h) {
188
+ size = h;
161
189
  }
162
190
  el.scrollTop -= -1 * size;
163
191
  }
@@ -166,7 +194,6 @@ if (!Modal && typeof (require) === 'function') {
166
194
 
167
195
  // Controls
168
196
  const scrollControls = function() {
169
- // Get all items that should be visible based on the position of the scroll
170
197
  getVisibleRows(false);
171
198
  }
172
199
 
@@ -184,8 +211,12 @@ if (!Modal && typeof (require) === 'function') {
184
211
 
185
212
  self.goto = function(item) {
186
213
  el.scrollTop = getRowPosition(item);
187
- // Get all items that should be visible based on the position of the scroll
188
- getVisibleRows(false);
214
+ let adjust = getVisibleRows(false);
215
+ if (adjust) {
216
+ el.scrollTop += adjust;
217
+ // Last adjust on the visible rows
218
+ getVisibleRows(false);
219
+ }
189
220
  }
190
221
 
191
222
  return (prop) => {
@@ -368,9 +399,9 @@ if (!Modal && typeof (require) === 'function') {
368
399
 
369
400
  const onclose = function() {
370
401
  // Cursor
371
- removeCursor();
402
+ removeCursor(true);
372
403
  // Reset search
373
- if (self.autocomplete && self.input.textContent) {
404
+ if (self.autocomplete) {
374
405
  // Go to begin of the data
375
406
  self.rows = self.data;
376
407
  // Remove editable attribute
@@ -390,8 +421,6 @@ if (!Modal && typeof (require) === 'function') {
390
421
  self.state = true;
391
422
  // Value
392
423
  let v = value[value.length-1];
393
- // Cursor
394
- removeCursor();
395
424
  // Move to the correct position
396
425
  if (v) {
397
426
  // Go to the last item in the array of values
@@ -433,9 +462,14 @@ if (!Modal && typeof (require) === 'function') {
433
462
  }
434
463
  }
435
464
 
465
+ let timer = null;
466
+
436
467
  self.open = function () {
437
468
  if (self.modal && self.modal.closed) {
469
+ // Open the modal
438
470
  self.modal.closed = false;
471
+ // Timer
472
+ timer = setTimeout(() => timer = null, 400);
439
473
  }
440
474
  }
441
475
 
@@ -443,12 +477,14 @@ if (!Modal && typeof (require) === 'function') {
443
477
  // Close the modal
444
478
  if (self.modal) {
445
479
  self.modal.closed = true;
446
- // Remove cursor
447
- removeCursor(true);
448
480
  }
449
481
  }
450
482
 
451
- self.toggle = function() {
483
+ self.toggle = function(e) {
484
+ if (timer) {
485
+ return;
486
+ }
487
+
452
488
  if (self.modal) {
453
489
  if (self.modal.closed) {
454
490
  self.open();
@@ -458,6 +494,20 @@ if (!Modal && typeof (require) === 'function') {
458
494
  }
459
495
  }
460
496
 
497
+ self.click = function(e) {
498
+ let x;
499
+ if (e.changedTouches && e.changedTouches[0]) {
500
+ x = e.changedTouches[0].clientX;
501
+ } else {
502
+ x = e.clientX;
503
+ }
504
+ if (e.target.offsetWidth - (x - e.target.offsetLeft) < 24) {
505
+ self.toggle();
506
+ } else {
507
+ self.open();
508
+ }
509
+ }
510
+
461
511
  self.select = function(e, s) {
462
512
  if (s) {
463
513
  if (self.multiple === true) {
@@ -504,9 +554,9 @@ if (!Modal && typeof (require) === 'function') {
504
554
  closed: true,
505
555
  focus: false,
506
556
  width: self.width,
507
- 'auto-close': false,
508
557
  onopen: onopen,
509
558
  onclose: onclose,
559
+ 'auto-close': false,
510
560
  };
511
561
  // Generate modal
512
562
  Modal(self.el.children[1], self.modal);
@@ -525,7 +575,7 @@ if (!Modal && typeof (require) === 'function') {
525
575
  if (self.modal) {
526
576
  if (! (e.relatedTarget && self.el.contains(e.relatedTarget)) && !self.el.contains(e.relatedTarget)) {
527
577
  if (! self.modal.closed) {
528
- self.close();
578
+ self.modal.closed = true;
529
579
  }
530
580
  }
531
581
  }
@@ -573,7 +623,7 @@ if (!Modal && typeof (require) === 'function') {
573
623
 
574
624
  return `<div class="lm-dropdown" data-type="{{self.type}}" data-state="{{self.state}}">
575
625
  <div class="lm-dropdown-header">
576
- <div class="lm-dropdown-input" oninput="self.search" onfocus="self.open" placeholder="{{self.placeholder}}" :ref="self.input" tabindex="0"></div>
626
+ <div class="lm-dropdown-input" oninput="self.search" onfocus="self.open" onclick="self.click" placeholder="{{self.placeholder}}" :ref="self.input" tabindex="0"></div>
577
627
  <button onclick="self.close" class="lm-dropdown-done">Done</button>
578
628
  </div>
579
629
  <div class="lm-dropdown-content">
package/dist/style.css CHANGED
@@ -44,13 +44,28 @@
44
44
  cursor: pointer;
45
45
  box-sizing: border-box;
46
46
  width: 100%;
47
- background-repeat: no-repeat;
48
- background-position: top 50% right 0;
49
- background-image: url("data:image/svg+xml,%0A%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='none' d='M0 0h24v24H0V0z'/%3E%3Cpath d='M7 10l5 5 5-5H7z' fill='gray'/%3E%3C/svg%3E");
50
47
  border: 1px solid #ccc;
51
48
  min-height: 1em;
52
49
  }
53
50
 
51
+ .lm-dropdown-input::after {
52
+ content: '';
53
+ position: absolute;
54
+ width: 24px;
55
+ height: 24px;
56
+ right: 2px;
57
+ top: 2px;
58
+ background-repeat: no-repeat;
59
+ background-image: url("data:image/svg+xml,%0A%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='none' d='M0 0h24v24H0V0z'/%3E%3Cpath d='M7 10l5 5 5-5H7z' fill='gray'/%3E%3C/svg%3E");
60
+ transition: transform .2s ease-in-out;
61
+ }
62
+
63
+
64
+ .lm-dropdown[data-state="true"] .lm-dropdown-input::after {
65
+ transform: rotate(-180deg);
66
+ }
67
+
68
+
54
69
  .lm-dropdown-input:empty::before {
55
70
  content: "\00a0";
56
71
  }
package/package.json CHANGED
@@ -18,5 +18,5 @@
18
18
  "@lemonadejs/modal": "^2.4.0"
19
19
  },
20
20
  "main": "dist/index.js",
21
- "version": "3.0.8"
21
+ "version": "3.0.10"
22
22
  }