@lemonadejs/dropdown 3.0.8 → 3.0.9

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 -13
  2. package/package.json +1 -1
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,10 @@ 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
+ }
189
218
  }
190
219
 
191
220
  return (prop) => {
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.9"
22
22
  }