@zendeskgarden/react-datepickers 8.49.1 → 8.49.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -416,7 +416,7 @@ function getDate(dirtyDate) {
416
416
  var COMPONENT_ID$b = 'datepickers.menu';
417
417
  var StyledMenu = styled__default["default"].div.attrs({
418
418
  'data-garden-id': COMPONENT_ID$b,
419
- 'data-garden-version': '8.49.1'
419
+ 'data-garden-version': '8.49.2'
420
420
  }).withConfig({
421
421
  displayName: "StyledMenu",
422
422
  componentId: "sc-1npbkk0-0"
@@ -3510,7 +3510,6 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3510
3510
  endValue = _ref3.endValue,
3511
3511
  locale = _ref3.locale,
3512
3512
  formatDate = _ref3.formatDate,
3513
- onChange = _ref3.onChange,
3514
3513
  customParseDate = _ref3.customParseDate;
3515
3514
  return function (state, action) {
3516
3515
  switch (action.type) {
@@ -3556,12 +3555,6 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3556
3555
  inputValue: state.startInputValue
3557
3556
  });
3558
3557
  }
3559
- if (onChange && parsedDate && isValid(parsedDate) && !isSameDay(parsedDate, startValue)) {
3560
- onChange({
3561
- startValue: parsedDate,
3562
- endValue: endValue
3563
- });
3564
- }
3565
3558
  var startInputValue = formatValue({
3566
3559
  value: parsedDate,
3567
3560
  locale: locale,
@@ -3586,12 +3579,6 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3586
3579
  inputValue: state.endInputValue
3587
3580
  });
3588
3581
  }
3589
- if (onChange && _parsedDate && isValid(_parsedDate) && !isSameDay(_parsedDate, endValue)) {
3590
- onChange({
3591
- startValue: startValue,
3592
- endValue: _parsedDate
3593
- });
3594
- }
3595
3582
  var endInputValue = formatValue({
3596
3583
  value: _parsedDate,
3597
3584
  locale: locale,
@@ -3649,54 +3636,54 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3649
3636
  });
3650
3637
  }
3651
3638
  case 'CLICK_DATE':
3652
- if (onChange) {
3653
- if (state.isStartFocused) {
3654
- if (endValue !== undefined && (isBefore(action.value, endValue) || isSameDay(action.value, endValue))) {
3655
- onChange({
3656
- startValue: action.value,
3657
- endValue: endValue
3658
- });
3659
- } else {
3660
- onChange({
3661
- startValue: action.value,
3662
- endValue: undefined
3663
- });
3664
- }
3665
- } else if (state.isEndFocused) {
3666
- if (startValue !== undefined && (isAfter(action.value, startValue) || isSameDay(action.value, startValue))) {
3667
- onChange({
3668
- startValue: startValue,
3669
- endValue: action.value
3670
- });
3671
- } else {
3672
- onChange({
3673
- startValue: action.value,
3674
- endValue: undefined
3675
- });
3676
- }
3677
- } else if (startValue === undefined) {
3678
- onChange({
3679
- startValue: action.value,
3680
- endValue: undefined
3639
+ if (state.isStartFocused) {
3640
+ if (endValue !== undefined && (isBefore(action.value, endValue) || isSameDay(action.value, endValue))) {
3641
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3642
+ startInputValue: formatValue({
3643
+ value: action.value
3644
+ })
3681
3645
  });
3682
- } else if (endValue === undefined) {
3683
- if (isBefore(action.value, startValue)) {
3684
- onChange({
3685
- startValue: action.value,
3686
- endValue: undefined
3687
- });
3688
- } else {
3689
- onChange({
3690
- startValue: startValue,
3691
- endValue: action.value
3692
- });
3693
- }
3694
- } else {
3695
- onChange({
3696
- startValue: action.value,
3697
- endValue: undefined
3646
+ }
3647
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3648
+ startInputValue: formatValue({
3649
+ value: action.value
3650
+ }),
3651
+ endInputValue: undefined
3652
+ });
3653
+ } else if (state.isEndFocused) {
3654
+ if (startValue !== undefined && (isAfter(action.value, startValue) || isSameDay(action.value, startValue))) {
3655
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3656
+ endInputValue: formatValue({
3657
+ value: action.value
3658
+ })
3659
+ });
3660
+ }
3661
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3662
+ startInputValue: formatValue({
3663
+ value: action.value
3664
+ })
3665
+ });
3666
+ } else if (startValue === undefined) {
3667
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3668
+ startInputValue: formatValue({
3669
+ value: action.value
3670
+ }),
3671
+ endInputValue: undefined
3672
+ });
3673
+ } else if (endValue === undefined) {
3674
+ if (isBefore(action.value, startValue)) {
3675
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3676
+ startInputValue: formatValue({
3677
+ value: action.value
3678
+ }),
3679
+ endInputValue: undefined
3698
3680
  });
3699
3681
  }
3682
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3683
+ endInputValue: formatValue({
3684
+ value: action.value
3685
+ })
3686
+ });
3700
3687
  }
3701
3688
  return state;
3702
3689
  case 'START_INPUT_ONCHANGE':
@@ -3769,7 +3756,11 @@ var Start = function Start(props) {
3769
3756
  var _useDatepickerRangeCo = useDatepickerContext(),
3770
3757
  state = _useDatepickerRangeCo.state,
3771
3758
  dispatch = _useDatepickerRangeCo.dispatch,
3772
- startInputRef = _useDatepickerRangeCo.startInputRef;
3759
+ onChange = _useDatepickerRangeCo.onChange,
3760
+ startValue = _useDatepickerRangeCo.startValue,
3761
+ endValue = _useDatepickerRangeCo.endValue,
3762
+ startInputRef = _useDatepickerRangeCo.startInputRef,
3763
+ customParseDate = _useDatepickerRangeCo.customParseDate;
3773
3764
  var onChangeCallback = React.useCallback(function (e) {
3774
3765
  dispatch({
3775
3766
  type: 'START_INPUT_ONCHANGE',
@@ -3783,24 +3774,39 @@ var Start = function Start(props) {
3783
3774
  });
3784
3775
  props.children.props.onFocus && props.children.props.onFocus(e);
3785
3776
  }, [dispatch, props.children]);
3777
+ var handleBlur = React.useCallback(function () {
3778
+ var parsedDate;
3779
+ if (customParseDate) {
3780
+ parsedDate = customParseDate(state.startInputValue);
3781
+ } else {
3782
+ parsedDate = parseInputValue({
3783
+ inputValue: state.startInputValue
3784
+ });
3785
+ }
3786
+ dispatch({
3787
+ type: 'START_BLUR'
3788
+ });
3789
+ if (parsedDate && isValid(parsedDate) && !isSameDay(parsedDate, startValue)) {
3790
+ onChange && onChange({
3791
+ startValue: parsedDate,
3792
+ endValue: endValue
3793
+ });
3794
+ }
3795
+ }, [dispatch, onChange, startValue, endValue, customParseDate, state.startInputValue]);
3786
3796
  var onKeyDownCallback = React.useCallback(function (e) {
3787
3797
  if (e.keyCode === containerUtilities.KEY_CODES.ENTER) {
3788
- dispatch({
3789
- type: 'START_BLUR'
3790
- });
3791
3798
  e.preventDefault();
3799
+ handleBlur();
3792
3800
  }
3793
3801
  props.children.props.onKeyDown && props.children.props.onKeyDown(e);
3794
- }, [dispatch, props.children]);
3802
+ }, [handleBlur, props.children]);
3795
3803
  var onBlurCallback = React.useCallback(function (e) {
3796
- dispatch({
3797
- type: 'START_BLUR'
3798
- });
3804
+ handleBlur();
3799
3805
  props.children.props.onBlur && props.children.props.onBlur(e);
3800
- }, [dispatch, props.children]);
3806
+ }, [handleBlur, props.children]);
3801
3807
  var childElement = React__default["default"].Children.only(props.children);
3802
3808
  return React__default["default"].cloneElement(childElement, {
3803
- value: state.startInputValue,
3809
+ value: state.startInputValue || '',
3804
3810
  ref: startInputRef,
3805
3811
  onChange: containerUtilities.composeEventHandlers(childElement.props.onChange, onChangeCallback),
3806
3812
  onFocus: containerUtilities.composeEventHandlers(childElement.props.onFocus, onFocusCallback),
@@ -3814,7 +3820,11 @@ var End = function End(props) {
3814
3820
  var _useDatepickerRangeCo = useDatepickerContext(),
3815
3821
  state = _useDatepickerRangeCo.state,
3816
3822
  dispatch = _useDatepickerRangeCo.dispatch,
3817
- endInputRef = _useDatepickerRangeCo.endInputRef;
3823
+ onChange = _useDatepickerRangeCo.onChange,
3824
+ startValue = _useDatepickerRangeCo.startValue,
3825
+ endValue = _useDatepickerRangeCo.endValue,
3826
+ endInputRef = _useDatepickerRangeCo.endInputRef,
3827
+ customParseDate = _useDatepickerRangeCo.customParseDate;
3818
3828
  var onChangeCallback = React.useCallback(function (e) {
3819
3829
  dispatch({
3820
3830
  type: 'END_INPUT_ONCHANGE',
@@ -3828,24 +3838,39 @@ var End = function End(props) {
3828
3838
  });
3829
3839
  props.children.props.onFocus && props.children.props.onFocus(e);
3830
3840
  }, [dispatch, props.children]);
3841
+ var handleBlur = React.useCallback(function () {
3842
+ dispatch({
3843
+ type: 'END_BLUR'
3844
+ });
3845
+ var parsedDate;
3846
+ if (customParseDate) {
3847
+ parsedDate = customParseDate(state.endInputValue);
3848
+ } else {
3849
+ parsedDate = parseInputValue({
3850
+ inputValue: state.endInputValue
3851
+ });
3852
+ }
3853
+ if (onChange && parsedDate && isValid(parsedDate) && !isSameDay(parsedDate, endValue)) {
3854
+ onChange && onChange({
3855
+ startValue: startValue,
3856
+ endValue: parsedDate
3857
+ });
3858
+ }
3859
+ }, [dispatch, onChange, startValue, endValue, customParseDate, state.endInputValue]);
3831
3860
  var onKeydownCallback = React.useCallback(function (e) {
3832
3861
  if (e.keyCode === containerUtilities.KEY_CODES.ENTER) {
3833
- dispatch({
3834
- type: 'END_BLUR'
3835
- });
3862
+ handleBlur();
3836
3863
  e.preventDefault();
3837
3864
  }
3838
3865
  props.children.props.onKeyDown && props.children.props.onKeyDown(e);
3839
- }, [dispatch, props.children]);
3866
+ }, [handleBlur, props.children]);
3840
3867
  var onBlurCallback = React.useCallback(function (e) {
3841
- dispatch({
3842
- type: 'END_BLUR'
3843
- });
3868
+ handleBlur();
3844
3869
  props.children.props.onBlur && props.children.props.onBlur(e);
3845
- }, [dispatch, props.children]);
3870
+ }, [handleBlur, props.children]);
3846
3871
  var childElement = React__default["default"].Children.only(props.children);
3847
3872
  return React__default["default"].cloneElement(childElement, {
3848
- value: state.endInputValue,
3873
+ value: state.endInputValue || '',
3849
3874
  ref: endInputRef,
3850
3875
  onChange: containerUtilities.composeEventHandlers(childElement.props.onChange, onChangeCallback),
3851
3876
  onFocus: containerUtilities.composeEventHandlers(childElement.props.onFocus, onFocusCallback),
@@ -3873,6 +3898,9 @@ var Month = React.forwardRef(function (_ref, ref) {
3873
3898
  startValue = _ref.startValue,
3874
3899
  endValue = _ref.endValue,
3875
3900
  hoverDate = _ref.hoverDate;
3901
+ var _useDatepickerRangeCo = useDatepickerContext(),
3902
+ state = _useDatepickerRangeCo.state,
3903
+ onChange = _useDatepickerRangeCo.onChange;
3876
3904
  var headerLabelFormatter = React.useCallback(function (date) {
3877
3905
  var formatter = new Intl.DateTimeFormat(locale, {
3878
3906
  month: 'long',
@@ -3988,6 +4016,55 @@ var Month = React.forwardRef(function (_ref, ref) {
3988
4016
  type: 'CLICK_DATE',
3989
4017
  value: date
3990
4018
  });
4019
+ if (onChange) {
4020
+ if (state.isStartFocused) {
4021
+ if (endValue !== undefined && (isBefore(date, endValue) || isSameDay(date, endValue))) {
4022
+ onChange({
4023
+ startValue: date,
4024
+ endValue: endValue
4025
+ });
4026
+ } else {
4027
+ onChange({
4028
+ startValue: date,
4029
+ endValue: undefined
4030
+ });
4031
+ }
4032
+ } else if (state.isEndFocused) {
4033
+ if (startValue !== undefined && (isAfter(date, startValue) || isSameDay(date, startValue))) {
4034
+ onChange({
4035
+ startValue: startValue,
4036
+ endValue: date
4037
+ });
4038
+ } else {
4039
+ onChange({
4040
+ startValue: date,
4041
+ endValue: undefined
4042
+ });
4043
+ }
4044
+ } else if (startValue === undefined) {
4045
+ onChange({
4046
+ startValue: date,
4047
+ endValue: undefined
4048
+ });
4049
+ } else if (endValue === undefined) {
4050
+ if (isBefore(date, startValue)) {
4051
+ onChange({
4052
+ startValue: date,
4053
+ endValue: undefined
4054
+ });
4055
+ } else {
4056
+ onChange({
4057
+ startValue: startValue,
4058
+ endValue: date
4059
+ });
4060
+ }
4061
+ } else {
4062
+ onChange({
4063
+ startValue: date,
4064
+ endValue: undefined
4065
+ });
4066
+ }
4067
+ }
3991
4068
  }
3992
4069
  },
3993
4070
  onMouseEnter: function onMouseEnter() {
@@ -4047,12 +4124,11 @@ var Calendar = React.forwardRef(function (props, ref) {
4047
4124
  minValue = _useDatepickerRangeCo.minValue,
4048
4125
  maxValue = _useDatepickerRangeCo.maxValue,
4049
4126
  startValue = _useDatepickerRangeCo.startValue,
4050
- endValue = _useDatepickerRangeCo.endValue,
4051
- onChange = _useDatepickerRangeCo.onChange;
4127
+ endValue = _useDatepickerRangeCo.endValue;
4052
4128
  return React__default["default"].createElement(StyledRangeCalendar, _extends$2({
4053
4129
  ref: ref,
4054
4130
  "data-garden-id": "datepickers.range",
4055
- "data-garden-version": '8.49.1'
4131
+ "data-garden-version": '8.49.2'
4056
4132
  }, props), React__default["default"].createElement(Month, {
4057
4133
  locale: locale,
4058
4134
  displayDate: state.previewDate,
@@ -4063,7 +4139,6 @@ var Calendar = React.forwardRef(function (props, ref) {
4063
4139
  maxValue: maxValue,
4064
4140
  startValue: startValue,
4065
4141
  endValue: endValue,
4066
- onChange: onChange,
4067
4142
  hoverDate: state.hoverDate
4068
4143
  }), React__default["default"].createElement(Month, {
4069
4144
  locale: locale,
@@ -4075,7 +4150,6 @@ var Calendar = React.forwardRef(function (props, ref) {
4075
4150
  maxValue: maxValue,
4076
4151
  startValue: startValue,
4077
4152
  endValue: endValue,
4078
- onChange: onChange,
4079
4153
  hoverDate: state.hoverDate
4080
4154
  }));
4081
4155
  });
@@ -4097,7 +4171,6 @@ var DatepickerRangeComponent = function DatepickerRangeComponent(props) {
4097
4171
  locale: locale,
4098
4172
  formatDate: formatDate,
4099
4173
  endValue: endValue,
4100
- onChange: onChange,
4101
4174
  customParseDate: customParseDate
4102
4175
  }), [startValue, endValue, locale, formatDate, onChange, customParseDate]);
4103
4176
  var _useReducer = React.useReducer(reducer, retrieveInitialState(props)),
@@ -4140,9 +4213,10 @@ var DatepickerRangeComponent = function DatepickerRangeComponent(props) {
4140
4213
  endValue: endValue,
4141
4214
  onChange: onChange,
4142
4215
  startInputRef: startInputRef,
4143
- endInputRef: endInputRef
4216
+ endInputRef: endInputRef,
4217
+ customParseDate: customParseDate
4144
4218
  };
4145
- }, [state, dispatch, isCompact, locale, minValue, maxValue, startValue, endValue, onChange, startInputRef, endInputRef]);
4219
+ }, [state, dispatch, isCompact, locale, minValue, maxValue, startValue, endValue, onChange, startInputRef, endInputRef, customParseDate]);
4146
4220
  return React__default["default"].createElement(DatepickerRangeContext.Provider, {
4147
4221
  value: value
4148
4222
  }, children);
package/dist/index.esm.js CHANGED
@@ -388,7 +388,7 @@ function getDate(dirtyDate) {
388
388
  var COMPONENT_ID$b = 'datepickers.menu';
389
389
  var StyledMenu = styled.div.attrs({
390
390
  'data-garden-id': COMPONENT_ID$b,
391
- 'data-garden-version': '8.49.1'
391
+ 'data-garden-version': '8.49.2'
392
392
  }).withConfig({
393
393
  displayName: "StyledMenu",
394
394
  componentId: "sc-1npbkk0-0"
@@ -3482,7 +3482,6 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3482
3482
  endValue = _ref3.endValue,
3483
3483
  locale = _ref3.locale,
3484
3484
  formatDate = _ref3.formatDate,
3485
- onChange = _ref3.onChange,
3486
3485
  customParseDate = _ref3.customParseDate;
3487
3486
  return function (state, action) {
3488
3487
  switch (action.type) {
@@ -3528,12 +3527,6 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3528
3527
  inputValue: state.startInputValue
3529
3528
  });
3530
3529
  }
3531
- if (onChange && parsedDate && isValid(parsedDate) && !isSameDay(parsedDate, startValue)) {
3532
- onChange({
3533
- startValue: parsedDate,
3534
- endValue: endValue
3535
- });
3536
- }
3537
3530
  var startInputValue = formatValue({
3538
3531
  value: parsedDate,
3539
3532
  locale: locale,
@@ -3558,12 +3551,6 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3558
3551
  inputValue: state.endInputValue
3559
3552
  });
3560
3553
  }
3561
- if (onChange && _parsedDate && isValid(_parsedDate) && !isSameDay(_parsedDate, endValue)) {
3562
- onChange({
3563
- startValue: startValue,
3564
- endValue: _parsedDate
3565
- });
3566
- }
3567
3554
  var endInputValue = formatValue({
3568
3555
  value: _parsedDate,
3569
3556
  locale: locale,
@@ -3621,54 +3608,54 @@ var datepickerRangeReducer = function datepickerRangeReducer(_ref3) {
3621
3608
  });
3622
3609
  }
3623
3610
  case 'CLICK_DATE':
3624
- if (onChange) {
3625
- if (state.isStartFocused) {
3626
- if (endValue !== undefined && (isBefore(action.value, endValue) || isSameDay(action.value, endValue))) {
3627
- onChange({
3628
- startValue: action.value,
3629
- endValue: endValue
3630
- });
3631
- } else {
3632
- onChange({
3633
- startValue: action.value,
3634
- endValue: undefined
3635
- });
3636
- }
3637
- } else if (state.isEndFocused) {
3638
- if (startValue !== undefined && (isAfter(action.value, startValue) || isSameDay(action.value, startValue))) {
3639
- onChange({
3640
- startValue: startValue,
3641
- endValue: action.value
3642
- });
3643
- } else {
3644
- onChange({
3645
- startValue: action.value,
3646
- endValue: undefined
3647
- });
3648
- }
3649
- } else if (startValue === undefined) {
3650
- onChange({
3651
- startValue: action.value,
3652
- endValue: undefined
3611
+ if (state.isStartFocused) {
3612
+ if (endValue !== undefined && (isBefore(action.value, endValue) || isSameDay(action.value, endValue))) {
3613
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3614
+ startInputValue: formatValue({
3615
+ value: action.value
3616
+ })
3653
3617
  });
3654
- } else if (endValue === undefined) {
3655
- if (isBefore(action.value, startValue)) {
3656
- onChange({
3657
- startValue: action.value,
3658
- endValue: undefined
3659
- });
3660
- } else {
3661
- onChange({
3662
- startValue: startValue,
3663
- endValue: action.value
3664
- });
3665
- }
3666
- } else {
3667
- onChange({
3668
- startValue: action.value,
3669
- endValue: undefined
3618
+ }
3619
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3620
+ startInputValue: formatValue({
3621
+ value: action.value
3622
+ }),
3623
+ endInputValue: undefined
3624
+ });
3625
+ } else if (state.isEndFocused) {
3626
+ if (startValue !== undefined && (isAfter(action.value, startValue) || isSameDay(action.value, startValue))) {
3627
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3628
+ endInputValue: formatValue({
3629
+ value: action.value
3630
+ })
3631
+ });
3632
+ }
3633
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3634
+ startInputValue: formatValue({
3635
+ value: action.value
3636
+ })
3637
+ });
3638
+ } else if (startValue === undefined) {
3639
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3640
+ startInputValue: formatValue({
3641
+ value: action.value
3642
+ }),
3643
+ endInputValue: undefined
3644
+ });
3645
+ } else if (endValue === undefined) {
3646
+ if (isBefore(action.value, startValue)) {
3647
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3648
+ startInputValue: formatValue({
3649
+ value: action.value
3650
+ }),
3651
+ endInputValue: undefined
3670
3652
  });
3671
3653
  }
3654
+ return _objectSpread2(_objectSpread2({}, state), {}, {
3655
+ endInputValue: formatValue({
3656
+ value: action.value
3657
+ })
3658
+ });
3672
3659
  }
3673
3660
  return state;
3674
3661
  case 'START_INPUT_ONCHANGE':
@@ -3741,7 +3728,11 @@ var Start = function Start(props) {
3741
3728
  var _useDatepickerRangeCo = useDatepickerContext(),
3742
3729
  state = _useDatepickerRangeCo.state,
3743
3730
  dispatch = _useDatepickerRangeCo.dispatch,
3744
- startInputRef = _useDatepickerRangeCo.startInputRef;
3731
+ onChange = _useDatepickerRangeCo.onChange,
3732
+ startValue = _useDatepickerRangeCo.startValue,
3733
+ endValue = _useDatepickerRangeCo.endValue,
3734
+ startInputRef = _useDatepickerRangeCo.startInputRef,
3735
+ customParseDate = _useDatepickerRangeCo.customParseDate;
3745
3736
  var onChangeCallback = useCallback(function (e) {
3746
3737
  dispatch({
3747
3738
  type: 'START_INPUT_ONCHANGE',
@@ -3755,24 +3746,39 @@ var Start = function Start(props) {
3755
3746
  });
3756
3747
  props.children.props.onFocus && props.children.props.onFocus(e);
3757
3748
  }, [dispatch, props.children]);
3749
+ var handleBlur = useCallback(function () {
3750
+ var parsedDate;
3751
+ if (customParseDate) {
3752
+ parsedDate = customParseDate(state.startInputValue);
3753
+ } else {
3754
+ parsedDate = parseInputValue({
3755
+ inputValue: state.startInputValue
3756
+ });
3757
+ }
3758
+ dispatch({
3759
+ type: 'START_BLUR'
3760
+ });
3761
+ if (parsedDate && isValid(parsedDate) && !isSameDay(parsedDate, startValue)) {
3762
+ onChange && onChange({
3763
+ startValue: parsedDate,
3764
+ endValue: endValue
3765
+ });
3766
+ }
3767
+ }, [dispatch, onChange, startValue, endValue, customParseDate, state.startInputValue]);
3758
3768
  var onKeyDownCallback = useCallback(function (e) {
3759
3769
  if (e.keyCode === KEY_CODES.ENTER) {
3760
- dispatch({
3761
- type: 'START_BLUR'
3762
- });
3763
3770
  e.preventDefault();
3771
+ handleBlur();
3764
3772
  }
3765
3773
  props.children.props.onKeyDown && props.children.props.onKeyDown(e);
3766
- }, [dispatch, props.children]);
3774
+ }, [handleBlur, props.children]);
3767
3775
  var onBlurCallback = useCallback(function (e) {
3768
- dispatch({
3769
- type: 'START_BLUR'
3770
- });
3776
+ handleBlur();
3771
3777
  props.children.props.onBlur && props.children.props.onBlur(e);
3772
- }, [dispatch, props.children]);
3778
+ }, [handleBlur, props.children]);
3773
3779
  var childElement = React__default.Children.only(props.children);
3774
3780
  return React__default.cloneElement(childElement, {
3775
- value: state.startInputValue,
3781
+ value: state.startInputValue || '',
3776
3782
  ref: startInputRef,
3777
3783
  onChange: composeEventHandlers(childElement.props.onChange, onChangeCallback),
3778
3784
  onFocus: composeEventHandlers(childElement.props.onFocus, onFocusCallback),
@@ -3786,7 +3792,11 @@ var End = function End(props) {
3786
3792
  var _useDatepickerRangeCo = useDatepickerContext(),
3787
3793
  state = _useDatepickerRangeCo.state,
3788
3794
  dispatch = _useDatepickerRangeCo.dispatch,
3789
- endInputRef = _useDatepickerRangeCo.endInputRef;
3795
+ onChange = _useDatepickerRangeCo.onChange,
3796
+ startValue = _useDatepickerRangeCo.startValue,
3797
+ endValue = _useDatepickerRangeCo.endValue,
3798
+ endInputRef = _useDatepickerRangeCo.endInputRef,
3799
+ customParseDate = _useDatepickerRangeCo.customParseDate;
3790
3800
  var onChangeCallback = useCallback(function (e) {
3791
3801
  dispatch({
3792
3802
  type: 'END_INPUT_ONCHANGE',
@@ -3800,24 +3810,39 @@ var End = function End(props) {
3800
3810
  });
3801
3811
  props.children.props.onFocus && props.children.props.onFocus(e);
3802
3812
  }, [dispatch, props.children]);
3813
+ var handleBlur = useCallback(function () {
3814
+ dispatch({
3815
+ type: 'END_BLUR'
3816
+ });
3817
+ var parsedDate;
3818
+ if (customParseDate) {
3819
+ parsedDate = customParseDate(state.endInputValue);
3820
+ } else {
3821
+ parsedDate = parseInputValue({
3822
+ inputValue: state.endInputValue
3823
+ });
3824
+ }
3825
+ if (onChange && parsedDate && isValid(parsedDate) && !isSameDay(parsedDate, endValue)) {
3826
+ onChange && onChange({
3827
+ startValue: startValue,
3828
+ endValue: parsedDate
3829
+ });
3830
+ }
3831
+ }, [dispatch, onChange, startValue, endValue, customParseDate, state.endInputValue]);
3803
3832
  var onKeydownCallback = useCallback(function (e) {
3804
3833
  if (e.keyCode === KEY_CODES.ENTER) {
3805
- dispatch({
3806
- type: 'END_BLUR'
3807
- });
3834
+ handleBlur();
3808
3835
  e.preventDefault();
3809
3836
  }
3810
3837
  props.children.props.onKeyDown && props.children.props.onKeyDown(e);
3811
- }, [dispatch, props.children]);
3838
+ }, [handleBlur, props.children]);
3812
3839
  var onBlurCallback = useCallback(function (e) {
3813
- dispatch({
3814
- type: 'END_BLUR'
3815
- });
3840
+ handleBlur();
3816
3841
  props.children.props.onBlur && props.children.props.onBlur(e);
3817
- }, [dispatch, props.children]);
3842
+ }, [handleBlur, props.children]);
3818
3843
  var childElement = React__default.Children.only(props.children);
3819
3844
  return React__default.cloneElement(childElement, {
3820
- value: state.endInputValue,
3845
+ value: state.endInputValue || '',
3821
3846
  ref: endInputRef,
3822
3847
  onChange: composeEventHandlers(childElement.props.onChange, onChangeCallback),
3823
3848
  onFocus: composeEventHandlers(childElement.props.onFocus, onFocusCallback),
@@ -3845,6 +3870,9 @@ var Month = forwardRef(function (_ref, ref) {
3845
3870
  startValue = _ref.startValue,
3846
3871
  endValue = _ref.endValue,
3847
3872
  hoverDate = _ref.hoverDate;
3873
+ var _useDatepickerRangeCo = useDatepickerContext(),
3874
+ state = _useDatepickerRangeCo.state,
3875
+ onChange = _useDatepickerRangeCo.onChange;
3848
3876
  var headerLabelFormatter = useCallback(function (date) {
3849
3877
  var formatter = new Intl.DateTimeFormat(locale, {
3850
3878
  month: 'long',
@@ -3960,6 +3988,55 @@ var Month = forwardRef(function (_ref, ref) {
3960
3988
  type: 'CLICK_DATE',
3961
3989
  value: date
3962
3990
  });
3991
+ if (onChange) {
3992
+ if (state.isStartFocused) {
3993
+ if (endValue !== undefined && (isBefore(date, endValue) || isSameDay(date, endValue))) {
3994
+ onChange({
3995
+ startValue: date,
3996
+ endValue: endValue
3997
+ });
3998
+ } else {
3999
+ onChange({
4000
+ startValue: date,
4001
+ endValue: undefined
4002
+ });
4003
+ }
4004
+ } else if (state.isEndFocused) {
4005
+ if (startValue !== undefined && (isAfter(date, startValue) || isSameDay(date, startValue))) {
4006
+ onChange({
4007
+ startValue: startValue,
4008
+ endValue: date
4009
+ });
4010
+ } else {
4011
+ onChange({
4012
+ startValue: date,
4013
+ endValue: undefined
4014
+ });
4015
+ }
4016
+ } else if (startValue === undefined) {
4017
+ onChange({
4018
+ startValue: date,
4019
+ endValue: undefined
4020
+ });
4021
+ } else if (endValue === undefined) {
4022
+ if (isBefore(date, startValue)) {
4023
+ onChange({
4024
+ startValue: date,
4025
+ endValue: undefined
4026
+ });
4027
+ } else {
4028
+ onChange({
4029
+ startValue: startValue,
4030
+ endValue: date
4031
+ });
4032
+ }
4033
+ } else {
4034
+ onChange({
4035
+ startValue: date,
4036
+ endValue: undefined
4037
+ });
4038
+ }
4039
+ }
3963
4040
  }
3964
4041
  },
3965
4042
  onMouseEnter: function onMouseEnter() {
@@ -4019,12 +4096,11 @@ var Calendar = forwardRef(function (props, ref) {
4019
4096
  minValue = _useDatepickerRangeCo.minValue,
4020
4097
  maxValue = _useDatepickerRangeCo.maxValue,
4021
4098
  startValue = _useDatepickerRangeCo.startValue,
4022
- endValue = _useDatepickerRangeCo.endValue,
4023
- onChange = _useDatepickerRangeCo.onChange;
4099
+ endValue = _useDatepickerRangeCo.endValue;
4024
4100
  return React__default.createElement(StyledRangeCalendar, _extends$2({
4025
4101
  ref: ref,
4026
4102
  "data-garden-id": "datepickers.range",
4027
- "data-garden-version": '8.49.1'
4103
+ "data-garden-version": '8.49.2'
4028
4104
  }, props), React__default.createElement(Month, {
4029
4105
  locale: locale,
4030
4106
  displayDate: state.previewDate,
@@ -4035,7 +4111,6 @@ var Calendar = forwardRef(function (props, ref) {
4035
4111
  maxValue: maxValue,
4036
4112
  startValue: startValue,
4037
4113
  endValue: endValue,
4038
- onChange: onChange,
4039
4114
  hoverDate: state.hoverDate
4040
4115
  }), React__default.createElement(Month, {
4041
4116
  locale: locale,
@@ -4047,7 +4122,6 @@ var Calendar = forwardRef(function (props, ref) {
4047
4122
  maxValue: maxValue,
4048
4123
  startValue: startValue,
4049
4124
  endValue: endValue,
4050
- onChange: onChange,
4051
4125
  hoverDate: state.hoverDate
4052
4126
  }));
4053
4127
  });
@@ -4069,7 +4143,6 @@ var DatepickerRangeComponent = function DatepickerRangeComponent(props) {
4069
4143
  locale: locale,
4070
4144
  formatDate: formatDate,
4071
4145
  endValue: endValue,
4072
- onChange: onChange,
4073
4146
  customParseDate: customParseDate
4074
4147
  }), [startValue, endValue, locale, formatDate, onChange, customParseDate]);
4075
4148
  var _useReducer = useReducer(reducer, retrieveInitialState(props)),
@@ -4112,9 +4185,10 @@ var DatepickerRangeComponent = function DatepickerRangeComponent(props) {
4112
4185
  endValue: endValue,
4113
4186
  onChange: onChange,
4114
4187
  startInputRef: startInputRef,
4115
- endInputRef: endInputRef
4188
+ endInputRef: endInputRef,
4189
+ customParseDate: customParseDate
4116
4190
  };
4117
- }, [state, dispatch, isCompact, locale, minValue, maxValue, startValue, endValue, onChange, startInputRef, endInputRef]);
4191
+ }, [state, dispatch, isCompact, locale, minValue, maxValue, startValue, endValue, onChange, startInputRef, endInputRef, customParseDate]);
4118
4192
  return React__default.createElement(DatepickerRangeContext.Provider, {
4119
4193
  value: value
4120
4194
  }, children);
@@ -17,10 +17,6 @@ interface IMonthProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
17
17
  maxValue?: Date;
18
18
  startValue?: Date;
19
19
  endValue?: Date;
20
- onChange?: (values: {
21
- startValue?: Date;
22
- endValue?: Date;
23
- }) => void;
24
20
  hoverDate?: Date;
25
21
  }
26
22
  export declare const Month: React.ForwardRefExoticComponent<IMonthProps & React.RefAttributes<HTMLDivElement>>;
@@ -13,6 +13,20 @@ export interface IDatepickerRangeState {
13
13
  startInputValue?: string;
14
14
  endInputValue?: string;
15
15
  }
16
+ /**
17
+ * Format date value to a localized string
18
+ */
19
+ export declare function formatValue({ value, locale, formatDate }: {
20
+ value?: Date;
21
+ formatDate?: any;
22
+ locale?: string;
23
+ }): string;
24
+ /**
25
+ * Parse string input value using current locale and date formats
26
+ */
27
+ export declare function parseInputValue({ inputValue }: {
28
+ inputValue?: string;
29
+ }): Date;
16
30
  export declare type DatepickerRangeAction = {
17
31
  type: 'HOVER_DATE';
18
32
  value?: Date;
@@ -44,15 +58,11 @@ export declare type DatepickerRangeAction = {
44
58
  type: 'CONTROLLED_END_VALUE_CHANGE';
45
59
  value?: Date;
46
60
  };
47
- export declare const datepickerRangeReducer: ({ startValue, endValue, locale, formatDate, onChange, customParseDate }: {
61
+ export declare const datepickerRangeReducer: ({ startValue, endValue, locale, formatDate, customParseDate }: {
48
62
  startValue?: Date | undefined;
49
63
  endValue?: Date | undefined;
50
64
  locale?: string | undefined;
51
65
  formatDate?: any;
52
- onChange?: ((values: {
53
- startValue?: Date | undefined;
54
- endValue?: Date | undefined;
55
- }) => void) | undefined;
56
66
  customParseDate?: ((inputValue?: string | undefined) => Date) | undefined;
57
67
  }) => (state: IDatepickerRangeState, action: DatepickerRangeAction) => IDatepickerRangeState;
58
68
  /**
@@ -21,6 +21,7 @@ export interface IDatepickerRangeContext {
21
21
  }) => void;
22
22
  startInputRef: MutableRefObject<HTMLInputElement | undefined>;
23
23
  endInputRef: MutableRefObject<HTMLInputElement | undefined>;
24
+ customParseDate?: (inputValue?: string) => Date;
24
25
  }
25
26
  export declare const DatepickerRangeContext: import("react").Context<IDatepickerRangeContext | undefined>;
26
27
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-datepickers",
3
- "version": "8.49.1",
3
+ "version": "8.49.2",
4
4
  "description": "Components relating to datepickers in the Garden Design System",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Zendesk Garden <garden@zendesk.com>",
@@ -33,7 +33,7 @@
33
33
  "styled-components": "^4.2.0 || ^5.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@zendeskgarden/react-theming": "^8.49.1",
36
+ "@zendeskgarden/react-theming": "^8.49.2",
37
37
  "@zendeskgarden/svg-icons": "6.30.2"
38
38
  },
39
39
  "keywords": [
@@ -46,5 +46,5 @@
46
46
  "access": "public"
47
47
  },
48
48
  "zendeskgarden:src": "src/index.ts",
49
- "gitHead": "40c9f918b5517480f73fc0ed4a47ffde212b28b6"
49
+ "gitHead": "fd7769285a2f4bc1169c63f4db57a85a6e793027"
50
50
  }