Skip to content

Commit 4068262

Browse files
committed
Merge branch 'main' into pr-3988-rebase-v3
2 parents 3e1733e + 47f8457 commit 4068262

File tree

11 files changed

+1373
-957
lines changed

11 files changed

+1373
-957
lines changed

docs-site/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"raw-loader": "^4.0.2",
3030
"react-app-rewired": "^2.2.1",
3131
"react-scripts": "5.0.1",
32-
"sass": "^1.79.4"
32+
"sass": "^1.80.2"
3333
},
3434
"resolutions": {
3535
"strip-ansi": "6.0.1"

docs-site/yarn.lock

Lines changed: 158 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,140 @@ __metadata:
26012601
languageName: node
26022602
linkType: hard
26032603

2604+
"@parcel/watcher-android-arm64@npm:2.4.1":
2605+
version: 2.4.1
2606+
resolution: "@parcel/watcher-android-arm64@npm:2.4.1"
2607+
conditions: os=android & cpu=arm64
2608+
languageName: node
2609+
linkType: hard
2610+
2611+
"@parcel/watcher-darwin-arm64@npm:2.4.1":
2612+
version: 2.4.1
2613+
resolution: "@parcel/watcher-darwin-arm64@npm:2.4.1"
2614+
conditions: os=darwin & cpu=arm64
2615+
languageName: node
2616+
linkType: hard
2617+
2618+
"@parcel/watcher-darwin-x64@npm:2.4.1":
2619+
version: 2.4.1
2620+
resolution: "@parcel/watcher-darwin-x64@npm:2.4.1"
2621+
conditions: os=darwin & cpu=x64
2622+
languageName: node
2623+
linkType: hard
2624+
2625+
"@parcel/watcher-freebsd-x64@npm:2.4.1":
2626+
version: 2.4.1
2627+
resolution: "@parcel/watcher-freebsd-x64@npm:2.4.1"
2628+
conditions: os=freebsd & cpu=x64
2629+
languageName: node
2630+
linkType: hard
2631+
2632+
"@parcel/watcher-linux-arm-glibc@npm:2.4.1":
2633+
version: 2.4.1
2634+
resolution: "@parcel/watcher-linux-arm-glibc@npm:2.4.1"
2635+
conditions: os=linux & cpu=arm & libc=glibc
2636+
languageName: node
2637+
linkType: hard
2638+
2639+
"@parcel/watcher-linux-arm64-glibc@npm:2.4.1":
2640+
version: 2.4.1
2641+
resolution: "@parcel/watcher-linux-arm64-glibc@npm:2.4.1"
2642+
conditions: os=linux & cpu=arm64 & libc=glibc
2643+
languageName: node
2644+
linkType: hard
2645+
2646+
"@parcel/watcher-linux-arm64-musl@npm:2.4.1":
2647+
version: 2.4.1
2648+
resolution: "@parcel/watcher-linux-arm64-musl@npm:2.4.1"
2649+
conditions: os=linux & cpu=arm64 & libc=musl
2650+
languageName: node
2651+
linkType: hard
2652+
2653+
"@parcel/watcher-linux-x64-glibc@npm:2.4.1":
2654+
version: 2.4.1
2655+
resolution: "@parcel/watcher-linux-x64-glibc@npm:2.4.1"
2656+
conditions: os=linux & cpu=x64 & libc=glibc
2657+
languageName: node
2658+
linkType: hard
2659+
2660+
"@parcel/watcher-linux-x64-musl@npm:2.4.1":
2661+
version: 2.4.1
2662+
resolution: "@parcel/watcher-linux-x64-musl@npm:2.4.1"
2663+
conditions: os=linux & cpu=x64 & libc=musl
2664+
languageName: node
2665+
linkType: hard
2666+
2667+
"@parcel/watcher-win32-arm64@npm:2.4.1":
2668+
version: 2.4.1
2669+
resolution: "@parcel/watcher-win32-arm64@npm:2.4.1"
2670+
conditions: os=win32 & cpu=arm64
2671+
languageName: node
2672+
linkType: hard
2673+
2674+
"@parcel/watcher-win32-ia32@npm:2.4.1":
2675+
version: 2.4.1
2676+
resolution: "@parcel/watcher-win32-ia32@npm:2.4.1"
2677+
conditions: os=win32 & cpu=ia32
2678+
languageName: node
2679+
linkType: hard
2680+
2681+
"@parcel/watcher-win32-x64@npm:2.4.1":
2682+
version: 2.4.1
2683+
resolution: "@parcel/watcher-win32-x64@npm:2.4.1"
2684+
conditions: os=win32 & cpu=x64
2685+
languageName: node
2686+
linkType: hard
2687+
2688+
"@parcel/watcher@npm:^2.4.1":
2689+
version: 2.4.1
2690+
resolution: "@parcel/watcher@npm:2.4.1"
2691+
dependencies:
2692+
"@parcel/watcher-android-arm64": "npm:2.4.1"
2693+
"@parcel/watcher-darwin-arm64": "npm:2.4.1"
2694+
"@parcel/watcher-darwin-x64": "npm:2.4.1"
2695+
"@parcel/watcher-freebsd-x64": "npm:2.4.1"
2696+
"@parcel/watcher-linux-arm-glibc": "npm:2.4.1"
2697+
"@parcel/watcher-linux-arm64-glibc": "npm:2.4.1"
2698+
"@parcel/watcher-linux-arm64-musl": "npm:2.4.1"
2699+
"@parcel/watcher-linux-x64-glibc": "npm:2.4.1"
2700+
"@parcel/watcher-linux-x64-musl": "npm:2.4.1"
2701+
"@parcel/watcher-win32-arm64": "npm:2.4.1"
2702+
"@parcel/watcher-win32-ia32": "npm:2.4.1"
2703+
"@parcel/watcher-win32-x64": "npm:2.4.1"
2704+
detect-libc: "npm:^1.0.3"
2705+
is-glob: "npm:^4.0.3"
2706+
micromatch: "npm:^4.0.5"
2707+
node-addon-api: "npm:^7.0.0"
2708+
node-gyp: "npm:latest"
2709+
dependenciesMeta:
2710+
"@parcel/watcher-android-arm64":
2711+
optional: true
2712+
"@parcel/watcher-darwin-arm64":
2713+
optional: true
2714+
"@parcel/watcher-darwin-x64":
2715+
optional: true
2716+
"@parcel/watcher-freebsd-x64":
2717+
optional: true
2718+
"@parcel/watcher-linux-arm-glibc":
2719+
optional: true
2720+
"@parcel/watcher-linux-arm64-glibc":
2721+
optional: true
2722+
"@parcel/watcher-linux-arm64-musl":
2723+
optional: true
2724+
"@parcel/watcher-linux-x64-glibc":
2725+
optional: true
2726+
"@parcel/watcher-linux-x64-musl":
2727+
optional: true
2728+
"@parcel/watcher-win32-arm64":
2729+
optional: true
2730+
"@parcel/watcher-win32-ia32":
2731+
optional: true
2732+
"@parcel/watcher-win32-x64":
2733+
optional: true
2734+
checksum: 10c0/33b7112094b9eb46c234d824953967435b628d3d93a0553255e9910829b84cab3da870153c3a870c31db186dc58f3b2db81382fcaee3451438aeec4d786a6211
2735+
languageName: node
2736+
linkType: hard
2737+
26042738
"@pkgjs/parseargs@npm:^0.11.0":
26052739
version: 0.11.0
26062740
resolution: "@pkgjs/parseargs@npm:0.11.0"
@@ -5345,6 +5479,15 @@ __metadata:
53455479
languageName: node
53465480
linkType: hard
53475481

5482+
"detect-libc@npm:^1.0.3":
5483+
version: 1.0.3
5484+
resolution: "detect-libc@npm:1.0.3"
5485+
bin:
5486+
detect-libc: ./bin/detect-libc.js
5487+
checksum: 10c0/4da0deae9f69e13bc37a0902d78bf7169480004b1fed3c19722d56cff578d16f0e11633b7fbf5fb6249181236c72e90024cbd68f0b9558ae06e281f47326d50d
5488+
languageName: node
5489+
linkType: hard
5490+
53485491
"detect-newline@npm:^3.0.0":
53495492
version: 3.1.0
53505493
resolution: "detect-newline@npm:3.1.0"
@@ -9195,6 +9338,15 @@ __metadata:
91959338
languageName: node
91969339
linkType: hard
91979340

9341+
"node-addon-api@npm:^7.0.0":
9342+
version: 7.1.1
9343+
resolution: "node-addon-api@npm:7.1.1"
9344+
dependencies:
9345+
node-gyp: "npm:latest"
9346+
checksum: 10c0/fb32a206276d608037fa1bcd7e9921e177fe992fc610d098aa3128baca3c0050fc1e014fa007e9b3874cf865ddb4f5bd9f43ccb7cbbbe4efaff6a83e920b17e9
9347+
languageName: node
9348+
linkType: hard
9349+
91989350
"node-forge@npm:^1":
91999351
version: 1.3.1
92009352
resolution: "node-forge@npm:1.3.1"
@@ -10842,7 +10994,7 @@ __metadata:
1084210994
react-dom: "npm:^18.3.1"
1084310995
react-live: "npm:^4.1.7"
1084410996
react-scripts: "npm:5.0.1"
10845-
sass: "npm:^1.79.4"
10997+
sass: "npm:^1.80.2"
1084610998
languageName: unknown
1084710999
linkType: soft
1084811000

@@ -11439,16 +11591,17 @@ __metadata:
1143911591
languageName: node
1144011592
linkType: hard
1144111593

11442-
"sass@npm:^1.79.4":
11443-
version: 1.79.4
11444-
resolution: "sass@npm:1.79.4"
11594+
"sass@npm:^1.80.2":
11595+
version: 1.80.2
11596+
resolution: "sass@npm:1.80.2"
1144511597
dependencies:
11598+
"@parcel/watcher": "npm:^2.4.1"
1144611599
chokidar: "npm:^4.0.0"
1144711600
immutable: "npm:^4.0.0"
1144811601
source-map-js: "npm:>=0.6.2 <2.0.0"
1144911602
bin:
1145011603
sass: sass.js
11451-
checksum: 10c0/505ff0d9267d0fb990971e617acfeabf7c060c55d4cef68fe8a4bc693e7ea88ae7d7caeca3975e4b453459ba4a707b6e5b6979fc9395a7e08f0a43ca6aed06b8
11604+
checksum: 10c0/0006e2ee7a732abaa96a663167b078b8d53b4d7fe5ce435636a8bca6e8a3b6ebc12308c0725f577a456329ed962436d96cfcdd50a8e733ed4c4e4590f21243c9
1145211605
languageName: node
1145311606
linkType: hard
1145411607

examples/hello-world/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"react": "^18.3.1",
7-
"react-datepicker": "^7.4.0",
7+
"react-datepicker": "^7.5.0",
88
"react-dom": "^18.3.1",
99
"react-scripts": "5.0.1"
1010
},

examples/hello-world/yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7068,7 +7068,7 @@ __metadata:
70687068
resolution: "hello-world@workspace:."
70697069
dependencies:
70707070
react: "npm:^18.3.1"
7071-
react-datepicker: "npm:^7.4.0"
7071+
react-datepicker: "npm:^7.5.0"
70727072
react-dom: "npm:^18.3.1"
70737073
react-scripts: "npm:5.0.1"
70747074
languageName: unknown
@@ -10794,9 +10794,9 @@ __metadata:
1079410794
languageName: node
1079510795
linkType: hard
1079610796

10797-
"react-datepicker@npm:^7.4.0":
10798-
version: 7.4.0
10799-
resolution: "react-datepicker@npm:7.4.0"
10797+
"react-datepicker@npm:^7.5.0":
10798+
version: 7.5.0
10799+
resolution: "react-datepicker@npm:7.5.0"
1080010800
dependencies:
1080110801
"@floating-ui/react": "npm:^0.26.23"
1080210802
clsx: "npm:^2.1.1"
@@ -10805,7 +10805,7 @@ __metadata:
1080510805
peerDependencies:
1080610806
react: ^16.9.0 || ^17 || ^18
1080710807
react-dom: ^16.9.0 || ^17 || ^18
10808-
checksum: 10c0/07f32a5b719106e1a3b933f5eb5aa18c0458bf5f712709df920fd78ac49858396219981874c02fb244b1b4d903b1df07d8860e32974ddb526bf56fd6942e0ddd
10808+
checksum: 10c0/6e94a609654b8a0eaa9b2e8c4fab803aa954e78df9729f05337ae97c4e910b1488129ee8d4b11dea575dbe0992242c078cb692ed0cba4e5d98414d8ba393972d
1080910809
languageName: node
1081010810
linkType: hard
1081110811

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "HackerOne",
33
"name": "react-datepicker",
44
"description": "A simple and reusable datepicker component for React",
5-
"version": "7.4.0",
5+
"version": "7.5.0",
66
"license": "MIT",
77
"homepage": "https://github.com/Hacker0x01/react-datepicker",
88
"main": "dist/index.js",
@@ -54,7 +54,7 @@
5454
"eslint-plugin-import": "^2.29.1",
5555
"eslint-plugin-jest": "^28.8.0",
5656
"eslint-plugin-react": "^7.35.0",
57-
"eslint-plugin-react-hooks": "^4.6.2",
57+
"eslint-plugin-react-hooks": "^5.0.0",
5858
"eslint-plugin-unused-imports": "^4.1.3",
5959
"husky": "9",
6060
"jest": "^29.7.0",
@@ -67,7 +67,7 @@
6767
"react-dom": "^18.3.1",
6868
"rollup": "^4.21.1",
6969
"rollup-plugin-filesize": "^10.0.0",
70-
"sass": "1.79.4",
70+
"sass": "1.79.5",
7171
"slugify": "^1.6.6",
7272
"stylelint": "^16.9.0",
7373
"stylelint-config-standard": "^36.0.1",

src/calendar.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { clsx } from "clsx";
2+
import { differenceInDays } from "date-fns";
23
import React, { Component, createRef } from "react";
34

45
import CalendarContainer from "./calendar_container";
@@ -40,6 +41,9 @@ import {
4041
DEFAULT_YEAR_ITEM_NUMBER,
4142
getMonthInLocale,
4243
type Locale,
44+
getStartOfMonth,
45+
getEndOfMonth,
46+
isDayDisabled,
4347
} from "./date_utils";
4448
import InputTime from "./input_time";
4549
import Month from "./month";
@@ -379,14 +383,42 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
379383
this.props.setPreSelection && this.props.setPreSelection(date);
380384
};
381385

386+
getEnabledPreSelectionDateForMonth = (date: Date) => {
387+
if (!isDayDisabled(date, this.props)) {
388+
return date;
389+
}
390+
391+
const startOfMonth = getStartOfMonth(date);
392+
const endOfMonth = getEndOfMonth(date);
393+
394+
const totalDays = differenceInDays(endOfMonth, startOfMonth);
395+
396+
let preSelectedDate = null;
397+
398+
for (let dayIdx = 0; dayIdx <= totalDays; dayIdx++) {
399+
const processingDate = addDays(startOfMonth, dayIdx);
400+
401+
if (!isDayDisabled(processingDate, this.props)) {
402+
preSelectedDate = processingDate;
403+
break;
404+
}
405+
}
406+
407+
return preSelectedDate;
408+
};
409+
382410
handleMonthChange = (date: Date): void => {
383-
this.handleCustomMonthChange(date);
411+
const enabledPreSelectionDate =
412+
this.getEnabledPreSelectionDateForMonth(date) ?? date;
413+
414+
this.handleCustomMonthChange(enabledPreSelectionDate);
384415
if (this.props.adjustDateOnChange) {
385-
this.props.onSelect(date);
416+
this.props.onSelect(enabledPreSelectionDate);
386417
this.props.setOpen?.(true);
387418
}
388419

389-
this.props.setPreSelection && this.props.setPreSelection(date);
420+
this.props.setPreSelection &&
421+
this.props.setPreSelection(enabledPreSelectionDate);
390422
};
391423

392424
handleCustomMonthChange = (date: Date): void => {

src/index.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,17 +451,24 @@ export default class DatePicker extends Component<
451451
}
452452
};
453453

454+
safeFocus = () => {
455+
setTimeout(() => {
456+
this.input?.focus?.({ preventScroll: true });
457+
}, 0);
458+
};
459+
460+
safeBlur = () => {
461+
setTimeout(() => {
462+
this.input?.blur?.();
463+
}, 0);
464+
};
465+
454466
setFocus = () => {
455-
if (this.input && this.input.focus) {
456-
this.input.focus({ preventScroll: true });
457-
}
467+
this.safeFocus();
458468
};
459469

460470
setBlur = () => {
461-
if (this.input && this.input.blur) {
462-
this.input.blur();
463-
}
464-
471+
this.safeBlur();
465472
this.cancelFocusInput();
466473
};
467474

src/portal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Portal extends Component<PortalProps> {
4646
private el: HTMLDivElement;
4747
private portalRoot: HTMLElement | null = null;
4848

49-
render() {
49+
render(): React.ReactPortal {
5050
return ReactDOM.createPortal(this.props.children, this.el);
5151
}
5252
}

0 commit comments

Comments
 (0)