Skip to content

Commit 4495a39

Browse files
Merge pull request #45 from reedsy/fix-chromium-crash
Fix Chromium browsers crash
2 parents 3cd6c63 + d09e364 commit 4495a39

File tree

3 files changed

+65
-59
lines changed

3 files changed

+65
-59
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reedsy/vuejs-datepicker",
3-
"version": "1.6.2-reedsy-2.1.9",
3+
"version": "1.6.2-reedsy-2.1.10",
44
"description": "A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations",
55
"keywords": [
66
"vue",

src/components/Datepicker.vue

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ import PickerYear from './PickerYear.vue';
168168
import utils, { makeDateUtils } from '../utils/DateUtils';
169169
import { ELEMENT_IDS } from '../config/ElementIds';
170170
import { getFocusableChildren } from '../utils/FocusableElements';
171-
import { isElementInViewport } from '../utils/IsElementInViewport';
171+
// TODO: reenable later if Chromium-based browsers issue is fixed
172+
// import { isElementInViewport } from '../utils/IsElementInViewport';
172173
export default {
173174
name: 'DatePicker',
174175
components: {
@@ -598,17 +599,21 @@ export default {
598599
599600
if (this.isInline) return;
600601
601-
if (emitEvent) {
602-
this.$emit('closed');
603-
const input = this.$refs.input;
604-
if (!input) return;
605-
const inputEl = input.$el.querySelector('input');
606-
if (!inputEl) return;
607-
if (!isElementInViewport(inputEl)) return;
608-
inputEl.focus();
609-
}
610-
611602
document.removeEventListener('click', this.clickOutside, false);
603+
604+
if (emitEvent) this.$emit('closed');
605+
606+
// This causes the current Chrome/Chromium-based browsers
607+
// version to crash on macOS Sonoma
608+
//
609+
// TODO: reevaluate and test on newer versions
610+
//
611+
// const input = this.$refs.input;
612+
// if (!input) return;
613+
// const inputEl = input.$el.querySelector('input');
614+
// if (!inputEl) return;
615+
// if (!isElementInViewport(inputEl)) return;
616+
// inputEl.focus();
612617
},
613618
/**
614619
* Initiate the component

test/unit/specs/Datepicker/Datepicker.spec.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -424,53 +424,54 @@ describe('Focus after opening the datepicker', () => {
424424
});
425425
});
426426

427-
describe('Focus after closing the datepicker', () => {
428-
it('should focus on the input', async () => {
429-
const wrapper = mount(Datepicker, { attachTo: document.body });
430-
await wrapper.vm.showCalendar();
431-
wrapper.vm.close(true);
432-
const input = wrapper.vm.$refs.input.$el.querySelector('input');
433-
expect(document.activeElement).toEqual(input);
434-
});
435-
describe('after scrolling and clicking outside', () => {
436-
let wrapper;
437-
let originalGetBoundingClientRect;
438-
beforeEach(() => {
439-
wrapper = mount(Datepicker, { attachTo: document.body });
440-
originalGetBoundingClientRect = Element.prototype.getBoundingClientRect;
441-
});
442-
afterEach(() => {
443-
Element.prototype.getBoundingClientRect = originalGetBoundingClientRect;
444-
wrapper.unmount();
445-
});
446-
447-
it('should focus on the input when it is in viewport', async () => {
448-
Element.prototype.getBoundingClientRect = jest.fn(() => ({
449-
top: 100,
450-
bottom: 0,
451-
left: 0,
452-
right: 0,
453-
}));
454-
await wrapper.vm.showCalendar();
455-
wrapper.vm.clickOutside({ target: document.body });
456-
const input = wrapper.vm.$refs.input.$el.querySelector('input');
457-
expect(document.activeElement).toEqual(input);
458-
});
459-
460-
it('should not focus on the input when it is out of viewport', async () => {
461-
Element.prototype.getBoundingClientRect = jest.fn(() => ({
462-
top: -100,
463-
bottom: 0,
464-
left: 0,
465-
right: 0,
466-
}));
467-
await wrapper.vm.showCalendar();
468-
wrapper.vm.clickOutside({ target: document.body });
469-
const input = wrapper.vm.$refs.input.$el.querySelector('input');
470-
expect(document.activeElement).not.toEqual(input);
471-
});
472-
});
473-
});
427+
// TODO: reenable later if Chromium-based browsers issue is fixed
428+
// describe('Focus after closing the datepicker', () => {
429+
// it('should focus on the input', async () => {
430+
// const wrapper = mount(Datepicker, { attachTo: document.body });
431+
// await wrapper.vm.showCalendar();
432+
// wrapper.vm.close(true);
433+
// const input = wrapper.vm.$refs.input.$el.querySelector('input');
434+
// expect(document.activeElement).toEqual(input);
435+
// });
436+
// describe('after scrolling and clicking outside', () => {
437+
// let wrapper;
438+
// let originalGetBoundingClientRect;
439+
// beforeEach(() => {
440+
// wrapper = mount(Datepicker, { attachTo: document.body });
441+
// originalGetBoundingClientRect = Element.prototype.getBoundingClientRect;
442+
// });
443+
// afterEach(() => {
444+
// Element.prototype.getBoundingClientRect = originalGetBoundingClientRect;
445+
// wrapper.unmount();
446+
// });
447+
448+
// it('should focus on the input when it is in viewport', async () => {
449+
// Element.prototype.getBoundingClientRect = jest.fn(() => ({
450+
// top: 100,
451+
// bottom: 0,
452+
// left: 0,
453+
// right: 0,
454+
// }));
455+
// await wrapper.vm.showCalendar();
456+
// wrapper.vm.clickOutside({ target: document.body });
457+
// const input = wrapper.vm.$refs.input.$el.querySelector('input');
458+
// expect(document.activeElement).toEqual(input);
459+
// });
460+
461+
// it('should not focus on the input when it is out of viewport', async () => {
462+
// Element.prototype.getBoundingClientRect = jest.fn(() => ({
463+
// top: -100,
464+
// bottom: 0,
465+
// left: 0,
466+
// right: 0,
467+
// }));
468+
// await wrapper.vm.showCalendar();
469+
// wrapper.vm.clickOutside({ target: document.body });
470+
// const input = wrapper.vm.$refs.input.$el.querySelector('input');
471+
// expect(document.activeElement).not.toEqual(input);
472+
// });
473+
// });
474+
// });
474475

475476
describe('Modal', () => {
476477
it('closes the datepicker if clicked on overlay', async () => {

0 commit comments

Comments
 (0)