Skip to content

Commit 21eeca5

Browse files
committed
fix(date-field): multivalue calendar positioning #24
1 parent 0d04f75 commit 21eeca5

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

src/tedi/components/form/date-field/date-field.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
FloatingFocusManager,
55
FloatingPortal,
66
offset,
7+
shift,
78
useClick,
89
useDismiss,
910
useFloating,
@@ -18,7 +19,7 @@ import { et } from 'react-day-picker/locale';
1819
import { UnknownType } from '../../../types/commonTypes';
1920
import { Calendar } from '../../content/calendar/calendar';
2021
import MultiValueField, { MultiValueFieldProps } from '../multi-value-field/multi-value-field';
21-
import TextField, { TextFieldForwardRef, TextFieldProps } from '../textfield/textfield';
22+
import TextField, { TextFieldProps } from '../textfield/textfield';
2223
import styles from './date-field.module.scss';
2324

2425
const CALENDAR_OFFSET = 4;
@@ -284,7 +285,7 @@ export const DateField: React.FC<DateFieldProps> = ({
284285
open,
285286
onOpenChange: setOpen,
286287
placement: calendarTrigger === 'input' ? 'bottom-start' : 'bottom-end',
287-
middleware: [offset(CALENDAR_OFFSET), flip()],
288+
middleware: [offset(CALENDAR_OFFSET), flip(), shift()],
288289
whileElementsMounted: autoUpdate,
289290
});
290291

@@ -387,25 +388,17 @@ export const DateField: React.FC<DateFieldProps> = ({
387388
if (shouldDisableMonth) disabledMatchers.push((date: Date) => shouldDisableMonth(date));
388389
if (shouldDisableYear) disabledMatchers.push((date: Date) => shouldDisableYear(date));
389390

390-
const textFieldRef = React.useRef<TextFieldForwardRef>(null);
391-
392-
useEffect(() => {
393-
if (textFieldRef.current?.input) {
394-
refs.setReference(textFieldRef.current.input);
395-
}
396-
}, [refs]);
397-
398391
return (
399392
<>
400393
<div
401394
className={cn(styles['tedi-date-field__container'], className)}
402395
{...interactions.getReferenceProps()}
403396
aria-haspopup="dialog"
397+
ref={refs.setReference}
404398
>
405399
{mode === 'multiple' ? (
406400
<MultiValueField
407401
{...(inputProps as MultiValueFieldProps)}
408-
ref={textFieldRef}
409402
id={id}
410403
label={label}
411404
readOnly={readOnly ?? (parseDate ? false : enableCalendar)}
@@ -430,7 +423,6 @@ export const DateField: React.FC<DateFieldProps> = ({
430423
) : (
431424
<TextField
432425
{...(inputProps as TextFieldProps)}
433-
ref={textFieldRef}
434426
id={id}
435427
label={label}
436428
readOnly={readOnly ?? (parseDate ? false : enableCalendar)}

src/tedi/components/form/multi-value-field/multi-value-field.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.tedi-multi-value-field > div {
2+
position: relative;
23
box-sizing: border-box;
34
display: block;
45
width: 100%;

0 commit comments

Comments
 (0)