Skip to content

Commit 1a82cbc

Browse files
committed
Fix "ReferenceError: HTMLElement is not defined" error
1 parent 5e25a4d commit 1a82cbc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/DatePicker.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import type {
2222
Value,
2323
} from './shared/types.js';
2424

25+
const isBrowser = typeof document !== 'undefined';
26+
2527
const baseClassName = 'react-date-picker';
2628
const outsideActionEvents = ['mousedown', 'focusin', 'touchstart'] as const;
2729
const allViews = ['century', 'decade', 'year', 'month'] as const;
@@ -465,7 +467,7 @@ DatePicker.propTypes = {
465467
onChange: PropTypes.func,
466468
onFocus: PropTypes.func,
467469
openCalendarOnFocus: PropTypes.bool,
468-
portalContainer: PropTypes.instanceOf(HTMLElement),
470+
portalContainer: isBrowser ? PropTypes.instanceOf(HTMLElement) : undefined,
469471
required: PropTypes.bool,
470472
returnValue: PropTypes.oneOf(['start', 'end', 'range'] as const),
471473
showLeadingZeros: PropTypes.bool,

0 commit comments

Comments
 (0)