Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Add moveFocusToCalendar parameter to show() #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ Sets focus on the date picker's input. Use this method instead of the global `fo

Type: `Promise<void>`

### `show() => Promise<void>`
### `show(moveFocusToCalendar?: boolean) => Promise<void>`

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

Expand Down
13 changes: 8 additions & 5 deletions src/components/duet-date-picker/duet-date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/components/duet-date-picker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ Type: `Promise<void>`



### `show() => Promise<void>`
### `show(moveFocusToCalendar?: boolean) => Promise<void>`

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

Expand Down