Skip to content

Commit add89fb

Browse files
committed
feat: Add support for 'disabled' prop to the DatePicker component
1 parent 07fd0f5 commit add89fb

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/DatePicker/DatePicker.story.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ WithCustomDateFormat.story = {
4747
name: "with custom date format",
4848
};
4949

50+
export const WithDisabled = () => (
51+
<DatePicker
52+
selected={select("selected", selectedDateExamples, selectedDateExamples[0], "selected")}
53+
disabled={true}
54+
/>
55+
);
56+
57+
WithDisabled.story = {
58+
name: "with disabled",
59+
};
60+
5061
export const WithDifferentSizes = () => (
5162
<Flex gap="x2" alignItems="flex-start">
5263
<DatePicker

src/DatePicker/DatePicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface DatePickerProps extends Omit<FieldProps, OmittedFieldProps> {
3333
highlightDates?: ReactDatePickerProps["highlightDates"];
3434
disableFlipping?: boolean;
3535
selected?: Date | null;
36+
disabled?: boolean;
3637
}
3738

3839
const DEFAULT_DATE_FORMAT = "yyyy-MMM-dd";
@@ -56,6 +57,7 @@ const DatePicker = forwardRef<unknown, DatePickerProps>(
5657
onBlur,
5758
onFocus,
5859
selected,
60+
disabled,
5961
...props
6062
},
6163
datePickerRef
@@ -128,6 +130,7 @@ const DatePicker = forwardRef<unknown, DatePickerProps>(
128130

129131
const customInput = (
130132
<DatePickerInput
133+
disabled={disabled}
131134
size={componentSize}
132135
inputProps={customInputProps}
133136
dateFormat={dateFormat}
@@ -147,6 +150,7 @@ const DatePicker = forwardRef<unknown, DatePickerProps>(
147150
{({ locale }) => (
148151
<ReactDatePicker
149152
selected={selectedDate}
153+
disabled={disabled}
150154
openToDate={selectedDate}
151155
dateFormat={dateFormat}
152156
onChange={handleSelectedDateChange}

src/DatePicker/DatePickerInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type DatePickerInputProps = Omit<React.ComponentPropsWithRef<"input">, "size"> &
2020
const DatePickerInput = forwardRef<HTMLInputElement, DatePickerInputProps>(
2121
(
2222
{
23+
disabled,
2324
onChange,
2425
onClick,
2526
onBlur,
@@ -37,6 +38,7 @@ const DatePickerInput = forwardRef<HTMLInputElement, DatePickerInputProps>(
3738
) => {
3839
const { t } = useTranslation();
3940
const { placeholder, ...inputFieldProps } = inputProps;
41+
inputFieldProps.disabled = disabled;
4042

4143
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
4244
onInputChange(event);
@@ -62,6 +64,7 @@ const DatePickerInput = forwardRef<HTMLInputElement, DatePickerInputProps>(
6264

6365
return (
6466
<InputField
67+
disabled={disabled}
6568
onBlur={onBlur}
6669
onFocus={onFocus}
6770
ref={ref}

0 commit comments

Comments
 (0)