Skip to content

Commit 76ac436

Browse files
committed
Move min and max dates out of usePlainDateState
1 parent 67cb882 commit 76ac436

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

packages/circuit-ui/components/DateInput/DateInput.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
FieldWrapper,
4949
} from '../Field/Field.js';
5050
import { getBrowserLocale } from '../../util/i18n.js';
51+
import { toPlainDate } from '../../util/date.js';
5152

5253
import { Dialog } from './components/Dialog.js';
5354
import { DateSegment } from './components/DateSegment.js';
@@ -190,14 +191,16 @@ export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
190191
const validationHintId = useId();
191192

192193
const descriptionIds = clsx(descriptionId, validationHintId);
194+
const minDate = toPlainDate(min);
195+
const maxDate = toPlainDate(max);
193196

194197
const focus = useSegmentFocus();
195198
const state = usePlainDateState({
196199
value,
197200
defaultValue,
198201
onChange,
199-
min,
200-
max,
202+
minDate,
203+
maxDate,
201204
locale,
202205
});
203206

@@ -482,8 +485,8 @@ export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
482485
className={classes.calendar}
483486
onSelect={handleSelect}
484487
selection={selection}
485-
minDate={state.minDate}
486-
maxDate={state.maxDate}
488+
minDate={minDate}
489+
maxDate={maxDate}
487490
locale={locale}
488491
firstDayOfWeek={firstDayOfWeek}
489492
modifiers={modifiers}

packages/circuit-ui/components/DateInput/hooks/usePlainDateState.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ type DateValues = {
3838
day: DateValue;
3939
};
4040

41-
type PlainDateState = {
41+
export type PlainDateState = {
4242
date: Temporal.PlainDate | undefined;
43-
minDate: Temporal.PlainDate | undefined;
44-
maxDate: Temporal.PlainDate | undefined;
4543
update: (values: Partial<DateValues>) => void;
4644
props: {
4745
year: Omit<DateSegmentProps, 'focus'>;
@@ -54,15 +52,15 @@ export function usePlainDateState({
5452
value,
5553
defaultValue,
5654
onChange,
57-
min,
58-
max,
55+
minDate,
56+
maxDate,
5957
locale,
6058
}: {
6159
value: string | undefined;
6260
defaultValue: string | undefined;
6361
onChange: ((date: string) => void) | undefined;
64-
min: string | undefined;
65-
max: string | undefined;
62+
minDate: Temporal.PlainDate | undefined;
63+
maxDate: Temporal.PlainDate | undefined;
6664
locale: Locale | undefined;
6765
}): PlainDateState {
6866
const [values, setValues] = useState<DateValues>(
@@ -110,8 +108,6 @@ export function usePlainDateState({
110108

111109
const date = safePlainDate(values.year, values.month, values.day);
112110
const today = getTodaysDate();
113-
const minDate = toPlainDate(min);
114-
const maxDate = toPlainDate(max);
115111

116112
const sameYearLimit = minDate && maxDate && minDate.year === maxDate.year;
117113
const sameMonthLimit = sameYearLimit && minDate.month === maxDate.month;
@@ -158,7 +154,7 @@ export function usePlainDateState({
158154
},
159155
};
160156

161-
return { date, minDate, maxDate, update, props };
157+
return { date, update, props };
162158
}
163159

164160
function parseValue(value?: string): DateValues {

0 commit comments

Comments
 (0)