Skip to content

Commit

Permalink
Fix: UI jumps when open calendar then scroll from the view and click …
Browse files Browse the repository at this point in the history
…outside
  • Loading branch information
zzz1ck committed Oct 21, 2024
1 parent 939b797 commit ca91368
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reedsy/vuejs-datepicker",
"version": "1.6.2-reedsy-2.1.8",
"version": "1.6.2-reedsy-2.1.9",
"description": "A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations",
"keywords": [
"vue",
Expand Down
2 changes: 2 additions & 0 deletions src/components/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ import PickerYear from './PickerYear.vue';
import utils, { makeDateUtils } from '../utils/DateUtils';
import { ELEMENT_IDS } from '../config/ElementIds';
import { getFocusableChildren } from '../utils/FocusableElements';
import { isElementInViewport } from '../utils/IsElementInViewport';
export default {
name: 'DatePicker',
components: {
Expand Down Expand Up @@ -603,6 +604,7 @@ export default {
if (!input) return;
const inputEl = input.$el.querySelector('input');
if (!inputEl) return;
if (!isElementInViewport(inputEl)) return;
inputEl.focus();
}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/IsElementInViewport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}

0 comments on commit ca91368

Please sign in to comment.