Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding disabled state for datepicker, resolves #180 #181

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/Datepicker/DatepickerRangeInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ describe('DatepickerRangeInput', () => {
expect(render(<DatepickerRangeInput />).container).toMatchSnapshot();
});

it('can be disabled', () => {
const { getAllByRole } = render(<DatepickerRangeInput disabled />);
const inputs = getAllByRole('textbox');
expect(inputs).toHaveLength(2);
inputs.forEach(input => {
expect(input).toBeDisabled();
});
});

describe('should call onClose function', () => {
it('when clicking outside', async () => {
const mockCloseHandler = jest.fn();
Expand Down
7 changes: 7 additions & 0 deletions src/components/Datepicker/DatepickerRangeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ interface DatepickerRangeInputProps extends MarginProps, WidthProps {
* @default 'normal'
*/
variant?: 'compact' | 'normal';
/**
* Determines whether the datePicker is disabled or not
*/
disabled?: boolean;
}

interface DateRangeInputText {
Expand Down Expand Up @@ -217,6 +221,7 @@ const DatepickerRangeInput: FC<DatepickerRangeInputProps> = ({
startInputId,
endInputId,
variant = 'normal',
disabled,
...rest
}: DatepickerRangeInputProps) => {
const localeObject = useLocaleObject(locale);
Expand Down Expand Up @@ -350,6 +355,7 @@ const DatepickerRangeInput: FC<DatepickerRangeInputProps> = ({
width="100%"
onChange={handleStartDateInputChange}
data-error={error.startDate}
disabled={disabled}
/>
{focusedInput === START_DATE && <StartDateFocusedBlock />}
<DateArrow color={Colors.AUTHENTIC_BLUE_550} />
Expand All @@ -367,6 +373,7 @@ const DatepickerRangeInput: FC<DatepickerRangeInputProps> = ({
onChange={handleEndDateInputChange}
width="100%"
data-error={error.endDate}
disabled={disabled}
/>
{focusedInput === END_DATE && <EndDateFocusedBlock />}
</DateRangeWrapper>
Expand Down
6 changes: 6 additions & 0 deletions src/components/Datepicker/DatepickerSingleInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('DatepickerSingleInput', () => {
expect(render(<DatepickerSingleInput />).container).toMatchSnapshot();
});

it('can be disabled', () => {
const { getByRole } = render(<DatepickerSingleInput disabled />);
const input = getByRole('textbox');
expect(input).toBeDisabled();
});

describe('should call onClose function', () => {
it('when clicking outside', async () => {
const mockCloseHandler = jest.fn();
Expand Down
6 changes: 6 additions & 0 deletions src/components/Datepicker/DatepickerSingleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ interface DatepickerSingleInputProps extends MarginProps, WidthProps {
* The id to be assigned to the input field
*/
inputId?: string;
/**
* Determines whether the datePicker is disabled or not
*/
disabled?: boolean;
snapsnapturtle marked this conversation as resolved.
Show resolved Hide resolved
}

const DatepickerSingleInput: FC<DatepickerSingleInputProps> = ({
Expand All @@ -87,6 +91,7 @@ const DatepickerSingleInput: FC<DatepickerSingleInputProps> = ({
value,
errorHandler,
inputId,
disabled,
...rest
}: DatepickerSingleInputProps) => {
const localeObject = useLocaleObject(locale);
Expand Down Expand Up @@ -174,6 +179,7 @@ const DatepickerSingleInput: FC<DatepickerSingleInputProps> = ({
onBlur={handleDatepickerClose}
onChange={handleDateTextChange}
data-error={error}
disabled={disabled}
{...rest}
/>
{displayErrorMessage && error && !isFocused && (
Expand Down