Skip to content

Commit e5f2c5f

Browse files
committed
- even if count-scroll = false we should still consider scroll position to keep picker in viewport as possible.
- bump version
1 parent 635ae6d commit e5f2c5f

File tree

6 files changed

+35
-29
lines changed

6 files changed

+35
-29
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Logs
22

3+
## v0.0.6
4+
5+
- even if `count-scroll = false` we should still consider scroll position to keep picker in viewport as possible.
6+
7+
38
## v0.0.5
49

510
- support `change` event when value changed.

dist/index.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@
208208
countScroll = true;
209209
while (n && n.getAttribute) {
210210
s = getComputedStyle(n);
211-
if (n.nodeName === 'BODY' || ['overflow', 'overflow-y', 'overflow-x'].filter(fn$).length) {
211+
if (n.nodeName === 'BODY') {
212+
if (!nscroll) {
213+
nscroll = document.scrollingElement;
214+
}
215+
}
216+
if (['overflow', 'overflow-y', 'overflow-x'].filter(fn$).length) {
212217
if (!nscroll) {
213218
nscroll = n;
214219
}
@@ -228,24 +233,19 @@
228233
}
229234
stackb = nstack.getBoundingClientRect();
230235
scrollb = nscroll.getBoundingClientRect();
231-
scroll = countScroll
232-
? {
233-
left: nscroll.scrollLeft,
234-
top: nscroll.scrollTop
235-
}
236-
: {
237-
left: 0,
238-
top: 0
239-
};
240-
if (hb.y + hb.height + cb.height > scrollb.y + scrollb.height) {
241-
y = hb.y - stackb.y - cb.height + scroll.top - 2;
236+
scroll = {
237+
left: nscroll.scrollLeft,
238+
top: nscroll.scrollTop
239+
};
240+
if (hb.y + hb.height + cb.height > scrollb.y + scrollb.height + scroll.top) {
241+
y = hb.y - stackb.y - cb.height + (countScroll ? scroll.top : 0) - 2;
242242
} else {
243-
y = hb.y - stackb.y + hb.height + scroll.top + 2;
243+
y = hb.y - stackb.y + hb.height + (countScroll ? scroll.top : 0) + 2;
244244
}
245-
if (hb.x + cb.width > scrollb.x + scrollb.width) {
246-
x = hb.x - stackb.x + hb.width - cb.width + scroll.left;
245+
if (hb.x + cb.width > scrollb.x + scrollb.width + scroll.left) {
246+
x = hb.x - stackb.x + hb.width - cb.width + (countScroll ? scroll.left : 0);
247247
} else {
248-
x = hb.x - stackb.x + scroll.left;
248+
x = hb.x - stackb.x + (countScroll ? scroll.left : 0);
249249
}
250250
c.style.transform = "translate(" + x + "px, " + y + "px)";
251251
return ref$ = c.style, ref$.top = 0, ref$.left = 0, ref$;

dist/index.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lddatetimepicker",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "vanilla date/time picker",
55
"browser": "dist/index.min.js",
66
"main": "dist/index.js",

src/index.ls

+10-9
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ lddatetimepicker.prototype = Object.create(Object.prototype) <<< do
154154

155155
while n and n.getAttribute
156156
s = getComputedStyle(n)
157-
if n.nodeName == \BODY or <[overflow overflow-y overflow-x]>.filter(-> s[it] != \visible).length =>
157+
if n.nodeName == \BODY =>
158+
if !nscroll => nscroll = document.scrollingElement
159+
if <[overflow overflow-y overflow-x]>.filter(-> s[it] != \visible).length =>
158160
if !nscroll => nscroll = n
159161
# TODO (should we consider opacity, transform and filter? )
160162
if n.nodeName == \BODY or s.position != \static =>
@@ -167,16 +169,15 @@ lddatetimepicker.prototype = Object.create(Object.prototype) <<< do
167169
n = n.parentNode
168170
stackb = nstack.getBoundingClientRect!
169171
scrollb = nscroll.getBoundingClientRect!
170-
scroll = if count-scroll => {left: nscroll.scrollLeft, top: nscroll.scrollTop} else {left: 0, top: 0}
171-
if hb.y + hb.height + cb.height > scrollb.y + scrollb.height =>
172-
y = hb.y - stackb.y - cb.height + scroll.top - 2
172+
scroll = {left: nscroll.scrollLeft, top: nscroll.scrollTop}
173+
if hb.y + hb.height + cb.height > scrollb.y + scrollb.height + scroll.top =>
174+
y = hb.y - stackb.y - cb.height + (if count-scroll => scroll.top else 0) - 2
173175
else
174-
y = hb.y - stackb.y + hb.height + scroll.top + 2
175-
if hb.x + cb.width > scrollb.x + scrollb.width =>
176-
x = hb.x - stackb.x + hb.width - cb.width + scroll.left
176+
y = hb.y - stackb.y + hb.height + (if count-scroll => scroll.top else 0) + 2
177+
if hb.x + cb.width > scrollb.x + scrollb.width + scroll.left =>
178+
x = hb.x - stackb.x + hb.width - cb.width + (if count-scroll => scroll.left else 0)
177179
else
178-
x = hb.x - stackb.x + scroll.left
179-
180+
x = hb.x - stackb.x + (if count-scroll => scroll.left else 0)
180181
c.style.transform = "translate(#{x}px, #{y}px)"
181182
c.style <<< top: 0, left: 0
182183

0 commit comments

Comments
 (0)