fix: stop a sliver of next Monday showing at the edge of the week view

This commit is contained in:
Linus Rath
2026-11-03 05:19:29 +01:00
parent 6c8648109f
commit 38b950b240
2 changed files with 19 additions and 1 deletions
@@ -186,3 +186,20 @@ describe('CalendarWeekView all-day and tasks height cap', () => {
expect(screen.getByRole('button', { name: /events.show_more|events.show_less/ })).toBeInTheDocument();
});
});
describe('CalendarWeekView column width', () => {
afterEach(() => {
cleanup();
vi.restoreAllMocks();
});
// Rounded down, the columns left a few pixels at the edge, where next Monday showed through.
it('fills the pane with exactly seven columns when the width does not divide evenly', () => {
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(1000);
renderView();
const columns = document.querySelector<HTMLElement>('[style*="grid-template-columns"]')!;
const colWidth = parseFloat(/([\d.]+)px/.exec(columns.style.gridTemplateColumns)![1]);
// 1000px less the 56px hour gutter
expect(colWidth * 7).toBeCloseTo(944, 1);
});
});
+2 -1
View File
@@ -152,7 +152,8 @@ export function CalendarWeekView({
const measureColWidth = useCallback((root: HTMLElement | null) => {
if (isMobile || !root) return MOBILE_COL_WIDTH;
return Math.max(MIN_COL_WIDTH, Math.floor((root.clientWidth - gutterWidth) / columnsPerWeek));
// Not rounded down: the pixels left over showed a sliver of next Monday at the edge.
return Math.max(MIN_COL_WIDTH, (root.clientWidth - gutterWidth) / columnsPerWeek);
}, [isMobile, gutterWidth, columnsPerWeek]);
const [colWidth, setColWidth] = useState(MOBILE_COL_WIDTH);
const [viewportWidth, setViewportWidth] = useState(0);