35240
35240
onFocus: function onFocus() {},
35241
35241
onBlur: function onBlur() {},
35242
35242
onKeyDown: function onKeyDown() {},
35243
+ onInputClick: function onInputClick() {},
35243
35244
onSelect: function onSelect() {},
35244
35245
onClickOutside: function onClickOutside() {},
35245
35246
onMonthChange: function onMonthChange() {},
@@ -35317,15 +35318,58 @@
35317
35318
}
35318
35319
};
35319
35320
35321
+ _this.setBlur = function() {
35322
+ if (_this.input && _this.input.blur) {
35323
+ _this.input.blur();
35324
+ }
35325
+
35326
+ if (_this.props.onBlur) {
35327
+ _this.props.onBlur();
35328
+ }
35329
+
35330
+ _this.cancelFocusInput();
35331
+ };
35332
+
35320
35333
_this.setOpen = function(open) {
35321
- _this.setState({
35322
- open: open,
35323
- preSelection:
35324
- open && _this.state.open
35325
- ? _this.state.preSelection
35326
- : _this.calcInitialState().preSelection,
35327
- lastPreSelectChange: PRESELECT_CHANGE_VIA_NAVIGATE
35328
- });
35334
+ var skipSetBlur =
35335
+ arguments.length > 1 && arguments[1] !== undefined
35336
+ ? arguments[1]
35337
+ : false;
35338
+
35339
+ _this.setState(
35340
+ {
35341
+ open: open,
35342
+ preSelection:
35343
+ open && _this.state.open
35344
+ ? _this.state.preSelection
35345
+ : _this.calcInitialState().preSelection,
35346
+ lastPreSelectChange: PRESELECT_CHANGE_VIA_NAVIGATE
35347
+ },
35348
+ function() {
35349
+ if (!open) {
35350
+ _this.setState(
35351
+ function(prev) {
35352
+ return {
35353
+ focused: skipSetBlur ? prev.focused : false
35354
+ };
35355
+ },
35356
+ function() {
35357
+ !skipSetBlur && _this.setBlur();
35358
+
35359
+ _this.setState({ inputValue: null, preSelection: null });
35360
+ }
35361
+ );
35362
+ }
35363
+ }
35364
+ );
35365
+ };
35366
+
35367
+ _this.isCalendarOpen = function() {
35368
+ return _this.props.open === undefined
35369
+ ? _this.state.open &&
35370
+ !_this.props.disabled &&
35371
+ !_this.props.readOnly
35372
+ : _this.props.open;
35329
35373
};
35330
35374
35331
35375
_this.handleFocus = function(event) {
35421
35465
) {
35422
35466
_this.setPreSelection(date);
35423
35467
} else if (!_this.props.inline) {
35424
- _this.props.onBlur(date);
35425
- _this.cancelFocusInput();
35426
-
35427
35468
_this.setOpen(false);
35428
35469
}
35429
35470
};
35438
35479
if ((0, _date_utils.isOutOfBounds)(changedDate, _this.props)) {
35439
35480
_this.props.onChange(date, event);
35440
35481
_this.props.onSelect(changedDate, event);
35441
- _this.setState({
35442
- inputValue: changedDate,
35443
- preSelection: changedDate
35444
- });
35445
35482
}
35446
35483
35447
35484
return;
35525
35562
if (!_this.props.disabled && !_this.props.readOnly) {
35526
35563
_this.setOpen(true);
35527
35564
}
35565
+
35566
+ _this.props.onInputClick();
35528
35567
};
35529
35568
35530
35569
_this.onInputKeyDown = function(event) {
@@ -35552,22 +35591,14 @@
35552
35591
_this.handleSelect(copy, event);
35553
35592
!_this.props.shouldCloseOnSelect && _this.setPreSelection(copy);
35554
35593
} else {
35555
- _this.input.blur();
35556
- _this.props.onBlur(copy);
35557
- _this.cancelFocusInput();
35558
-
35559
35594
_this.setOpen(false);
35560
35595
}
35561
35596
} else if (eventKey === "Escape") {
35562
35597
event.preventDefault();
35563
35598
35564
- _this.input.blur();
35565
- _this.props.onBlur(copy);
35566
- _this.cancelFocusInput();
35567
-
35568
35599
_this.setOpen(false);
35569
35600
} else if (eventKey === "Tab") {
35570
- _this.setOpen(false);
35601
+ _this.setOpen(false, true );
35571
35602
} else if (!_this.props.disabledKeyboardNavigation) {
35572
35603
var newSelection = void 0;
35573
35604
switch (eventKey) {
35623
35654
};
35624
35655
35625
35656
_this.renderCalendar = function() {
35626
- if (
35627
- !_this.props.inline &&
35628
- (!_this.state.open ||
35629
- _this.props.disabled ||
35630
- _this.props.readOnly)
35631
- ) {
35657
+ if (!_this.props.inline && !_this.isCalendarOpen()) {
35632
35658
return null;
35633
35659
}
35634
35660
return _react2.default.createElement(
35838
35864
35839
35865
return _react2.default.createElement(_popper_component2.default, {
35840
35866
className: this.props.popperClassName,
35841
- hidePopper:
35842
- !this.state.open || this.props.disabled || this.props.readOnly,
35867
+ hidePopper: !this.isCalendarOpen(),
35843
35868
popperModifiers: this.props.popperModifiers,
35844
35869
targetComponent: _react2.default.createElement(
35845
35870
"div",
35902
35927
onClickOutside: _propTypes2.default.func,
35903
35928
onChangeRaw: _propTypes2.default.func,
35904
35929
onFocus: _propTypes2.default.func,
35930
+ onInputClick: _propTypes2.default.func,
35905
35931
onKeyDown: _propTypes2.default.func,
35906
35932
onMonthChange: _propTypes2.default.func,
35907
35933
onYearChange: _propTypes2.default.func,
35934
+ open: _propTypes2.default.bool,
35908
35935
openToDate: _propTypes2.default.object,
35909
35936
peekNextMonth: _propTypes2.default.bool,
35910
35937
placeholderText: _propTypes2.default.string,
35933
35960
tabIndex: _propTypes2.default.number,
35934
35961
timeCaption: _propTypes2.default.string,
35935
35962
title: _propTypes2.default.string,
35936
- todayButton: _propTypes2.default.string ,
35963
+ todayButton: _propTypes2.default.node ,
35937
35964
useWeekdaysShort: _propTypes2.default.bool,
35938
35965
formatWeekDay: _propTypes2.default.func,
35939
35966
utcOffset: _propTypes2.default.oneOfType([
36819
36846
};
36820
36847
36821
36848
_this.renderTimeSection = function() {
36822
- if (_this.props.showTimeSelect) {
36849
+ if (
36850
+ _this.props.showTimeSelect &&
36851
+ (_this.state.monthContainer || _this.props.showTimeSelectOnly)
36852
+ ) {
36823
36853
return _react2.default.createElement(_time2.default, {
36824
36854
selected: _this.props.selected,
36825
36855
onChange: _this.props.onTimeChange,
36844
36874
_this.state = {
36845
36875
date: _this.localizeDate(_this.getDateInView()),
36846
36876
selectingDate: null,
36847
- monthContainer: _this.monthContainer
36877
+ monthContainer: null
36848
36878
};
36849
36879
return _this;
36850
36880
}
36970
37000
showWeekNumbers: _propTypes2.default.bool,
36971
37001
showYearDropdown: _propTypes2.default.bool,
36972
37002
startDate: _propTypes2.default.object,
36973
- todayButton: _propTypes2.default.string ,
37003
+ todayButton: _propTypes2.default.node ,
36974
37004
useWeekdaysShort: _propTypes2.default.bool,
36975
37005
formatWeekDay: _propTypes2.default.func,
36976
37006
withPortal: _propTypes2.default.bool,
58854
58884
{
58855
58885
key: i,
58856
58886
onClick: _this.handleClick.bind(_this, time),
58857
- className: _this.liClasses(time, currH, currM)
58887
+ className: _this.liClasses(time, currH, currM),
58888
+ ref: function ref(li) {
58889
+ if (
58890
+ (currH === (0, _date_utils.getHour)(time) &&
58891
+ currM === (0, _date_utils.getMinute)(time)) ||
58892
+ (currH === (0, _date_utils.getHour)(time) &&
58893
+ !_this.centerLi)
58894
+ ) {
58895
+ _this.centerLi = li;
58896
+ }
58897
+ }
58858
58898
},
58859
58899
(0, _date_utils.formatDate)(time, format)
58860
58900
);
@@ -58867,19 +58907,21 @@
58867
58907
58868
58908
Time.prototype.componentDidMount = function componentDidMount() {
58869
58909
// code to ensure selected time will always be in focus within time window when it first appears
58870
- var multiplier = 60 / this.props.intervals;
58871
- var currH = this.props.selected
58872
- ? (0, _date_utils.getHour)(this.props.selected)
58873
- : (0, _date_utils.getHour)((0, _date_utils.newDate)());
58874
- this.list.scrollTop = 30 * (multiplier * currH);
58910
+ this.list.scrollTop = Time.calcCenterPosition(
58911
+ this.props.monthRef
58912
+ ? this.props.monthRef.clientHeight - this.header.clientHeight
58913
+ : this.list.clientHeight,
58914
+ this.centerLi
58915
+ );
58875
58916
};
58876
58917
58877
58918
Time.prototype.render = function render() {
58878
58919
var _this2 = this;
58879
58920
58880
58921
var height = null;
58881
- if (this.props.monthRef) {
58882
- height = this.props.monthRef.clientHeight - 39;
58922
+ if (this.props.monthRef && this.header) {
58923
+ height =
58924
+ this.props.monthRef.clientHeight - this.header.clientHeight;
58883
58925
}
58884
58926
58885
58927
return _react2.default.createElement(
58895
58937
"div",
58896
58938
{
58897
58939
className:
58898
- "react-datepicker__header react-datepicker__header--time"
58940
+ "react-datepicker__header react-datepicker__header--time",
58941
+ ref: function ref(header) {
58942
+ _this2.header = header;
58943
+ }
58899
58944
},
58900
58945
_react2.default.createElement(
58901
58946
"div",
@@ -58948,14 +58993,22 @@
58948
58993
intervals: _propTypes2.default.number,
58949
58994
selected: _propTypes2.default.object,
58950
58995
onChange: _propTypes2.default.func,
58951
- todayButton: _propTypes2.default.string ,
58996
+ todayButton: _propTypes2.default.node ,
58952
58997
minTime: _propTypes2.default.object,
58953
58998
maxTime: _propTypes2.default.object,
58954
58999
excludeTimes: _propTypes2.default.array,
58955
59000
monthRef: _propTypes2.default.object,
58956
59001
timeCaption: _propTypes2.default.string,
58957
59002
injectTimes: _propTypes2.default.array
58958
59003
};
59004
+
59005
+ Time.calcCenterPosition = function(listHeight, centerLiRef) {
59006
+ return (
59007
+ centerLiRef.offsetTop -
59008
+ (listHeight / 2 - centerLiRef.clientHeight / 2)
59009
+ );
59010
+ };
59011
+
58959
59012
exports.default = Time;
58960
59013
58961
59014
/***/
0 commit comments