Skip to content
Merged
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
44 changes: 14 additions & 30 deletions src/components/DateInput/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../utils/date';
import { Input, type InputProps } from '../Input';
import { Calendar } from 'lucide-react';
import { useAnchoredPosition } from '../../hooks/useAnchoredPosition';

export type DateInputMode =
| 'default'
Expand Down Expand Up @@ -322,34 +323,17 @@ const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(

// Calendar picker state
const [isCalendarOpen, setIsCalendarOpen] = React.useState(false);
const calendarRef = React.useRef<HTMLDivElement>(null);
const buttonRef = React.useRef<HTMLButtonElement>(null);
const [calendarStyle, setCalendarStyle] =
React.useState<React.CSSProperties>();

const updateCalendarPosition = React.useCallback(() => {
if (!buttonRef.current) return;

const rect = buttonRef.current.getBoundingClientRect();
setCalendarStyle({
position: 'fixed',
top: rect.bottom + 4,
left: Math.max(8, rect.right - 288),
zIndex: 9999,
});
}, []);

React.useEffect(() => {
if (!isCalendarOpen) return;

updateCalendarPosition();
window.addEventListener('scroll', updateCalendarPosition, true);
window.addEventListener('resize', updateCalendarPosition);
return () => {
window.removeEventListener('scroll', updateCalendarPosition, true);
window.removeEventListener('resize', updateCalendarPosition);
};
}, [isCalendarOpen, updateCalendarPosition]);
// Portal + fixed positioning so the calendar escapes overflow-hidden
// ancestors, flips vertically, and clamps to the viewport.
const {
anchorRef: buttonRef,
floatingRef: calendarRef,
style: calendarStyle,
} = useAnchoredPosition<HTMLButtonElement, HTMLDivElement>({
open: isCalendarOpen,
placement: 'bottom-end',
});

// Parse current value into date parts for calendar
const parsedDate = React.useMemo(() => {
Expand Down Expand Up @@ -484,7 +468,7 @@ const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(
return () =>
document.removeEventListener('mousedown', handleClickOutside);
}
}, [isCalendarOpen]);
}, [isCalendarOpen, buttonRef, calendarRef]);

// Close on Escape key
React.useEffect(() => {
Expand All @@ -499,7 +483,7 @@ const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(
document.addEventListener('keydown', handleEscape);
return () => document.removeEventListener('keydown', handleEscape);
}
}, [isCalendarOpen]);
}, [isCalendarOpen, buttonRef]);

const handleDateSelect = (day: number) => {
if (!isCalendarDateInRange(day)) return;
Expand Down Expand Up @@ -617,7 +601,7 @@ const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(
ref={calendarRef}
className={cn(
'bg-background border-border rounded-lg border shadow-lg',
'w-72 p-3'
'w-72 overflow-auto p-3'
)}
style={calendarStyle}
role="dialog"
Expand Down
2 changes: 2 additions & 0 deletions src/tailwind-preset.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ module.exports = {
// SchedulePicker / overflow handling
'overflow-x-auto',
'overflow-hidden',
// Scrollable floating panels (DateInput calendar, Autocomplete, Select, Table, ScrollArea, …)
'overflow-auto',
// Select component
'truncate',
],
Expand Down
2 changes: 2 additions & 0 deletions src/tailwind-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ export const miewebUISafelist = [
// SchedulePicker / overflow handling
'overflow-x-auto',
'overflow-hidden',
// Scrollable floating panels (DateInput calendar, Autocomplete, Select, Table, ScrollArea, …)
'overflow-auto',
// Select component
'truncate',
// AIReconciliationPanel
Expand Down
Loading