🩹(react) fix DateRangePicker layout overflow

Resolved a width conflict in the date range picker where the field width
conflicted with the component's min-width. This caused content
overflow in the field container, resulting in layout issues.
This commit is contained in:
Lebaud Antoine
2024-01-14 21:32:08 +01:00
committed by NathanVss
parent f685abb36c
commit 9795b7184b
5 changed files with 40 additions and 13 deletions

View File

@@ -0,0 +1,5 @@
---
"@openfun/cunningham-react": patch
---
fix DateRangePicker layout overflow

View File

@@ -46,6 +46,7 @@ export type DatePickerAuxProps = PropsWithChildren &
isFocused: boolean; isFocused: boolean;
labelAsPlaceholder: boolean; labelAsPlaceholder: boolean;
optionalClassName?: string; optionalClassName?: string;
isRange?: boolean;
onClear: () => void; onClear: () => void;
}; };
@@ -67,6 +68,7 @@ const DatePickerAux = forwardRef(
locale, locale,
disabled = false, disabled = false,
optionalClassName, optionalClassName,
isRange,
...props ...props
}: DatePickerAuxProps, }: DatePickerAuxProps,
ref: Ref<HTMLDivElement>, ref: Ref<HTMLDivElement>,
@@ -82,7 +84,12 @@ const DatePickerAux = forwardRef(
return ( return (
<I18nProvider locale={locale || currentLocale}> <I18nProvider locale={locale || currentLocale}>
<Field {...props}> <Field
{...props}
className={classNames({
"c__date-picker__range__container": isRange,
})}
>
<div <div
ref={pickerRef} ref={pickerRef}
className={classNames(["c__date-picker", optionalClassName], { className={classNames(["c__date-picker", optionalClassName], {

View File

@@ -80,6 +80,7 @@ export const DateRangePicker = ({
pickerState, pickerState,
pickerProps, pickerProps,
optionalClassName: "c__date-picker__range", optionalClassName: "c__date-picker__range",
isRange: true,
onClear: () => { onClear: () => {
pickerState.setValue({ pickerState.setValue({
start: null as unknown as DateValue, start: null as unknown as DateValue,

View File

@@ -221,7 +221,12 @@
} }
&__range { &__range {
min-width: px-to-rem(350px); $component-min-width: px-to-rem(350px);
min-width: $component-min-width;
&__container {
min-width: $component-min-width;
}
&__separator { &__separator {
background-color: var(--c--theme--colors--greyscale-400); background-color: var(--c--theme--colors--greyscale-400);

View File

@@ -189,17 +189,26 @@ export const RangeControlled = () => {
"2023-06-23T13:37:00.000+02:00", "2023-06-23T13:37:00.000+02:00",
]); ]);
return ( return (
<div> <>
<div className="clr-greyscale-900">Value: {value?.join(" ")}</div> <div className="clr-greyscale-900">Value: {value?.join(" ")}</div>
<DateRangePicker <div
startLabel="Start date" style={{
endLabel="Due date" display: "flex",
minValue="2023-01-23T00:00:00.000+00:00" alignItems: "center",
maxValue="2023-08-23T00:00:00.000+00:00" gap: "1rem",
value={value} marginTop: "1rem",
onChange={(e) => setValue(e)} }}
/> >
<Button onClick={() => setValue(null)}>Reset</Button> <DateRangePicker
</div> startLabel="Start date"
endLabel="Due date"
minValue="2023-01-23T00:00:00.000+00:00"
maxValue="2023-08-23T00:00:00.000+00:00"
value={value}
onChange={(e) => setValue(e)}
/>
<Button onClick={() => setValue(null)}>Reset</Button>
</div>
</>
); );
}; };