Skip to content

Commit f3759a6

Browse files
Merge 313f424 into next
2 parents ce72559 + 313f424 commit f3759a6

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/components/Datepicker/DatepickerRangeInput.spec.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ describe('DatepickerRangeInput', () => {
3838
expect(render(<DatepickerRangeInput />).container).toMatchSnapshot();
3939
});
4040

41+
it('can be disabled', () => {
42+
const { getAllByRole } = render(<DatepickerRangeInput disabled />);
43+
const inputs = getAllByRole('textbox');
44+
expect(inputs).toHaveLength(2);
45+
inputs.forEach(input => {
46+
expect(input).toBeDisabled();
47+
});
48+
});
49+
4150
describe('should call onClose function', () => {
4251
it('when clicking outside', async () => {
4352
const mockCloseHandler = jest.fn();

src/components/Datepicker/DatepickerRangeInput.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ interface DatepickerRangeInputProps extends MarginProps, WidthProps {
168168
* @default 'normal'
169169
*/
170170
variant?: 'compact' | 'normal';
171+
/**
172+
* Determines whether the datePicker is disabled or not
173+
*/
174+
disabled?: boolean;
171175
}
172176

173177
interface DateRangeInputText {
@@ -217,6 +221,7 @@ const DatepickerRangeInput: FC<DatepickerRangeInputProps> = ({
217221
startInputId,
218222
endInputId,
219223
variant = 'normal',
224+
disabled,
220225
...rest
221226
}: DatepickerRangeInputProps) => {
222227
const localeObject = useLocaleObject(locale);
@@ -350,9 +355,10 @@ const DatepickerRangeInput: FC<DatepickerRangeInputProps> = ({
350355
width="100%"
351356
onChange={handleStartDateInputChange}
352357
data-error={error.startDate}
358+
disabled={disabled}
353359
/>
354360
{focusedInput === START_DATE && <StartDateFocusedBlock />}
355-
<DateArrow color={Colors.AUTHENTIC_BLUE_550} />
361+
<DateArrow color={disabled ? Colors.AUTHENTIC_BLUE_200 : Colors.AUTHENTIC_BLUE_550} />
356362
<Input
357363
id={endId}
358364
ref={endDateRef}
@@ -367,6 +373,7 @@ const DatepickerRangeInput: FC<DatepickerRangeInputProps> = ({
367373
onChange={handleEndDateInputChange}
368374
width="100%"
369375
data-error={error.endDate}
376+
disabled={disabled}
370377
/>
371378
{focusedInput === END_DATE && <EndDateFocusedBlock />}
372379
</DateRangeWrapper>

src/components/Datepicker/DatepickerSingleInput.spec.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('DatepickerSingleInput', () => {
2020
expect(render(<DatepickerSingleInput />).container).toMatchSnapshot();
2121
});
2222

23+
it('can be disabled', () => {
24+
const { getByRole } = render(<DatepickerSingleInput disabled />);
25+
const input = getByRole('textbox');
26+
expect(input).toBeDisabled();
27+
});
28+
2329
describe('should call onClose function', () => {
2430
it('when clicking outside', async () => {
2531
const mockCloseHandler = jest.fn();

src/components/Datepicker/DatepickerSingleInput.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ interface DatepickerSingleInputProps extends MarginProps, WidthProps {
7171
* The id to be assigned to the input field
7272
*/
7373
inputId?: string;
74+
/**
75+
* Determines whether the datePicker is disabled or not
76+
*/
77+
disabled?: boolean;
7478
}
7579

7680
const DatepickerSingleInput: FC<DatepickerSingleInputProps> = ({
@@ -87,6 +91,7 @@ const DatepickerSingleInput: FC<DatepickerSingleInputProps> = ({
8791
value,
8892
errorHandler,
8993
inputId,
94+
disabled,
9095
...rest
9196
}: DatepickerSingleInputProps) => {
9297
const localeObject = useLocaleObject(locale);
@@ -174,6 +179,7 @@ const DatepickerSingleInput: FC<DatepickerSingleInputProps> = ({
174179
onBlur={handleDatepickerClose}
175180
onChange={handleDateTextChange}
176181
data-error={error}
182+
disabled={disabled}
177183
{...rest}
178184
/>
179185
{displayErrorMessage && error && !isFocused && (

0 commit comments

Comments
 (0)