@douyinfe/semi-ui 2.7.0-beta.0 → 2.8.0-beta.0

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.
Files changed (70) hide show
  1. package/_base/_story/index.stories.js +2 -6
  2. package/_portal/_story/portal.stories.js +1 -5
  3. package/_utils/hooks/usePrevFocus.ts +1 -0
  4. package/_utils/index.ts +29 -1
  5. package/datePicker/_story/v2/FixDefaultPickerValue.jsx +31 -0
  6. package/datePicker/_story/v2/InsetInput.jsx +1 -1
  7. package/datePicker/_story/v2/index.js +1 -0
  8. package/datePicker/monthsGrid.tsx +3 -13
  9. package/dist/css/semi.css +30 -21
  10. package/dist/css/semi.min.css +1 -1
  11. package/dist/umd/semi-ui.js +627 -287
  12. package/dist/umd/semi-ui.js.map +1 -1
  13. package/dist/umd/semi-ui.min.js +1 -1
  14. package/dist/umd/semi-ui.min.js.map +1 -1
  15. package/form/hooks/useFormApi.tsx +3 -2
  16. package/input/_story/input.stories.js +10 -1
  17. package/inputNumber/_story/inputNumber.stories.js +4 -0
  18. package/lib/cjs/_utils/hooks/usePrevFocus.js +1 -0
  19. package/lib/cjs/_utils/index.d.ts +3 -1
  20. package/lib/cjs/_utils/index.js +25 -1
  21. package/lib/cjs/datePicker/monthsGrid.js +11 -19
  22. package/lib/cjs/form/hooks/useFormApi.d.ts +2 -1
  23. package/lib/cjs/modal/useModal/HookModal.js +2 -0
  24. package/lib/cjs/notification/useNotification/index.js +1 -1
  25. package/lib/cjs/popover/index.d.ts +18 -3
  26. package/lib/cjs/popover/index.js +53 -23
  27. package/lib/cjs/radio/radioGroup.js +6 -0
  28. package/lib/cjs/select/index.js +5 -2
  29. package/lib/cjs/tag/group.d.ts +2 -0
  30. package/lib/cjs/tag/group.js +4 -2
  31. package/lib/cjs/tooltip/index.d.ts +22 -4
  32. package/lib/cjs/tooltip/index.js +65 -27
  33. package/lib/cjs/tree/nodeList.js +1 -0
  34. package/lib/cjs/treeSelect/index.js +4 -0
  35. package/lib/es/_utils/hooks/usePrevFocus.js +2 -0
  36. package/lib/es/_utils/index.d.ts +3 -1
  37. package/lib/es/_utils/index.js +18 -0
  38. package/lib/es/datePicker/monthsGrid.js +11 -19
  39. package/lib/es/form/hooks/useFormApi.d.ts +2 -1
  40. package/lib/es/modal/useModal/HookModal.js +2 -0
  41. package/lib/es/notification/useNotification/index.js +2 -1
  42. package/lib/es/popover/index.d.ts +18 -3
  43. package/lib/es/popover/index.js +52 -23
  44. package/lib/es/radio/radioGroup.js +6 -0
  45. package/lib/es/select/index.js +5 -2
  46. package/lib/es/tag/group.d.ts +2 -0
  47. package/lib/es/tag/group.js +4 -2
  48. package/lib/es/tooltip/index.d.ts +22 -4
  49. package/lib/es/tooltip/index.js +65 -27
  50. package/lib/es/tree/nodeList.js +1 -0
  51. package/lib/es/treeSelect/index.js +4 -0
  52. package/modal/_story/modal.stories.js +93 -1
  53. package/modal/useModal/HookModal.tsx +1 -0
  54. package/notification/_story/useNotification/index.jsx +21 -7
  55. package/notification/useNotification/index.tsx +1 -1
  56. package/package.json +9 -9
  57. package/popover/_story/popover.stories.js +75 -1
  58. package/popover/index.tsx +24 -8
  59. package/radio/__test__/radioGroup.test.jsx +9 -1
  60. package/radio/_story/radio.stories.js +22 -1
  61. package/radio/radioGroup.tsx +9 -0
  62. package/select/_story/select.stories.js +73 -2
  63. package/select/index.tsx +5 -3
  64. package/table/_story/v2/FixedMemoryLeak/index.jsx +33 -0
  65. package/table/_story/v2/index.js +2 -1
  66. package/tag/group.tsx +5 -3
  67. package/toast/_story/toast.stories.js +41 -0
  68. package/tooltip/index.tsx +72 -22
  69. package/tree/nodeList.tsx +1 -0
  70. package/treeSelect/index.tsx +3 -0
@@ -1,6 +1,7 @@
1
+ import { BaseFormApi } from '@douyinfe/semi-foundation/form/interface';
1
2
  import React, { useContext } from 'react';
2
3
  import { FormApiContext } from '../context';
3
4
 
4
- export default function useFormApi() {
5
- return useContext(FormApiContext);
5
+ export default function useFormApi<T extends Record<string, any> = any>() {
6
+ return useContext<BaseFormApi<T>>(FormApiContext);
6
7
  }
@@ -897,4 +897,13 @@ export const InputFocus = () => {
897
897
  <Input ref={ref} onChange={() => console.log('ref', ref) } onFocus={() => console.log('focus')} />
898
898
  </>
899
899
  );
900
- };
900
+ };
901
+
902
+ export const TextAreaAutosize = () => {
903
+ return (
904
+ <div style={{ width: 200 }}>
905
+ <TextArea autosize />
906
+ </div>
907
+ )
908
+ };
909
+ TextAreaAutosize.storyName = "textarea autosize";
@@ -63,6 +63,10 @@ export const _InputNumber = () => {
63
63
  />
64
64
  <br />
65
65
 
66
+ <label>小数(没有初始化值)</label>
67
+ <InputNumber precision={2} onChange={log} />
68
+ <br />
69
+
66
70
  <label>小数</label>
67
71
  <InputNumber defaultValue={10.08} precision={2} onChange={log} />
68
72
  <br />
@@ -18,6 +18,7 @@ var _react = require("react");
18
18
 
19
19
  var _index = require("../index");
20
20
 
21
+ /* istanbul ignore next */
21
22
  function usePrevFocus() {
22
23
  const [prevFocusElement, setPrevFocus] = (0, _react.useState)((0, _index.getActiveElement)());
23
24
  (0, _react.useEffect)(() => {
@@ -67,4 +67,6 @@ export interface HighLightTextHTMLChunk {
67
67
  * @returns boolean
68
68
  */
69
69
  export declare const isSemiIcon: (icon: any) => boolean;
70
- export declare function getActiveElement(): HTMLElement;
70
+ export declare function getActiveElement(): HTMLElement | null;
71
+ export declare function isNodeContainsFocus(node: HTMLElement): boolean;
72
+ export declare function getFocusableElements(node: HTMLElement): HTMLElement[];
@@ -10,7 +10,10 @@ _Object$defineProperty(exports, "__esModule", {
10
10
 
11
11
  exports.cloneDeep = cloneDeep;
12
12
  exports.getActiveElement = getActiveElement;
13
- exports.registerMediaQuery = exports.isSemiIcon = exports.getHighLightTextHTML = void 0;
13
+ exports.getFocusableElements = getFocusableElements;
14
+ exports.getHighLightTextHTML = void 0;
15
+ exports.isNodeContainsFocus = isNodeContainsFocus;
16
+ exports.registerMediaQuery = exports.isSemiIcon = void 0;
14
17
  exports.stopPropagation = stopPropagation;
15
18
 
16
19
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
@@ -23,6 +26,8 @@ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
23
26
 
24
27
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
25
28
 
29
+ var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
30
+
26
31
  var _get2 = _interopRequireDefault(require("lodash/get"));
27
32
 
28
33
  var _set2 = _interopRequireDefault(require("lodash/set"));
@@ -35,6 +40,8 @@ var _warning = _interopRequireDefault(require("@douyinfe/semi-foundation/lib/cjs
35
40
 
36
41
  var _getHighlight = require("@douyinfe/semi-foundation/lib/cjs/utils/getHighlight");
37
42
 
43
+ var _dom = require("@douyinfe/semi-foundation/lib/cjs/utils/dom");
44
+
38
45
  /* eslint-disable max-len */
39
46
 
40
47
  /* argus-disable unPkgSensitiveInfo */
@@ -202,4 +209,21 @@ exports.isSemiIcon = isSemiIcon;
202
209
 
203
210
  function getActiveElement() {
204
211
  return document ? document.activeElement : null;
212
+ }
213
+
214
+ function isNodeContainsFocus(node) {
215
+ const activeElement = getActiveElement();
216
+ return activeElement === node || node.contains(activeElement);
217
+ }
218
+
219
+ function getFocusableElements(node) {
220
+ if (!(0, _dom.isHTMLElement)(node)) {
221
+ return [];
222
+ }
223
+
224
+ const focusableSelectorsList = ["input:not([disabled]):not([tabindex='-1'])", "textarea:not([disabled]):not([tabindex='-1'])", "button:not([disabled]):not([tabindex='-1'])", "a[href]:not([tabindex='-1'])", "select:not([disabled]):not([tabindex='-1'])", "area[href]:not([tabindex='-1'])", "iframe:not([tabindex='-1'])", "object:not([tabindex='-1'])", "*[tabindex]:not([tabindex='-1'])", "*[contenteditable]:not([tabindex='-1'])"];
225
+ const focusableSelectorsStr = focusableSelectorsList.join(','); // we are not filtered elements which are invisible
226
+
227
+ const focusableElements = (0, _from.default)(node.querySelectorAll(focusableSelectorsStr));
228
+ return focusableElements;
205
229
  }
@@ -12,8 +12,6 @@ exports.default = void 0;
12
12
 
13
13
  var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
14
14
 
15
- var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
16
-
17
15
  var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
18
16
 
19
17
  var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
@@ -54,6 +52,8 @@ var _semiIcons = require("@douyinfe/semi-icons");
54
52
 
55
53
  var _getDefaultFormatToken = require("@douyinfe/semi-foundation/lib/cjs/datePicker/_utils/getDefaultFormatToken");
56
54
 
55
+ var _getDefaultPickerDate = _interopRequireDefault(require("@douyinfe/semi-foundation/lib/cjs/datePicker/_utils/getDefaultPickerDate"));
56
+
57
57
  /* eslint-disable jsx-a11y/interactive-supports-focus,jsx-a11y/click-events-have-key-events */
58
58
 
59
59
  /* eslint-disable jsx-a11y/no-static-element-interactions */
@@ -165,23 +165,15 @@ class MonthsGrid extends _baseComponent.default {
165
165
  return this.foundation.getYAMOpenType();
166
166
  };
167
167
 
168
- let nowDate = (0, _isArray.default)(props.defaultPickerValue) ? props.defaultPickerValue[0] : props.defaultPickerValue;
169
168
  const validFormat = props.format || (0, _getDefaultFormatToken.getDefaultFormatTokenByType)(props.type);
170
-
171
- if (!nowDate) {
172
- nowDate = new Date();
173
- } else {
174
- nowDate = (0, _parser.compatiableParse)(nowDate, validFormat, undefined, props.dateFnsLocale);
175
- }
176
-
177
- let nextDate = (0, _isArray.default)(props.defaultPickerValue) ? props.defaultPickerValue[1] : undefined;
178
-
179
- if (!nextDate) {
180
- nextDate = (0, _dateFns.addMonths)(nowDate, 1);
181
- } else {
182
- nextDate = (0, _parser.compatiableParse)(nextDate, validFormat, undefined, props.dateFnsLocale);
183
- }
184
-
169
+ const {
170
+ nowDate,
171
+ nextDate
172
+ } = (0, _getDefaultPickerDate.default)({
173
+ defaultPickerValue: props.defaultPickerValue,
174
+ format: validFormat,
175
+ dateFnsLocale: props.dateFnsLocale
176
+ });
185
177
  const dateState = {
186
178
  // Direct use of full date string storage, mainly considering the month rendering comparison to save a conversion
187
179
  // The selected value for single or multiple selection, full date string, eg. {'2019-10-01', '2019-10-02'}
@@ -676,7 +668,7 @@ class MonthsGrid extends _baseComponent.default {
676
668
  className: monthGridCls,
677
669
  "x-type": type,
678
670
  "x-panel-yearandmonth-open-type": yearOpenType,
679
- "x-insetInput": insetInput ? "true" : "false",
671
+ "x-insetinput": insetInput ? "true" : "false",
680
672
  ref: current => this.cacheRefCurrent('monthGrid', current)
681
673
  }, content);
682
674
  }
@@ -1 +1,2 @@
1
- export default function useFormApi(): import("@douyinfe/semi-foundation/lib/cjs/form/interface").BaseFormApi<any>;
1
+ import { BaseFormApi } from '@douyinfe/semi-foundation/lib/cjs/form/interface';
2
+ export default function useFormApi<T extends Record<string, any> = any>(): BaseFormApi<T>;
@@ -57,6 +57,8 @@ const HookModal = (_a, ref) => {
57
57
  const {
58
58
  motion
59
59
  } = props;
60
+ /* istanbul ignore next */
61
+
60
62
  const mergedMotion = typeof motion === 'undefined' || motion ? (0, _assign.default)((0, _assign.default)({}, motion), {
61
63
  didLeave: function () {
62
64
  const didLeave = (0, _get2.default)(props.motion, 'didLeave');
@@ -111,9 +111,9 @@ function usePatchElement() {
111
111
  function useNotification() {
112
112
  const [elements, patchElement] = usePatchElement();
113
113
  const noticeRef = new _map2.default();
114
- const id = (0, _uuid.default)('semi_notice_');
115
114
 
116
115
  const addNotice = config => {
116
+ const id = (0, _uuid.default)('semi_notice_');
117
117
  const mergeConfig = (0, _assign.default)((0, _assign.default)({}, config), {
118
118
  id
119
119
  }); // eslint-disable-next-line prefer-const
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { ArrowBounding, Position, Trigger } from '../tooltip/index';
3
+ import { ArrowBounding, Position, TooltipProps, Trigger, RenderContentProps } from '../tooltip/index';
4
4
  import '@douyinfe/semi-foundation/lib/cjs/popover/popover.css';
5
5
  import { BaseProps } from '../_base/baseComponent';
6
6
  import { Motion } from '../_base/base';
@@ -12,7 +12,7 @@ declare interface ArrowStyle {
12
12
  }
13
13
  export interface PopoverProps extends BaseProps {
14
14
  children?: React.ReactNode;
15
- content?: React.ReactNode;
15
+ content?: TooltipProps['content'];
16
16
  visible?: boolean;
17
17
  autoAdjustOverflow?: boolean;
18
18
  motion?: Motion;
@@ -33,6 +33,10 @@ export interface PopoverProps extends BaseProps {
33
33
  rePosKey?: string | number;
34
34
  getPopupContainer?: () => HTMLElement;
35
35
  zIndex?: number;
36
+ closeOnEsc?: TooltipProps['closeOnEsc'];
37
+ guardFocus?: TooltipProps['guardFocus'];
38
+ returnFocusOnClose?: TooltipProps['returnFocusOnClose'];
39
+ onEscKeyDown?: TooltipProps['onEscKeyDown'];
36
40
  }
37
41
  export interface PopoverState {
38
42
  popConfirmVisible: boolean;
@@ -64,6 +68,7 @@ declare class Popover extends React.PureComponent<PopoverProps, PopoverState> {
64
68
  arrowPointAtCenter: PropTypes.Requireable<boolean>;
65
69
  arrowBounding: PropTypes.Requireable<object>;
66
70
  prefixCls: PropTypes.Requireable<string>;
71
+ guardFocus: PropTypes.Requireable<boolean>;
67
72
  };
68
73
  static defaultProps: {
69
74
  arrowBounding: {
@@ -82,8 +87,18 @@ declare class Popover extends React.PureComponent<PopoverProps, PopoverState> {
82
87
  position: string;
83
88
  prefixCls: string;
84
89
  onClickOutSide: (...args: any[]) => void;
90
+ onEscKeyDown: (...args: any[]) => void;
91
+ closeOnEsc: boolean;
92
+ returnFocusOnClose: boolean;
93
+ guardFocus: boolean;
85
94
  };
86
- renderPopCard(): JSX.Element;
95
+ renderPopCard: ({ initialFocusRef }: {
96
+ initialFocusRef: RenderContentProps['initialFocusRef'];
97
+ }) => JSX.Element;
98
+ renderContentNode: (props: {
99
+ content: TooltipProps['content'];
100
+ initialFocusRef: RenderContentProps['initialFocusRef'];
101
+ }) => React.ReactNode;
87
102
  render(): JSX.Element;
88
103
  }
89
104
  export default Popover;
@@ -18,6 +18,8 @@ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
18
18
 
19
19
  var _noop2 = _interopRequireDefault(require("lodash/noop"));
20
20
 
21
+ var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
22
+
21
23
  var _react = _interopRequireDefault(require("react"));
22
24
 
23
25
  var _classnames = _interopRequireDefault(require("classnames"));
@@ -49,23 +51,45 @@ const positionSet = _constants.strings.POSITION_SET;
49
51
  const triggerSet = _constants.strings.TRIGGER_SET;
50
52
 
51
53
  class Popover extends _react.default.PureComponent {
52
- renderPopCard() {
53
- const {
54
- content,
55
- contentClassName,
56
- prefixCls
57
- } = this.props;
58
- const {
59
- direction
60
- } = this.context;
61
- const popCardCls = (0, _classnames.default)(prefixCls, contentClassName, {
62
- ["".concat(prefixCls, "-rtl")]: direction === 'rtl'
63
- });
64
- return /*#__PURE__*/_react.default.createElement("div", {
65
- className: popCardCls
66
- }, /*#__PURE__*/_react.default.createElement("div", {
67
- className: "".concat(prefixCls, "-content")
68
- }, content));
54
+ constructor() {
55
+ super(...arguments);
56
+
57
+ this.renderPopCard = _ref => {
58
+ let {
59
+ initialFocusRef
60
+ } = _ref;
61
+ const {
62
+ content,
63
+ contentClassName,
64
+ prefixCls
65
+ } = this.props;
66
+ const {
67
+ direction
68
+ } = this.context;
69
+ const popCardCls = (0, _classnames.default)(prefixCls, contentClassName, {
70
+ ["".concat(prefixCls, "-rtl")]: direction === 'rtl'
71
+ });
72
+ const contentNode = this.renderContentNode({
73
+ initialFocusRef,
74
+ content
75
+ });
76
+ return /*#__PURE__*/_react.default.createElement("div", {
77
+ className: popCardCls
78
+ }, /*#__PURE__*/_react.default.createElement("div", {
79
+ className: "".concat(prefixCls, "-content")
80
+ }, contentNode));
81
+ };
82
+
83
+ this.renderContentNode = props => {
84
+ const {
85
+ initialFocusRef,
86
+ content
87
+ } = props;
88
+ const contentProps = {
89
+ initialFocusRef
90
+ };
91
+ return !(0, _isFunction2.default)(content) ? content : content(contentProps);
92
+ };
69
93
  }
70
94
 
71
95
  render() {
@@ -85,7 +109,6 @@ class Popover extends _react.default.PureComponent {
85
109
  let {
86
110
  spacing
87
111
  } = this.props;
88
- const popContent = this.renderPopCard();
89
112
  const arrowProps = {
90
113
  position,
91
114
  className: '',
@@ -99,11 +122,13 @@ class Popover extends _react.default.PureComponent {
99
122
  }
100
123
 
101
124
  const role = trigger === 'click' || trigger === 'custom' ? 'dialog' : 'tooltip';
102
- return /*#__PURE__*/_react.default.createElement(_index.default, (0, _assign.default)({}, attr, {
125
+ return /*#__PURE__*/_react.default.createElement(_index.default, (0, _assign.default)({
126
+ guardFocus: true
127
+ }, attr, {
103
128
  trigger: trigger,
104
129
  position: position,
105
130
  style: style,
106
- content: popContent,
131
+ content: this.renderPopCard,
107
132
  prefixCls: prefixCls,
108
133
  spacing: spacing,
109
134
  showArrow: arrow,
@@ -117,7 +142,7 @@ class Popover extends _react.default.PureComponent {
117
142
  Popover.contextType = _context.default;
118
143
  Popover.propTypes = {
119
144
  children: _propTypes.default.node,
120
- content: _propTypes.default.node,
145
+ content: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]),
121
146
  visible: _propTypes.default.bool,
122
147
  autoAdjustOverflow: _propTypes.default.bool,
123
148
  motion: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.object, _propTypes.default.func]),
@@ -140,7 +165,8 @@ Popover.propTypes = {
140
165
  }),
141
166
  arrowPointAtCenter: _propTypes.default.bool,
142
167
  arrowBounding: _propTypes.default.object,
143
- prefixCls: _propTypes.default.string
168
+ prefixCls: _propTypes.default.string,
169
+ guardFocus: _propTypes.default.bool
144
170
  };
145
171
  Popover.defaultProps = {
146
172
  arrowBounding: _constants.numbers.ARROW_BOUNDING,
@@ -153,7 +179,11 @@ Popover.defaultProps = {
153
179
  okText: 'Yes',
154
180
  position: 'bottom',
155
181
  prefixCls: _constants.cssClasses.PREFIX,
156
- onClickOutSide: _noop2.default
182
+ onClickOutSide: _noop2.default,
183
+ onEscKeyDown: _noop2.default,
184
+ closeOnEsc: true,
185
+ returnFocusOnClose: true,
186
+ guardFocus: true
157
187
  };
158
188
  var _default = Popover;
159
189
  exports.default = _default;
@@ -55,6 +55,12 @@ class RadioGroup extends _baseComponent.default {
55
55
  }
56
56
 
57
57
  componentDidUpdate(prevProps) {
58
+ if (typeof prevProps.value === 'number' && isNaN(prevProps.value) && typeof this.props.value === 'number' && isNaN(this.props.value)) {
59
+ // `NaN === NaN` returns false, and this will fail the next if check
60
+ // therefore triggering an infinite loop
61
+ return;
62
+ }
63
+
58
64
  if (prevProps.value !== this.props.value) {
59
65
  this.foundation.handlePropValueChange(this.props.value);
60
66
  }
@@ -742,7 +742,9 @@ class Select extends _baseComponent.default {
742
742
  });
743
743
  }
744
744
 
745
- const tags = (0, _map2.default)(selectedItems).call(selectedItems, (item, i) => {
745
+ const mapItems = maxTagCount ? (0, _slice.default)(selectedItems).call(selectedItems, 0, maxTagCount) : selectedItems; // no need to render rest tag when maxTagCount is setting
746
+
747
+ const tags = (0, _map2.default)(mapItems).call(mapItems, (item, i) => {
746
748
  const label = item[0];
747
749
  const {
748
750
  value
@@ -800,12 +802,13 @@ class Select extends _baseComponent.default {
800
802
  const placeholderText = placeholder && !inputValue ? /*#__PURE__*/_react.default.createElement("span", {
801
803
  className: spanCls
802
804
  }, placeholder) : null;
803
- const n = tags.length > maxTagCount ? maxTagCount : undefined;
805
+ const n = selectedItems.length > maxTagCount ? maxTagCount : undefined;
804
806
  const NotOneLine = !maxTagCount; // Multiple lines (that is, do not set maxTagCount), do not use TagGroup, directly traverse with Tag, otherwise Input cannot follow the correct position
805
807
 
806
808
  const tagContent = NotOneLine ? tags : /*#__PURE__*/_react.default.createElement(_group.default, {
807
809
  tagList: tags,
808
810
  maxTagCount: n,
811
+ restCount: maxTagCount ? selectedItems.length - maxTagCount : undefined,
809
812
  size: "large",
810
813
  mode: "custom"
811
814
  });
@@ -7,6 +7,7 @@ export interface TagGroupProps {
7
7
  style?: React.CSSProperties;
8
8
  className?: string;
9
9
  maxTagCount?: number;
10
+ restCount?: number;
10
11
  tagList?: (TagProps | React.ReactNode)[];
11
12
  size?: 'small' | 'large';
12
13
  showPopover?: boolean;
@@ -26,6 +27,7 @@ export default class TagGroup extends PureComponent<TagGroupProps> {
26
27
  style: PropTypes.Requireable<object>;
27
28
  className: PropTypes.Requireable<string>;
28
29
  maxTagCount: PropTypes.Requireable<number>;
30
+ restCount: PropTypes.Requireable<number>;
29
31
  tagList: PropTypes.Requireable<any[]>;
30
32
  size: PropTypes.Requireable<string>;
31
33
  mode: PropTypes.Requireable<string>;
@@ -77,9 +77,10 @@ class TagGroup extends _react.PureComponent {
77
77
  renderMergeTags(tags) {
78
78
  const {
79
79
  maxTagCount,
80
- tagList
80
+ tagList,
81
+ restCount
81
82
  } = this.props;
82
- const n = tagList.length - maxTagCount;
83
+ const n = restCount ? restCount : tagList.length - maxTagCount;
83
84
  let renderTags = tags;
84
85
  const normalTags = (0, _slice.default)(tags).call(tags, 0, maxTagCount);
85
86
  const restTags = (0, _slice.default)(tags).call(tags, maxTagCount);
@@ -156,6 +157,7 @@ TagGroup.propTypes = {
156
157
  style: _propTypes.default.object,
157
158
  className: _propTypes.default.string,
158
159
  maxTagCount: _propTypes.default.number,
160
+ restCount: _propTypes.default.number,
159
161
  tagList: _propTypes.default.array,
160
162
  size: _propTypes.default.oneOf(tagSize),
161
163
  mode: _propTypes.default.string,
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import Event from '@douyinfe/semi-foundation/lib/cjs/utils/Event';
4
4
  import { ArrayElement } from '@douyinfe/semi-foundation/lib/cjs/utils/type';
5
- import { TooltipAdapter, Position } from '@douyinfe/semi-foundation/lib/cjs/tooltip/foundation';
5
+ import TooltipFoundation, { TooltipAdapter, Position } from '@douyinfe/semi-foundation/lib/cjs/tooltip/foundation';
6
6
  import { strings } from '@douyinfe/semi-foundation/lib/cjs/tooltip/constants';
7
7
  import '@douyinfe/semi-foundation/lib/cjs/tooltip/tooltip.css';
8
8
  import BaseComponent, { BaseProps } from '../_base/baseComponent';
@@ -15,6 +15,10 @@ export interface ArrowBounding {
15
15
  width?: number;
16
16
  height?: number;
17
17
  }
18
+ export interface RenderContentProps {
19
+ initialFocusRef?: React.RefObject<HTMLElement>;
20
+ }
21
+ export declare type RenderContent = (props: RenderContentProps) => React.ReactNode;
18
22
  export interface TooltipProps extends BaseProps {
19
23
  children?: React.ReactNode;
20
24
  motion?: Motion;
@@ -28,7 +32,7 @@ export interface TooltipProps extends BaseProps {
28
32
  clickToHide?: boolean;
29
33
  visible?: boolean;
30
34
  style?: React.CSSProperties;
31
- content?: React.ReactNode;
35
+ content?: React.ReactNode | RenderContent;
32
36
  prefixCls?: string;
33
37
  onVisibleChange?: (visible: boolean) => void;
34
38
  onClickOutSide?: (e: React.MouseEvent) => void;
@@ -44,6 +48,10 @@ export interface TooltipProps extends BaseProps {
44
48
  stopPropagation?: boolean;
45
49
  clickTriggerToHide?: boolean;
46
50
  wrapperClassName?: string;
51
+ closeOnEsc?: boolean;
52
+ guardFocus?: boolean;
53
+ returnFocusOnClose?: boolean;
54
+ onEscKeyDown?: (e: React.KeyboardEvent) => void;
47
55
  }
48
56
  interface TooltipState {
49
57
  visible: boolean;
@@ -97,6 +105,8 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
97
105
  stopPropagation: PropTypes.Requireable<boolean>;
98
106
  role: PropTypes.Requireable<string>;
99
107
  wrapWhenSpecial: PropTypes.Requireable<boolean>;
108
+ guardFocus: PropTypes.Requireable<boolean>;
109
+ returnFocusOnClose: PropTypes.Requireable<boolean>;
100
110
  };
101
111
  static defaultProps: {
102
112
  arrowBounding: {
@@ -121,10 +131,15 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
121
131
  showArrow: boolean;
122
132
  wrapWhenSpecial: boolean;
123
133
  zIndex: 1060;
134
+ closeOnEsc: boolean;
135
+ guardFocus: boolean;
136
+ returnFocusOnClose: boolean;
137
+ onEscKeyDown: (...args: any[]) => void;
124
138
  };
125
139
  eventManager: Event;
126
140
  triggerEl: React.RefObject<unknown>;
127
- containerEl: React.RefObject<unknown>;
141
+ containerEl: React.RefObject<HTMLDivElement>;
142
+ initialFocusRef: React.RefObject<HTMLElement>;
128
143
  clickOutsideHandler: any;
129
144
  resizeHandler: any;
130
145
  isWrapped: boolean;
@@ -132,6 +147,7 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
132
147
  scrollHandler: any;
133
148
  getPopupContainer: () => HTMLElement;
134
149
  containerPosition: string;
150
+ foundation: TooltipFoundation;
135
151
  constructor(props: TooltipProps);
136
152
  setContainerEl: (node: HTMLDivElement) => {
137
153
  current: HTMLDivElement;
@@ -142,10 +158,12 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
142
158
  isSpecial: (elem: React.ReactNode | HTMLElement | any) => boolean | "disabled" | "loading";
143
159
  didLeave: () => void;
144
160
  /** for transition - end */
145
- rePosition(): any;
161
+ rePosition(): Record<string, string | number>;
146
162
  componentDidUpdate(prevProps: TooltipProps, prevState: TooltipState): void;
147
163
  renderIcon: () => any;
148
164
  handlePortalInnerClick: (e: React.MouseEvent) => void;
165
+ handlePortalInnerKeyDown: (e: React.KeyboardEvent) => void;
166
+ renderContentNode: (content: TooltipProps['content']) => React.ReactNode;
149
167
  renderPortal: () => JSX.Element;
150
168
  wrapSpan: (elem: React.ReactNode | React.ReactElement) => JSX.Element;
151
169
  mergeEvents: (rawEvents: Record<string, any>, events: Record<string, any>) => {};