From b1315d7cb0d620e8eb010f96e9716fe78670f399 Mon Sep 17 00:00:00 2001 From: Ryan DeBeasi Date: Mon, 1 Aug 2022 14:06:30 -0400 Subject: [PATCH] Add moveFocusToCalendar parameter to show() --- README.md | 5 +++-- .../duet-date-picker/duet-date-picker.tsx | 13 ++++++++----- src/components/duet-date-picker/readme.md | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 43f2bea..fd8a4b6 100644 --- a/README.md +++ b/README.md @@ -155,9 +155,10 @@ Sets focus on the date picker's input. Use this method instead of the global `fo Type: `Promise` -### `show() => Promise` +### `show(moveFocusToCalendar?: boolean) => Promise` -Show the calendar modal, moving focus to the calendar inside. +Show the calendar modal. Set `moveFocusToCalendar` to false to prevent +the focus from moving to the calendar. Default is true. #### Returns diff --git a/src/components/duet-date-picker/duet-date-picker.tsx b/src/components/duet-date-picker/duet-date-picker.tsx index ad1d811..6bc99d3 100644 --- a/src/components/duet-date-picker/duet-date-picker.tsx +++ b/src/components/duet-date-picker/duet-date-picker.tsx @@ -311,17 +311,20 @@ export class DuetDatePicker implements ComponentInterface { } /** - * Show the calendar modal, moving focus to the calendar inside. + * Show the calendar modal. Set `moveFocusToCalendar` to false to prevent + * the focus from moving to the calendar. Default is true. */ - @Method() async show() { + @Method() async show(moveFocusToCalendar = true) { this.open = true this.duetOpen.emit({ component: "duet-date-picker", }) - this.setFocusedDay(parseISODate(this.value) || new Date()) - clearTimeout(this.focusTimeoutId) - this.focusTimeoutId = setTimeout(() => this.monthSelectNode.focus(), TRANSITION_MS) + this.setFocusedDay(parseISODate(this.value) || new Date()) + if (moveFocusToCalendar) { + clearTimeout(this.focusTimeoutId) + this.focusTimeoutId = setTimeout(() => this.monthSelectNode.focus(), TRANSITION_MS) + } } /** diff --git a/src/components/duet-date-picker/readme.md b/src/components/duet-date-picker/readme.md index c5bd4db..2b25acd 100644 --- a/src/components/duet-date-picker/readme.md +++ b/src/components/duet-date-picker/readme.md @@ -58,9 +58,10 @@ Type: `Promise` -### `show() => Promise` +### `show(moveFocusToCalendar?: boolean) => Promise` -Show the calendar modal, moving focus to the calendar inside. +Show the calendar modal. Set `moveFocusToCalendar` to false to prevent +the focus from moving to the calendar. Default is true. #### Returns