@rc-component/dialog 1.5.1 → 1.6.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 (52) hide show
  1. package/README.md +24 -17
  2. package/dist/common-async.js +2518 -0
  3. package/dist/common-async.js.map +1 -0
  4. package/dist/demos-async.css +396 -0
  5. package/dist/demos-async.css.map +1 -0
  6. package/dist/demos-async.js +1242 -0
  7. package/dist/demos-async.js.map +1 -0
  8. package/dist/docs_changelog_md-async.js +2141 -0
  9. package/dist/docs_changelog_md-async.js.map +1 -0
  10. package/dist/docs_demo_ant-design_md-async.js +101 -0
  11. package/dist/docs_demo_ant-design_md-async.js.map +1 -0
  12. package/dist/docs_demo_bootstrap_md-async.js +101 -0
  13. package/dist/docs_demo_bootstrap_md-async.js.map +1 -0
  14. package/dist/docs_demo_draggable_md-async.js +101 -0
  15. package/dist/docs_demo_draggable_md-async.js.map +1 -0
  16. package/dist/docs_demo_multiple-Portal_md-async.js +147 -0
  17. package/dist/docs_demo_multiple-Portal_md-async.js.map +1 -0
  18. package/dist/docs_demo_pure_md-async.js +101 -0
  19. package/dist/docs_demo_pure_md-async.js.map +1 -0
  20. package/dist/docs_index_md-async.js +1754 -0
  21. package/dist/docs_index_md-async.js.map +1 -0
  22. package/dist/dumi__tmp__dumi__theme__ContextWrapper-async.js +201 -0
  23. package/dist/dumi__tmp__dumi__theme__ContextWrapper-async.js.map +1 -0
  24. package/dist/meta__docs-async.css +396 -0
  25. package/dist/meta__docs-async.css.map +1 -0
  26. package/dist/meta__docs-async.js +1048 -0
  27. package/dist/meta__docs-async.js.map +1 -0
  28. package/dist/nm__dumi__dist__client__pages__404-async.js +69 -0
  29. package/dist/nm__dumi__dist__client__pages__404-async.js.map +1 -0
  30. package/dist/nm__dumi__dist__client__pages__Demo__index-async.js +63 -0
  31. package/dist/nm__dumi__dist__client__pages__Demo__index-async.js.map +1 -0
  32. package/dist/node_modules_dumi_dist_client_misc_reactDemoCompiler_js-async.js +368 -0
  33. package/dist/node_modules_dumi_dist_client_misc_reactDemoCompiler_js-async.js.map +1 -0
  34. package/dist/node_modules_dumi_theme-default_layouts_DocLayout_index_js-async.js +1077 -0
  35. package/dist/node_modules_dumi_theme-default_layouts_DocLayout_index_js-async.js.map +1 -0
  36. package/dist/node_modules_react-dom_server_browser_js-async.js +18 -0
  37. package/dist/node_modules_react-dom_server_browser_js-async.js.map +1 -0
  38. package/dist/umi.css +1317 -0
  39. package/dist/umi.css.map +1 -0
  40. package/dist/umi.js +83003 -0
  41. package/dist/umi.js.map +1 -0
  42. package/dist/vendors-async.css +26259 -0
  43. package/dist/vendors-async.css.map +1 -0
  44. package/dist/vendors-async.js +56792 -0
  45. package/dist/vendors-async.js.map +1 -0
  46. package/es/Dialog/Content/Panel.d.ts +0 -1
  47. package/es/Dialog/Content/Panel.js +8 -37
  48. package/es/Dialog/index.js +0 -7
  49. package/lib/Dialog/Content/Panel.d.ts +0 -1
  50. package/lib/Dialog/Content/Panel.js +8 -37
  51. package/lib/Dialog/index.js +0 -7
  52. package/package.json +2 -2
@@ -9,7 +9,6 @@ export interface PanelProps extends Omit<IDialogPropTypes, 'getOpenCount'> {
9
9
  }
10
10
  export type PanelRef = {
11
11
  focus: () => void;
12
- changeActive: (next: boolean) => void;
13
12
  };
14
13
  declare const Panel: React.ForwardRefExoticComponent<PanelProps & React.RefAttributes<PanelRef>>;
15
14
  export default Panel;
@@ -1,19 +1,11 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import { clsx } from 'clsx';
3
3
  import { useComposeRef } from "@rc-component/util/es/ref";
4
+ import { useLockFocus } from "@rc-component/util/es/Dom/focus";
4
5
  import React, { useMemo, useRef } from 'react';
5
6
  import { RefContext } from "../../context";
6
7
  import MemoChildren from "./MemoChildren";
7
8
  import pickAttrs from "@rc-component/util/es/pickAttrs";
8
- const sentinelStyle = {
9
- width: 0,
10
- height: 0,
11
- overflow: 'hidden',
12
- outline: 'none'
13
- };
14
- const entityStyle = {
15
- outline: 'none'
16
- };
17
9
  const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
18
10
  const {
19
11
  prefixCls,
@@ -44,28 +36,14 @@ const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
44
36
  const {
45
37
  panel: panelRef
46
38
  } = React.useContext(RefContext);
47
- const mergedRef = useComposeRef(holderRef, panelRef);
48
- const sentinelStartRef = useRef(null);
49
- const sentinelEndRef = useRef(null);
39
+ const internalRef = useRef(null);
40
+ const mergedRef = useComposeRef(holderRef, panelRef, internalRef);
41
+ useLockFocus(visible, () => internalRef.current);
50
42
  React.useImperativeHandle(ref, () => ({
51
43
  focus: () => {
52
- sentinelStartRef.current?.focus({
44
+ internalRef.current?.focus({
53
45
  preventScroll: true
54
46
  });
55
- },
56
- changeActive: next => {
57
- const {
58
- activeElement
59
- } = document;
60
- if (next && activeElement === sentinelEndRef.current) {
61
- sentinelStartRef.current.focus({
62
- preventScroll: true
63
- });
64
- } else if (!next && activeElement === sentinelStartRef.current) {
65
- sentinelEndRef.current.focus({
66
- preventScroll: true
67
- });
68
- }
69
47
  }
70
48
  }));
71
49
 
@@ -141,18 +119,11 @@ const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
141
119
  },
142
120
  className: clsx(prefixCls, className),
143
121
  onMouseDown: onMouseDown,
144
- onMouseUp: onMouseUp
145
- }, /*#__PURE__*/React.createElement("div", {
146
- ref: sentinelStartRef,
147
- tabIndex: 0,
148
- style: entityStyle
122
+ onMouseUp: onMouseUp,
123
+ tabIndex: -1
149
124
  }, /*#__PURE__*/React.createElement(MemoChildren, {
150
125
  shouldUpdate: visible || forceRender
151
- }, modalRender ? modalRender(content) : content)), /*#__PURE__*/React.createElement("div", {
152
- tabIndex: 0,
153
- ref: sentinelEndRef,
154
- style: sentinelStyle
155
- }));
126
+ }, modalRender ? modalRender(content) : content));
156
127
  });
157
128
  if (process.env.NODE_ENV !== 'production') {
158
129
  Panel.displayName = 'Panel';
@@ -43,7 +43,6 @@ const Dialog = props => {
43
43
  } = props;
44
44
  if (process.env.NODE_ENV !== 'production') {
45
45
  ['wrapStyle', 'bodyStyle', 'maskStyle'].forEach(prop => {
46
- // (prop in props) && console.error(`Warning: ${prop} is deprecated, please use styles instead.`)
47
46
  warning(!(prop in props), `${prop} is deprecated, please use styles instead.`);
48
47
  });
49
48
  if ('wrapClassName' in props) {
@@ -137,11 +136,6 @@ const Dialog = props => {
137
136
  onInternalClose(e);
138
137
  return;
139
138
  }
140
-
141
- // keep focus inside dialog
142
- if (visible && e.keyCode === KeyCode.TAB) {
143
- contentRef.current.changeActive(!e.shiftKey);
144
- }
145
139
  }
146
140
 
147
141
  // ========================= Effect =========================
@@ -183,7 +177,6 @@ const Dialog = props => {
183
177
  maskProps: maskProps,
184
178
  className: modalClassNames?.mask
185
179
  }), /*#__PURE__*/React.createElement("div", _extends({
186
- tabIndex: -1,
187
180
  onKeyDown: onWrapperKeyDown,
188
181
  className: clsx(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper),
189
182
  ref: wrapperRef,
@@ -9,7 +9,6 @@ export interface PanelProps extends Omit<IDialogPropTypes, 'getOpenCount'> {
9
9
  }
10
10
  export type PanelRef = {
11
11
  focus: () => void;
12
- changeActive: (next: boolean) => void;
13
12
  };
14
13
  declare const Panel: React.ForwardRefExoticComponent<PanelProps & React.RefAttributes<PanelRef>>;
15
14
  export default Panel;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _clsx = require("clsx");
8
8
  var _ref = require("@rc-component/util/lib/ref");
9
+ var _focus = require("@rc-component/util/lib/Dom/focus");
9
10
  var _react = _interopRequireWildcard(require("react"));
10
11
  var _context = require("../../context");
11
12
  var _MemoChildren = _interopRequireDefault(require("./MemoChildren"));
@@ -14,15 +15,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
17
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
- const sentinelStyle = {
18
- width: 0,
19
- height: 0,
20
- overflow: 'hidden',
21
- outline: 'none'
22
- };
23
- const entityStyle = {
24
- outline: 'none'
25
- };
26
18
  const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
27
19
  const {
28
20
  prefixCls,
@@ -53,28 +45,14 @@ const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
53
45
  const {
54
46
  panel: panelRef
55
47
  } = _react.default.useContext(_context.RefContext);
56
- const mergedRef = (0, _ref.useComposeRef)(holderRef, panelRef);
57
- const sentinelStartRef = (0, _react.useRef)(null);
58
- const sentinelEndRef = (0, _react.useRef)(null);
48
+ const internalRef = (0, _react.useRef)(null);
49
+ const mergedRef = (0, _ref.useComposeRef)(holderRef, panelRef, internalRef);
50
+ (0, _focus.useLockFocus)(visible, () => internalRef.current);
59
51
  _react.default.useImperativeHandle(ref, () => ({
60
52
  focus: () => {
61
- sentinelStartRef.current?.focus({
53
+ internalRef.current?.focus({
62
54
  preventScroll: true
63
55
  });
64
- },
65
- changeActive: next => {
66
- const {
67
- activeElement
68
- } = document;
69
- if (next && activeElement === sentinelEndRef.current) {
70
- sentinelStartRef.current.focus({
71
- preventScroll: true
72
- });
73
- } else if (!next && activeElement === sentinelStartRef.current) {
74
- sentinelEndRef.current.focus({
75
- preventScroll: true
76
- });
77
- }
78
56
  }
79
57
  }));
80
58
 
@@ -150,18 +128,11 @@ const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
150
128
  },
151
129
  className: (0, _clsx.clsx)(prefixCls, className),
152
130
  onMouseDown: onMouseDown,
153
- onMouseUp: onMouseUp
154
- }, /*#__PURE__*/_react.default.createElement("div", {
155
- ref: sentinelStartRef,
156
- tabIndex: 0,
157
- style: entityStyle
131
+ onMouseUp: onMouseUp,
132
+ tabIndex: -1
158
133
  }, /*#__PURE__*/_react.default.createElement(_MemoChildren.default, {
159
134
  shouldUpdate: visible || forceRender
160
- }, modalRender ? modalRender(content) : content)), /*#__PURE__*/_react.default.createElement("div", {
161
- tabIndex: 0,
162
- ref: sentinelEndRef,
163
- style: sentinelStyle
164
- }));
135
+ }, modalRender ? modalRender(content) : content));
165
136
  });
166
137
  if (process.env.NODE_ENV !== 'production') {
167
138
  Panel.displayName = 'Panel';
@@ -52,7 +52,6 @@ const Dialog = props => {
52
52
  } = props;
53
53
  if (process.env.NODE_ENV !== 'production') {
54
54
  ['wrapStyle', 'bodyStyle', 'maskStyle'].forEach(prop => {
55
- // (prop in props) && console.error(`Warning: ${prop} is deprecated, please use styles instead.`)
56
55
  (0, _warning.warning)(!(prop in props), `${prop} is deprecated, please use styles instead.`);
57
56
  });
58
57
  if ('wrapClassName' in props) {
@@ -146,11 +145,6 @@ const Dialog = props => {
146
145
  onInternalClose(e);
147
146
  return;
148
147
  }
149
-
150
- // keep focus inside dialog
151
- if (visible && e.keyCode === _KeyCode.default.TAB) {
152
- contentRef.current.changeActive(!e.shiftKey);
153
- }
154
148
  }
155
149
 
156
150
  // ========================= Effect =========================
@@ -192,7 +186,6 @@ const Dialog = props => {
192
186
  maskProps: maskProps,
193
187
  className: modalClassNames?.mask
194
188
  }), /*#__PURE__*/React.createElement("div", _extends({
195
- tabIndex: -1,
196
189
  onKeyDown: onWrapperKeyDown,
197
190
  className: (0, _clsx.clsx)(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper),
198
191
  ref: wrapperRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/dialog",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "dialog ui component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -52,7 +52,7 @@
52
52
  "dependencies": {
53
53
  "@rc-component/motion": "^1.1.3",
54
54
  "@rc-component/portal": "^2.0.0",
55
- "@rc-component/util": "^1.0.1",
55
+ "@rc-component/util": "^1.5.0",
56
56
  "clsx": "^2.1.1"
57
57
  },
58
58
  "devDependencies": {