Skip to content

Commit

Permalink
Merge branch 'main' into pr-3988-rebase-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
laug committed Oct 22, 2024
2 parents 3e1733e + 47f8457 commit 4068262
Show file tree
Hide file tree
Showing 11 changed files with 1,373 additions and 957 deletions.
2 changes: 1 addition & 1 deletion docs-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"raw-loader": "^4.0.2",
"react-app-rewired": "^2.2.1",
"react-scripts": "5.0.1",
"sass": "^1.79.4"
"sass": "^1.80.2"
},
"resolutions": {
"strip-ansi": "6.0.1"
Expand Down
163 changes: 158 additions & 5 deletions docs-site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,140 @@ __metadata:
languageName: node
linkType: hard

"@parcel/watcher-android-arm64@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-android-arm64@npm:2.4.1"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard

"@parcel/watcher-darwin-arm64@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-darwin-arm64@npm:2.4.1"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"@parcel/watcher-darwin-x64@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-darwin-x64@npm:2.4.1"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"@parcel/watcher-freebsd-x64@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-freebsd-x64@npm:2.4.1"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard

"@parcel/watcher-linux-arm-glibc@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-linux-arm-glibc@npm:2.4.1"
conditions: os=linux & cpu=arm & libc=glibc
languageName: node
linkType: hard

"@parcel/watcher-linux-arm64-glibc@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-linux-arm64-glibc@npm:2.4.1"
conditions: os=linux & cpu=arm64 & libc=glibc
languageName: node
linkType: hard

"@parcel/watcher-linux-arm64-musl@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-linux-arm64-musl@npm:2.4.1"
conditions: os=linux & cpu=arm64 & libc=musl
languageName: node
linkType: hard

"@parcel/watcher-linux-x64-glibc@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-linux-x64-glibc@npm:2.4.1"
conditions: os=linux & cpu=x64 & libc=glibc
languageName: node
linkType: hard

"@parcel/watcher-linux-x64-musl@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-linux-x64-musl@npm:2.4.1"
conditions: os=linux & cpu=x64 & libc=musl
languageName: node
linkType: hard

"@parcel/watcher-win32-arm64@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-win32-arm64@npm:2.4.1"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"@parcel/watcher-win32-ia32@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-win32-ia32@npm:2.4.1"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard

"@parcel/watcher-win32-x64@npm:2.4.1":
version: 2.4.1
resolution: "@parcel/watcher-win32-x64@npm:2.4.1"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard

"@parcel/watcher@npm:^2.4.1":
version: 2.4.1
resolution: "@parcel/watcher@npm:2.4.1"
dependencies:
"@parcel/watcher-android-arm64": "npm:2.4.1"
"@parcel/watcher-darwin-arm64": "npm:2.4.1"
"@parcel/watcher-darwin-x64": "npm:2.4.1"
"@parcel/watcher-freebsd-x64": "npm:2.4.1"
"@parcel/watcher-linux-arm-glibc": "npm:2.4.1"
"@parcel/watcher-linux-arm64-glibc": "npm:2.4.1"
"@parcel/watcher-linux-arm64-musl": "npm:2.4.1"
"@parcel/watcher-linux-x64-glibc": "npm:2.4.1"
"@parcel/watcher-linux-x64-musl": "npm:2.4.1"
"@parcel/watcher-win32-arm64": "npm:2.4.1"
"@parcel/watcher-win32-ia32": "npm:2.4.1"
"@parcel/watcher-win32-x64": "npm:2.4.1"
detect-libc: "npm:^1.0.3"
is-glob: "npm:^4.0.3"
micromatch: "npm:^4.0.5"
node-addon-api: "npm:^7.0.0"
node-gyp: "npm:latest"
dependenciesMeta:
"@parcel/watcher-android-arm64":
optional: true
"@parcel/watcher-darwin-arm64":
optional: true
"@parcel/watcher-darwin-x64":
optional: true
"@parcel/watcher-freebsd-x64":
optional: true
"@parcel/watcher-linux-arm-glibc":
optional: true
"@parcel/watcher-linux-arm64-glibc":
optional: true
"@parcel/watcher-linux-arm64-musl":
optional: true
"@parcel/watcher-linux-x64-glibc":
optional: true
"@parcel/watcher-linux-x64-musl":
optional: true
"@parcel/watcher-win32-arm64":
optional: true
"@parcel/watcher-win32-ia32":
optional: true
"@parcel/watcher-win32-x64":
optional: true
checksum: 10c0/33b7112094b9eb46c234d824953967435b628d3d93a0553255e9910829b84cab3da870153c3a870c31db186dc58f3b2db81382fcaee3451438aeec4d786a6211
languageName: node
linkType: hard

"@pkgjs/parseargs@npm:^0.11.0":
version: 0.11.0
resolution: "@pkgjs/parseargs@npm:0.11.0"
Expand Down Expand Up @@ -5345,6 +5479,15 @@ __metadata:
languageName: node
linkType: hard

"detect-libc@npm:^1.0.3":
version: 1.0.3
resolution: "detect-libc@npm:1.0.3"
bin:
detect-libc: ./bin/detect-libc.js
checksum: 10c0/4da0deae9f69e13bc37a0902d78bf7169480004b1fed3c19722d56cff578d16f0e11633b7fbf5fb6249181236c72e90024cbd68f0b9558ae06e281f47326d50d
languageName: node
linkType: hard

"detect-newline@npm:^3.0.0":
version: 3.1.0
resolution: "detect-newline@npm:3.1.0"
Expand Down Expand Up @@ -9195,6 +9338,15 @@ __metadata:
languageName: node
linkType: hard

"node-addon-api@npm:^7.0.0":
version: 7.1.1
resolution: "node-addon-api@npm:7.1.1"
dependencies:
node-gyp: "npm:latest"
checksum: 10c0/fb32a206276d608037fa1bcd7e9921e177fe992fc610d098aa3128baca3c0050fc1e014fa007e9b3874cf865ddb4f5bd9f43ccb7cbbbe4efaff6a83e920b17e9
languageName: node
linkType: hard

"node-forge@npm:^1":
version: 1.3.1
resolution: "node-forge@npm:1.3.1"
Expand Down Expand Up @@ -10842,7 +10994,7 @@ __metadata:
react-dom: "npm:^18.3.1"
react-live: "npm:^4.1.7"
react-scripts: "npm:5.0.1"
sass: "npm:^1.79.4"
sass: "npm:^1.80.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -11439,16 +11591,17 @@ __metadata:
languageName: node
linkType: hard

"sass@npm:^1.79.4":
version: 1.79.4
resolution: "sass@npm:1.79.4"
"sass@npm:^1.80.2":
version: 1.80.2
resolution: "sass@npm:1.80.2"
dependencies:
"@parcel/watcher": "npm:^2.4.1"
chokidar: "npm:^4.0.0"
immutable: "npm:^4.0.0"
source-map-js: "npm:>=0.6.2 <2.0.0"
bin:
sass: sass.js
checksum: 10c0/505ff0d9267d0fb990971e617acfeabf7c060c55d4cef68fe8a4bc693e7ea88ae7d7caeca3975e4b453459ba4a707b6e5b6979fc9395a7e08f0a43ca6aed06b8
checksum: 10c0/0006e2ee7a732abaa96a663167b078b8d53b4d7fe5ce435636a8bca6e8a3b6ebc12308c0725f577a456329ed962436d96cfcdd50a8e733ed4c4e4590f21243c9
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"react": "^18.3.1",
"react-datepicker": "^7.4.0",
"react-datepicker": "^7.5.0",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1"
},
Expand Down
10 changes: 5 additions & 5 deletions examples/hello-world/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7068,7 +7068,7 @@ __metadata:
resolution: "hello-world@workspace:."
dependencies:
react: "npm:^18.3.1"
react-datepicker: "npm:^7.4.0"
react-datepicker: "npm:^7.5.0"
react-dom: "npm:^18.3.1"
react-scripts: "npm:5.0.1"
languageName: unknown
Expand Down Expand Up @@ -10794,9 +10794,9 @@ __metadata:
languageName: node
linkType: hard

"react-datepicker@npm:^7.4.0":
version: 7.4.0
resolution: "react-datepicker@npm:7.4.0"
"react-datepicker@npm:^7.5.0":
version: 7.5.0
resolution: "react-datepicker@npm:7.5.0"
dependencies:
"@floating-ui/react": "npm:^0.26.23"
clsx: "npm:^2.1.1"
Expand All @@ -10805,7 +10805,7 @@ __metadata:
peerDependencies:
react: ^16.9.0 || ^17 || ^18
react-dom: ^16.9.0 || ^17 || ^18
checksum: 10c0/07f32a5b719106e1a3b933f5eb5aa18c0458bf5f712709df920fd78ac49858396219981874c02fb244b1b4d903b1df07d8860e32974ddb526bf56fd6942e0ddd
checksum: 10c0/6e94a609654b8a0eaa9b2e8c4fab803aa954e78df9729f05337ae97c4e910b1488129ee8d4b11dea575dbe0992242c078cb692ed0cba4e5d98414d8ba393972d
languageName: node
linkType: hard

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "HackerOne",
"name": "react-datepicker",
"description": "A simple and reusable datepicker component for React",
"version": "7.4.0",
"version": "7.5.0",
"license": "MIT",
"homepage": "https://github.com/Hacker0x01/react-datepicker",
"main": "dist/index.js",
Expand Down Expand Up @@ -54,7 +54,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.8.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-unused-imports": "^4.1.3",
"husky": "9",
"jest": "^29.7.0",
Expand All @@ -67,7 +67,7 @@
"react-dom": "^18.3.1",
"rollup": "^4.21.1",
"rollup-plugin-filesize": "^10.0.0",
"sass": "1.79.4",
"sass": "1.79.5",
"slugify": "^1.6.6",
"stylelint": "^16.9.0",
"stylelint-config-standard": "^36.0.1",
Expand Down
38 changes: 35 additions & 3 deletions src/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { clsx } from "clsx";
import { differenceInDays } from "date-fns";
import React, { Component, createRef } from "react";

import CalendarContainer from "./calendar_container";
Expand Down Expand Up @@ -40,6 +41,9 @@ import {
DEFAULT_YEAR_ITEM_NUMBER,
getMonthInLocale,
type Locale,
getStartOfMonth,
getEndOfMonth,
isDayDisabled,
} from "./date_utils";
import InputTime from "./input_time";
import Month from "./month";
Expand Down Expand Up @@ -379,14 +383,42 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
this.props.setPreSelection && this.props.setPreSelection(date);
};

getEnabledPreSelectionDateForMonth = (date: Date) => {
if (!isDayDisabled(date, this.props)) {
return date;
}

const startOfMonth = getStartOfMonth(date);
const endOfMonth = getEndOfMonth(date);

const totalDays = differenceInDays(endOfMonth, startOfMonth);

let preSelectedDate = null;

for (let dayIdx = 0; dayIdx <= totalDays; dayIdx++) {
const processingDate = addDays(startOfMonth, dayIdx);

if (!isDayDisabled(processingDate, this.props)) {
preSelectedDate = processingDate;
break;
}
}

return preSelectedDate;
};

handleMonthChange = (date: Date): void => {
this.handleCustomMonthChange(date);
const enabledPreSelectionDate =
this.getEnabledPreSelectionDateForMonth(date) ?? date;

this.handleCustomMonthChange(enabledPreSelectionDate);
if (this.props.adjustDateOnChange) {
this.props.onSelect(date);
this.props.onSelect(enabledPreSelectionDate);
this.props.setOpen?.(true);
}

this.props.setPreSelection && this.props.setPreSelection(date);
this.props.setPreSelection &&
this.props.setPreSelection(enabledPreSelectionDate);
};

handleCustomMonthChange = (date: Date): void => {
Expand Down
21 changes: 14 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,24 @@ export default class DatePicker extends Component<
}
};

safeFocus = () => {
setTimeout(() => {
this.input?.focus?.({ preventScroll: true });
}, 0);
};

safeBlur = () => {
setTimeout(() => {
this.input?.blur?.();
}, 0);
};

setFocus = () => {
if (this.input && this.input.focus) {
this.input.focus({ preventScroll: true });
}
this.safeFocus();
};

setBlur = () => {
if (this.input && this.input.blur) {
this.input.blur();
}

this.safeBlur();
this.cancelFocusInput();
};

Expand Down
2 changes: 1 addition & 1 deletion src/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Portal extends Component<PortalProps> {
private el: HTMLDivElement;
private portalRoot: HTMLElement | null = null;

render() {
render(): React.ReactPortal {
return ReactDOM.createPortal(this.props.children, this.el);
}
}
Expand Down
Loading

0 comments on commit 4068262

Please sign in to comment.