Improves all-day event hover detection

Enhances the all-day event selection by creating transparent, full-height columns for each day, which enables more accurate and reliable hover detection across all-day events.

Now selects all-day events by hovering on the entire column, not just day headers.
This commit is contained in:
Janus Knudsen 2025-09-17 22:08:27 +02:00
parent 3db93a9e89
commit b4af5a9211
3 changed files with 44 additions and 3 deletions

View file

@ -50,11 +50,12 @@ export class HeaderManager {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
// Optimized element detection - only handle day headers // Optimized element detection - handle day headers and all-day columns
const dayHeader = target.closest('swp-day-header'); const dayHeader = target.closest('swp-day-header');
const allDayColumn = target.closest('swp-allday-column');
if (dayHeader) { if (dayHeader || allDayColumn) {
const hoveredElement = dayHeader as HTMLElement; const hoveredElement = (dayHeader || allDayColumn) as HTMLElement;
const targetDate = hoveredElement.dataset.date; const targetDate = hoveredElement.dataset.date;
// Get header renderer for coordination // Get header renderer for coordination

View file

@ -26,12 +26,40 @@ export class AllDayEventRenderer {
if (!this.container) { if (!this.container) {
this.container = document.createElement('swp-allday-container'); this.container = document.createElement('swp-allday-container');
header.appendChild(this.container); header.appendChild(this.container);
// Create ghost columns for mouseenter events
this.createGhostColumns();
} }
} }
} }
return this.container; return this.container;
} }
/**
* Create ghost columns for mouseenter events
*/
private createGhostColumns(): void {
if (!this.container) return;
// Get all day headers to create matching ghost columns
const dayHeaders = document.querySelectorAll('swp-day-header');
dayHeaders.forEach((header, index) => {
const ghostColumn = document.createElement('swp-allday-column');
const headerElement = header as HTMLElement;
// Copy date from corresponding day header
if (headerElement.dataset.date) {
ghostColumn.dataset.date = headerElement.dataset.date;
}
// Set grid column position (1-indexed)
ghostColumn.style.gridColumn = (index + 1).toString();
ghostColumn.style.gridRow = '1 / -1'; // Span all rows
this.container!.appendChild(ghostColumn);
});
}
/** /**
* Render an all-day event using factory pattern * Render an all-day event using factory pattern
*/ */

View file

@ -288,11 +288,23 @@ swp-allday-container {
overflow: hidden; overflow: hidden;
} }
/* Ghost columns for mouseenter events */
swp-allday-column {
position: relative;
opacity: 0; /* Invisible but functional */
pointer-events: auto; /* Enable mouse events */
background: transparent;
z-index: 1; /* Below all-day events */
height: 100%;
}
/* All-day events in containers */ /* All-day events in containers */
swp-allday-event { swp-allday-event {
height: 22px; /* Fixed height for consistent stacking */ height: 22px; /* Fixed height for consistent stacking */
background: #ff9800; /* Default orange background */ background: #ff9800; /* Default orange background */
display: flex; display: flex;
position: relative;
z-index: 2; /* Above ghost columns */
align-items: center; align-items: center;
justify-content: flex-start; justify-content: flex-start;
color: #fff; color: #fff;