diff --git a/src/panels/calendar/dialog-calendar-event-editor.ts b/src/panels/calendar/dialog-calendar-event-editor.ts index d673577df5..0997260929 100644 --- a/src/panels/calendar/dialog-calendar-event-editor.ts +++ b/src/panels/calendar/dialog-calendar-event-editor.ts @@ -73,7 +73,11 @@ class DialogCalendarEventEditor extends LitElement { } } else { this._allDay = false; - this._dtstart = startOfHour(new Date()); + // If we have been provided a selected date (e.g. based on the currently displayed + // day in a calendar view), use that as the starting value. + this._dtstart = startOfHour( + params.selectedDate ? params.selectedDate : new Date() + ); this._dtend = addHours(this._dtstart, 1); } } diff --git a/src/panels/calendar/ha-full-calendar.ts b/src/panels/calendar/ha-full-calendar.ts index 5fcde29675..7089b4f97c 100644 --- a/src/panels/calendar/ha-full-calendar.ts +++ b/src/panels/calendar/ha-full-calendar.ts @@ -276,8 +276,19 @@ export class HAFullCalendar extends LitElement { } private _createEvent(_info) { + // Logic for selectedDate: In week and day view, use the start of the week or the selected day. + // If we are in month view, we only use the start of the month, if we are not showing the + // current actual month, as for that one the current day is automatically highlighted and + // defaulting to a different day in the event creation dialog would be weird. showCalendarEventEditDialog(this, { calendars: this._mutableCalendars, + selectedDate: + this._activeView === "dayGridWeek" || + this._activeView === "dayGridDay" || + (this._activeView === "dayGridMonth" && + this.calendar!.view.currentStart.getMonth() !== new Date().getMonth()) + ? this.calendar!.view.currentStart + : undefined, updated: () => { this._fireViewChanged(); }, diff --git a/src/panels/calendar/show-dialog-calendar-event-detail.ts b/src/panels/calendar/show-dialog-calendar-event-detail.ts index 902e8746b6..9946ed9bdb 100644 --- a/src/panels/calendar/show-dialog-calendar-event-detail.ts +++ b/src/panels/calendar/show-dialog-calendar-event-detail.ts @@ -2,7 +2,7 @@ import { fireEvent } from "../../common/dom/fire_event"; import { Calendar, CalendarEventData } from "../../data/calendar"; export interface CalendarEventDetailDialogParams { - calendars: Calendar[]; // When creating new events, is the list of events that support creation + calendars: Calendar[]; // When creating new events, is the list of calendar entities that support creation calendarId?: string; entry?: CalendarEventData; canDelete?: boolean; diff --git a/src/panels/calendar/show-dialog-calendar-event-editor.ts b/src/panels/calendar/show-dialog-calendar-event-editor.ts index 695832d164..f2ab58a4f6 100644 --- a/src/panels/calendar/show-dialog-calendar-event-editor.ts +++ b/src/panels/calendar/show-dialog-calendar-event-editor.ts @@ -2,8 +2,9 @@ import { fireEvent } from "../../common/dom/fire_event"; import { Calendar, CalendarEventData } from "../../data/calendar"; export interface CalendarEventEditDialogParams { - calendars: Calendar[]; // When creating new events, is the list of events that support creation + calendars: Calendar[]; // When creating new events, is the list of calendar entities that support creation calendarId?: string; + selectedDate?: Date; // When provided is used as the pre-filled date for the event creation dialog entry?: CalendarEventData; canDelete?: boolean; updated: () => void;