Skip to content

Commit e2ee8de

Browse files
committed
fix(datepicker): Resolve bug for when `append-to-body = true
1 parent 47cde8f commit e2ee8de

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/components/Datepicker.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
:class="pickerClasses"
6868
data-test-calendar
6969
@mousedown.prevent
70+
@focusin.stop="handleFocusIn($event)"
71+
@focusout.stop="handleFocusOut($event)"
72+
@keydown.esc.stop="clearDate"
73+
@keydown.tab.stop="tabThroughNavigation($event)"
7074
>
7175
<Transition name="view">
7276
<div ref="view" :key="view">

src/mixins/navMixin.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ export default {
363363
*/
364364
setAllElements() {
365365
this.allElements = this.getFocusableElements(this.$refs.datepicker)
366+
367+
if (this.appendToBody) {
368+
this.allElements = this.allElements.concat(
369+
this.getFocusableElements(this.$refs.popup.$el),
370+
)
371+
}
366372
},
367373
/**
368374
* Set the focus

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@ describe('Datepicker mounted to body', () => {
225225
expect(document.activeElement).toStrictEqual(todayCell.element)
226226
})
227227

228+
it("focuses today's date when append-to-body is true", async () => {
229+
await wrapper.setProps({
230+
appendToBody: true,
231+
})
232+
233+
const input = wrapper.find('input')
234+
await input.trigger('click')
235+
jest.advanceTimersByTime(250)
236+
const todayCell = wrapper.find('button.today')
237+
238+
expect(todayCell.text()).toBe(new Date().getDate().toString())
239+
expect(document.activeElement).toStrictEqual(todayCell.element)
240+
})
241+
228242
it('focuses the up button on increasing the view', async () => {
229243
const input = wrapper.find('input')
230244
await input.trigger('click')

0 commit comments

Comments
 (0)