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

Allow overriding allowClear #2078

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export type DatePickerProps = {
id?: string;
disabled?: boolean;
labelProps?: LabelProps;
allowClear?: boolean;
[key: string]: any;
};

Expand Down
13 changes: 10 additions & 3 deletions src/components/DatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const DatePicker = forwardRef(
value,
labelProps,
required = false,
allowClear = true,
...otherProps
},
ref
Expand Down Expand Up @@ -149,9 +150,11 @@ const DatePicker = forwardRef(
suffixIcon={<Calendar size={16} />}
superNextIcon={<IconOverride icon={Right} />}
superPrevIcon={<IconOverride icon={Left} />}
allowClear={{
clearIcon: <Close data-cy="date-time-clear-icon" size={16} />,
}}
allowClear={
allowClear && {
clearIcon: <Close data-cy="date-time-clear-icon" size={16} />,
}
}
/>
{!!error && typeof error === "string" && (
<p
Expand Down Expand Up @@ -244,6 +247,10 @@ DatePicker.propTypes = {
* To specify whether the Date picker is required or not.
*/
required: PropTypes.bool,
/**
* To specify whether the Date picker value can be cleared or not.
*/
allowClear: PropTypes.bool,
};

export default DatePicker;
Loading