@douyinfe/semi-ui 2.2.1 → 2.2.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.
@@ -968,4 +968,97 @@ describe(`DatePicker`, () => {
968
968
 
969
969
  it('test month sync change dateRange type', () => { testMonthSyncChange('dateRange') });
970
970
  it('test month sync change dateTimeRange type', () => { testMonthSyncChange('dateTimeRange')});
971
+
972
+ it(`test preset given null`, async () => {
973
+ const props = {
974
+ presets: [
975
+ {
976
+ text: 'Today',
977
+ start: null,
978
+ end: null,
979
+ }
980
+ ],
981
+ defaultValue: baseDate,
982
+ defaultOpen: true,
983
+ motion: false,
984
+ type: 'dateRange'
985
+ }
986
+ const handleChange = sinon.spy();
987
+ const demo = mount(<DatePicker {...props} onChange={handleChange} />);
988
+ const elem = demo.find(BaseDatePicker);
989
+
990
+ const btns = document.querySelectorAll('.semi-datepicker-quick-control-item');
991
+
992
+ btns[0].click();
993
+ expect(handleChange.called).toBeTruthy();
994
+ const args = handleChange.getCall(0).args;
995
+ expect(args[0].length).toEqual(0);
996
+ expect(elem.state('panelShow')).toBeFalsy();
997
+ });
998
+
999
+ it(`test preset given null + needConfirm`, async () => {
1000
+ const props = {
1001
+ presets: [
1002
+ {
1003
+ text: 'Today',
1004
+ start: null,
1005
+ end: null,
1006
+ }
1007
+ ],
1008
+ defaultValue: baseDate,
1009
+ defaultOpen: true,
1010
+ motion: false,
1011
+ type: 'dateTimeRange',
1012
+ needConfirm: true,
1013
+ }
1014
+ const handleChange = sinon.spy();
1015
+ const handleConfirm = sinon.spy();
1016
+ const demo = mount(<DatePicker {...props} onChange={handleChange} onConfirm={handleConfirm} />);
1017
+ const elem = demo.find(BaseDatePicker);
1018
+
1019
+ const btns = document.querySelectorAll('.semi-datepicker-quick-control-item');
1020
+
1021
+ // 点击 preset
1022
+ btns[0].click();
1023
+ expect(handleChange.called).toBe(true);
1024
+ const argsChange = handleChange.getCall(0).args;
1025
+ expect(argsChange[0].length).toBe(0);
1026
+ expect(elem.state('panelShow')).toBe(true);
1027
+ // 点击确定
1028
+ const footerBtns = document.querySelectorAll('.semi-datepicker-footer .semi-button');
1029
+ footerBtns[1].click();
1030
+ expect(handleConfirm.called).toBe(true);
1031
+ const argsConfirm = handleConfirm.getCall(0).args;
1032
+ expect(argsConfirm[0].length).toBe(0);
1033
+ expect(elem.state('panelShow')).toBe(false);
1034
+ });
1035
+
1036
+ it('test dateRange triggerRender', async () => {
1037
+ const elem = mount(
1038
+ <DatePicker
1039
+ motion={false}
1040
+ // defaultOpen
1041
+ type="dateRange"
1042
+ triggerRender={({ placeholder }) => (
1043
+ <button>
1044
+ {placeholder}
1045
+ </button>
1046
+ )}
1047
+ />
1048
+ );
1049
+ const trigger = document.querySelector('button');
1050
+ trigger.click();
1051
+ await sleep();
1052
+ const leftPanel = document.querySelector(`.${BASE_CLASS_PREFIX}-datepicker-month-grid-left`);
1053
+ const leftSecondWeek = leftPanel.querySelectorAll(`.${BASE_CLASS_PREFIX}-datepicker-week`)[1];
1054
+ const leftSecondWeekDays = leftSecondWeek.querySelectorAll(`.${BASE_CLASS_PREFIX}-datepicker-day`);
1055
+ const rightPanel = document.querySelector(`.${BASE_CLASS_PREFIX}-datepicker-month-grid-right`);
1056
+ const rightSecondWeek = rightPanel.querySelectorAll(`.${BASE_CLASS_PREFIX}-datepicker-week`)[1];
1057
+ const rightSecondWeekDays = rightSecondWeek.querySelectorAll(`.${BASE_CLASS_PREFIX}-datepicker-day`);
1058
+ leftSecondWeekDays[0].click();
1059
+ rightSecondWeekDays[0].click();
1060
+
1061
+ const baseElem = elem.find(BaseDatePicker);
1062
+ expect(baseElem.state('panelShow')).toBeFalsy();
1063
+ });
971
1064
  });
@@ -10,7 +10,7 @@ import {
10
10
  startOfWeek,
11
11
  endOfWeek,
12
12
  } from 'date-fns';
13
- import { Space, ConfigProvider, InputGroup, InputNumber, Form, withField } from '../../index';
13
+ import { Space, ConfigProvider, InputGroup, InputNumber, Form, withField, Button } from '../../index';
14
14
 
15
15
  // stores
16
16
  import NeedConfirmDemo from './NeedConfirm';
@@ -723,3 +723,86 @@ export const FixNeedConfirm = () => {
723
723
  )
724
724
  }
725
725
  FixNeedConfirm.storyName = '修复 needConfirm 取消后输入框显示错误';
726
+
727
+ /**
728
+ * fix https://github.com/DouyinFE/semi-design/issues/388
729
+ */
730
+ export const FixPresetsClick = () => {
731
+ const presets = [
732
+ {
733
+ text: '清空',
734
+ start: '',
735
+ end: '',
736
+ },
737
+ {
738
+ text: 'Tomorrow',
739
+ start: new Date(new Date().valueOf() + 1000 * 3600 * 24),
740
+ end: new Date(new Date().valueOf() + 1000 * 3600 * 24),
741
+ },
742
+ ];
743
+
744
+ const handleChange = v => {
745
+ console.log('change', v);
746
+ };
747
+
748
+ const handleConfirm = v => {
749
+ console.log('confirm', v);
750
+ }
751
+
752
+ return (
753
+ <div>
754
+ <div>
755
+ <label>
756
+ <span>不设置 needConfirm</span>
757
+ <DatePicker onChange={console.log} type="dateRange" presets={presets} />
758
+ </label>
759
+ </div>
760
+ <div>
761
+ <label>
762
+ <span>设置 needConfirm</span>
763
+ <DatePicker needConfirm onChange={handleChange} onConfirm={handleConfirm} type="dateTimeRange" presets={presets} />
764
+ </label>
765
+ </div>
766
+ </div>
767
+ );
768
+ };
769
+ FixPresetsClick.storyName = '修复 presets 点击后不收起问题';
770
+
771
+ /**
772
+ * fix https://github.com/DouyinFE/semi-design/issues/410
773
+ */
774
+ export const FixTriggerRenderClosePanel = () => {
775
+ const [value, setValue] = useState([]);
776
+
777
+ const handleChange = v => {
778
+ console.log('change', v);
779
+ setValue(v);
780
+ };
781
+
782
+ const formatValue = (dates) => {
783
+ const dateStrs = dates.map(v => String(v));
784
+ return dateStrs.join(' ~ ');
785
+ };
786
+
787
+ const showClear = Array.isArray(value) && value.length > 1;
788
+
789
+ return (
790
+ <Space>
791
+ <DatePicker
792
+ value={value}
793
+ type="dateRange"
794
+ onChange={handleChange}
795
+ motion={false}
796
+ triggerRender={({ placeholder }) => (
797
+ <Button>
798
+ {(value && formatValue(value)) || placeholder}
799
+ </Button>
800
+ )}
801
+ />
802
+ {showClear && (
803
+ <Button onClick={() => setValue([])}>清除</Button>
804
+ )}
805
+ </Space>
806
+ );
807
+ };
808
+ FixTriggerRenderClosePanel.storyName = "fix triggerRender close bug"
@@ -363,6 +363,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
363
363
  syncSwitchMonth,
364
364
  onPanelChange,
365
365
  timeZone,
366
+ triggerRender
366
367
  } = this.props;
367
368
  const { value, cachedSelectedValue, motionEnd, rangeInputFocus } = this.state;
368
369
 
@@ -408,6 +409,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
408
409
  onPanelChange={onPanelChange}
409
410
  timeZone={timeZone}
410
411
  focusRecordsRef={this.focusRecordsRef}
412
+ triggerRender={triggerRender}
411
413
  />
412
414
  );
413
415
  }
@@ -71,7 +71,8 @@ export default class MonthsGrid extends BaseComponent<MonthsGridProps, MonthsGri
71
71
  syncSwitchMonth: PropTypes.bool,
72
72
  // Callback function for panel date switching
73
73
  onPanelChange: PropTypes.func,
74
- focusRecordsRef: PropTypes.object
74
+ focusRecordsRef: PropTypes.object,
75
+ triggerRender: PropTypes.func,
75
76
  };
76
77
 
77
78
  static defaultProps = {
@@ -29600,6 +29600,7 @@ const IconUpload_IconComponent = convertIcon(IconUpload_SvgComponent, 'upload');
29600
29600
 
29601
29601
 
29602
29602
 
29603
+
29603
29604
 
29604
29605
 
29605
29606
  // CONCATENATED MODULE: ../semi-icons/lib/es/index.js
@@ -52351,12 +52352,10 @@ class foundation_DatePickerFoundation extends foundation {
52351
52352
  };
52352
52353
 
52353
52354
  this._isRangeValueComplete = value => {
52354
- let result = true;
52355
+ let result = false;
52355
52356
 
52356
52357
  if (is_array_default()(value)) {
52357
52358
  result = !some_default()(value).call(value, date => isNullOrUndefined(date));
52358
- } else {
52359
- result = false;
52360
52359
  }
52361
52360
 
52362
52361
  return result;
@@ -53014,7 +53013,7 @@ class foundation_DatePickerFoundation extends foundation {
53014
53013
 
53015
53014
  if (!this._someDateDisabled(changedDates)) {
53016
53015
  inputValue = this._isMultiple() ? this.formatMultipleDates(dates) : this.formatDates(dates);
53017
- const isRangeTypeAndInputIncomplete = this._isRangeType() && (isNullOrUndefined(dates[0]) || isNullOrUndefined(dates[1]));
53016
+ const isRangeTypeAndInputIncomplete = this._isRangeType() && !this._isRangeValueComplete(dates);
53018
53017
  /**
53019
53018
  * If the input is incomplete when under control, the notifyChange is not triggered because
53020
53019
  * You need to update the value of the input box, otherwise there will be a problem that a date is selected but the input box does not show the date #1357
@@ -54542,6 +54541,7 @@ const getMonthTable = (month, weekStartsOn) => {
54542
54541
 
54543
54542
 
54544
54543
 
54544
+
54545
54545
  /* eslint-disable max-len */
54546
54546
 
54547
54547
 
@@ -55235,13 +55235,16 @@ class monthsGridFoundation_MonthsGridFoundation extends foundation {
55235
55235
  rangeStart,
55236
55236
  rangeEnd
55237
55237
  } = this.getStates();
55238
+
55238
55239
  const {
55239
55240
  startDateOffset,
55240
55241
  endDateOffset,
55241
55242
  type,
55242
55243
  dateFnsLocale,
55243
- rangeInputFocus
55244
- } = this.getProps();
55244
+ rangeInputFocus,
55245
+ triggerRender
55246
+ } = this._adapter.getProps();
55247
+
55245
55248
  const {
55246
55249
  fullDate
55247
55250
  } = day;
@@ -55322,9 +55325,17 @@ class monthsGridFoundation_MonthsGridFoundation extends foundation {
55322
55325
  date = [start, end];
55323
55326
  }
55324
55327
  }
55328
+ /**
55329
+ * no need to check focus then
55330
+ * - dateRange and isDateRangeAndHasOffset
55331
+ * - dateRange and triggerRender
55332
+ */
55333
+
55334
+
55335
+ const needCheckFocusRecord = !(type === 'dateRange' && (isDateRangeAndHasOffset || isFunction_default()(triggerRender)));
55325
55336
 
55326
55337
  this._adapter.notifySelectedChange(date, {
55327
- needCheckFocusRecord: !(type === 'dateRange' && isDateRangeAndHasOffset)
55338
+ needCheckFocusRecord
55328
55339
  });
55329
55340
  }
55330
55341
  }
@@ -58913,7 +58924,8 @@ monthsGrid_MonthsGrid.propTypes = {
58913
58924
  syncSwitchMonth: prop_types_default.a.bool,
58914
58925
  // Callback function for panel date switching
58915
58926
  onPanelChange: prop_types_default.a.func,
58916
- focusRecordsRef: prop_types_default.a.object
58927
+ focusRecordsRef: prop_types_default.a.object,
58928
+ triggerRender: prop_types_default.a.func
58917
58929
  };
58918
58930
  monthsGrid_MonthsGrid.defaultProps = {
58919
58931
  type: 'date',
@@ -59445,7 +59457,8 @@ class datePicker_DatePicker extends baseComponent_BaseComponent {
59445
59457
  density,
59446
59458
  syncSwitchMonth,
59447
59459
  onPanelChange,
59448
- timeZone
59460
+ timeZone,
59461
+ triggerRender
59449
59462
  } = this.props;
59450
59463
  const {
59451
59464
  value,
@@ -59492,7 +59505,8 @@ class datePicker_DatePicker extends baseComponent_BaseComponent {
59492
59505
  syncSwitchMonth: syncSwitchMonth,
59493
59506
  onPanelChange: onPanelChange,
59494
59507
  timeZone: timeZone,
59495
- focusRecordsRef: this.focusRecordsRef
59508
+ focusRecordsRef: this.focusRecordsRef,
59509
+ triggerRender: triggerRender
59496
59510
  });
59497
59511
  }
59498
59512
 
@@ -63797,6 +63811,8 @@ class foundation_InputNumberFoundation extends foundation {
63797
63811
 
63798
63812
  this._adapter.setFocusing(true, null);
63799
63813
 
63814
+ this._adapter.setClickUpOrDown(false);
63815
+
63800
63816
  this._adapter.notifyFocus(e);
63801
63817
  }
63802
63818
  /**
@@ -64135,7 +64151,7 @@ class foundation_InputNumberFoundation extends foundation {
64135
64151
  }
64136
64152
  /**
64137
64153
  * format number to string
64138
- * @param {number} value
64154
+ * @param {string|number} value
64139
64155
  * @param {boolean} needAdjustPrec
64140
64156
  * @returns {string}
64141
64157
  */
@@ -64688,7 +64704,11 @@ class inputNumber_InputNumber extends baseComponent_BaseComponent {
64688
64704
  if (this.foundation.isValidNumber(parsedNum) && parsedNum !== this.state.number) {
64689
64705
  const obj = {
64690
64706
  number: parsedNum
64691
- }; // Updates input when a button is clicked
64707
+ };
64708
+ /**
64709
+ * If you are clicking the button, it will automatically format once
64710
+ * We need to set the status to false after trigger focus event
64711
+ */
64692
64712
 
64693
64713
  if (this.clickUpOrDown) {
64694
64714
  obj.value = this.foundation.doFormat(valueStr, true);
@@ -98708,11 +98728,11 @@ class transfer_Transfer extends baseComponent_BaseComponent {
98708
98728
  }, inputCom, content);
98709
98729
  }
98710
98730
 
98711
- renderGroupTitle(group) {
98731
+ renderGroupTitle(group, index) {
98712
98732
  const groupCls = classnames_default()("".concat(transfer_prefixcls, "-group-title"));
98713
98733
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", {
98714
98734
  className: groupCls,
98715
- key: group.title
98735
+ key: "title-".concat(index)
98716
98736
  }, group.title);
98717
98737
  }
98718
98738
 
@@ -98769,7 +98789,7 @@ class transfer_Transfer extends baseComponent_BaseComponent {
98769
98789
  // group content already insert
98770
98790
  content.push(optionContent);
98771
98791
  } else if (parentGroup) {
98772
- const groupContent = this.renderGroupTitle(parentGroup);
98792
+ const groupContent = this.renderGroupTitle(parentGroup, index);
98773
98793
  groupStatus.set(parentGroup.title, true);
98774
98794
  content.push(groupContent);
98775
98795
  content.push(optionContent);