Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
domschab23 committed Dec 17, 2024
1 parent f3e710c commit 64e803c
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/DateTimePicker/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const localeMap = {
const STANDARD_TIME_FORMAT_FNS = 'hh:mm aa';
const ISO_DATE_FORMAT_FNS = 'yyyy-MM-dd';

const popperContainerDocumentBody = ({ children }: { children?: React.ReactNode }) => (
createPortal(children, document.body)
);

export type DateTimePickerProps = {
date?: string;
dateFormat?: string;
Expand All @@ -52,12 +56,6 @@ export type DateTimePickerProps = {
onDateParseError?: (...args: unknown[]) => unknown;
};

function DocumentBodyContainer({ children }) {
return children ? (
createPortal(React.cloneElement(children, {}), document.body)
) : null;
}

function DateTimePicker({
date = '',
dateFormat = ISO_DATE_FORMAT_FNS,
Expand Down Expand Up @@ -204,8 +202,9 @@ function DateTimePicker({
minDate={minDate}
name={name}
placeholderText={getDateFormat().toUpperCase()}
popperClassName={isWithinModal ? 'react-datepicker__popper-container--modal' : ''}
popperContainer={isWithinModal ? popperContainerDocumentBody : undefined}
selected={dateFromString()}
showMonthDropdown={showMonthAndYearSelects}
showTimeSelect={showTimeSelect}
showYearDropdown={showMonthAndYearSelects}
timeCaption="Time"
Expand All @@ -214,10 +213,6 @@ function DateTimePicker({
title={name}
onCalendarClose={handleOnCalendarClose}
onChange={handleOnChange}
{...(isWithinModal ? {
popperContainer: DocumentBodyContainer,
popperClassName: 'react-datepicker__popper-container--modal',
} : {})}
/>
</div>
);
Expand Down

0 comments on commit 64e803c

Please sign in to comment.