@rc-component/dialog 1.5.1 → 1.6.1

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 +2 -1
  47. package/es/Dialog/Content/Panel.js +10 -38
  48. package/es/Dialog/index.js +9 -8
  49. package/lib/Dialog/Content/Panel.d.ts +2 -1
  50. package/lib/Dialog/Content/Panel.js +10 -38
  51. package/lib/Dialog/index.js +9 -8
  52. package/package.json +2 -2
@@ -6,10 +6,11 @@ export interface PanelProps extends Omit<IDialogPropTypes, 'getOpenCount'> {
6
6
  onMouseDown?: React.MouseEventHandler;
7
7
  onMouseUp?: React.MouseEventHandler;
8
8
  holderRef?: React.Ref<HTMLDivElement>;
9
+ /** Used for focus lock. When true and open, focus will lock into the panel */
10
+ isFixedPos?: boolean;
9
11
  }
10
12
  export type PanelRef = {
11
13
  focus: () => void;
12
- changeActive: (next: boolean) => void;
13
14
  };
14
15
  declare const Panel: React.ForwardRefExoticComponent<PanelProps & React.RefAttributes<PanelRef>>;
15
16
  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,
@@ -37,35 +29,22 @@ const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
37
29
  width,
38
30
  height,
39
31
  classNames: modalClassNames,
40
- styles: modalStyles
32
+ styles: modalStyles,
33
+ isFixedPos
41
34
  } = props;
42
35
 
43
36
  // ================================= Refs =================================
44
37
  const {
45
38
  panel: panelRef
46
39
  } = React.useContext(RefContext);
47
- const mergedRef = useComposeRef(holderRef, panelRef);
48
- const sentinelStartRef = useRef(null);
49
- const sentinelEndRef = useRef(null);
40
+ const internalRef = useRef(null);
41
+ const mergedRef = useComposeRef(holderRef, panelRef, internalRef);
42
+ useLockFocus(visible && isFixedPos, () => internalRef.current);
50
43
  React.useImperativeHandle(ref, () => ({
51
44
  focus: () => {
52
- sentinelStartRef.current?.focus({
45
+ internalRef.current?.focus({
53
46
  preventScroll: true
54
47
  });
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
48
  }
70
49
  }));
71
50
 
@@ -141,18 +120,11 @@ const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
141
120
  },
142
121
  className: clsx(prefixCls, className),
143
122
  onMouseDown: onMouseDown,
144
- onMouseUp: onMouseUp
145
- }, /*#__PURE__*/React.createElement("div", {
146
- ref: sentinelStartRef,
147
- tabIndex: 0,
148
- style: entityStyle
123
+ onMouseUp: onMouseUp,
124
+ tabIndex: -1
149
125
  }, /*#__PURE__*/React.createElement(MemoChildren, {
150
126
  shouldUpdate: visible || forceRender
151
- }, modalRender ? modalRender(content) : content)), /*#__PURE__*/React.createElement("div", {
152
- tabIndex: 0,
153
- ref: sentinelEndRef,
154
- style: sentinelStyle
155
- }));
127
+ }, modalRender ? modalRender(content) : content));
156
128
  });
157
129
  if (process.env.NODE_ENV !== 'production') {
158
130
  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) {
@@ -54,6 +53,7 @@ const Dialog = props => {
54
53
  const wrapperRef = useRef(null);
55
54
  const contentRef = useRef(null);
56
55
  const [animatedVisible, setAnimatedVisible] = React.useState(visible);
56
+ const [isFixedPos, setIsFixedPos] = React.useState(false);
57
57
 
58
58
  // ========================== Init ==========================
59
59
  const ariaId = useId();
@@ -108,7 +108,7 @@ const Dialog = props => {
108
108
  const contentClickRef = useRef(false);
109
109
  const contentTimeoutRef = useRef(null);
110
110
 
111
- // We need record content click incase content popup out of dialog
111
+ // We need record content click in case content popup out of dialog
112
112
  const onContentMouseDown = () => {
113
113
  clearTimeout(contentTimeoutRef.current);
114
114
  contentClickRef.current = true;
@@ -137,11 +137,6 @@ const Dialog = props => {
137
137
  onInternalClose(e);
138
138
  return;
139
139
  }
140
-
141
- // keep focus inside dialog
142
- if (visible && e.keyCode === KeyCode.TAB) {
143
- contentRef.current.changeActive(!e.shiftKey);
144
- }
145
140
  }
146
141
 
147
142
  // ========================= Effect =========================
@@ -149,6 +144,12 @@ const Dialog = props => {
149
144
  if (visible) {
150
145
  setAnimatedVisible(true);
151
146
  saveLastOutSideActiveElementRef();
147
+
148
+ // Calc the position style
149
+ if (wrapperRef.current) {
150
+ const computedWrapStyle = getComputedStyle(wrapperRef.current);
151
+ setIsFixedPos(computedWrapStyle.position === 'fixed');
152
+ }
152
153
  } else if (animatedVisible && contentRef.current.enableMotion() && !contentRef.current.inMotion()) {
153
154
  doClose();
154
155
  }
@@ -183,13 +184,13 @@ const Dialog = props => {
183
184
  maskProps: maskProps,
184
185
  className: modalClassNames?.mask
185
186
  }), /*#__PURE__*/React.createElement("div", _extends({
186
- tabIndex: -1,
187
187
  onKeyDown: onWrapperKeyDown,
188
188
  className: clsx(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper),
189
189
  ref: wrapperRef,
190
190
  onClick: onWrapperClick,
191
191
  style: mergedStyle
192
192
  }, wrapProps), /*#__PURE__*/React.createElement(Content, _extends({}, props, {
193
+ isFixedPos: isFixedPos,
193
194
  onMouseDown: onContentMouseDown,
194
195
  onMouseUp: onContentMouseUp,
195
196
  ref: contentRef,
@@ -6,10 +6,11 @@ export interface PanelProps extends Omit<IDialogPropTypes, 'getOpenCount'> {
6
6
  onMouseDown?: React.MouseEventHandler;
7
7
  onMouseUp?: React.MouseEventHandler;
8
8
  holderRef?: React.Ref<HTMLDivElement>;
9
+ /** Used for focus lock. When true and open, focus will lock into the panel */
10
+ isFixedPos?: boolean;
9
11
  }
10
12
  export type PanelRef = {
11
13
  focus: () => void;
12
- changeActive: (next: boolean) => void;
13
14
  };
14
15
  declare const Panel: React.ForwardRefExoticComponent<PanelProps & React.RefAttributes<PanelRef>>;
15
16
  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,
@@ -46,35 +38,22 @@ const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
46
38
  width,
47
39
  height,
48
40
  classNames: modalClassNames,
49
- styles: modalStyles
41
+ styles: modalStyles,
42
+ isFixedPos
50
43
  } = props;
51
44
 
52
45
  // ================================= Refs =================================
53
46
  const {
54
47
  panel: panelRef
55
48
  } = _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);
49
+ const internalRef = (0, _react.useRef)(null);
50
+ const mergedRef = (0, _ref.useComposeRef)(holderRef, panelRef, internalRef);
51
+ (0, _focus.useLockFocus)(visible && isFixedPos, () => internalRef.current);
59
52
  _react.default.useImperativeHandle(ref, () => ({
60
53
  focus: () => {
61
- sentinelStartRef.current?.focus({
54
+ internalRef.current?.focus({
62
55
  preventScroll: true
63
56
  });
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
57
  }
79
58
  }));
80
59
 
@@ -150,18 +129,11 @@ const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
150
129
  },
151
130
  className: (0, _clsx.clsx)(prefixCls, className),
152
131
  onMouseDown: onMouseDown,
153
- onMouseUp: onMouseUp
154
- }, /*#__PURE__*/_react.default.createElement("div", {
155
- ref: sentinelStartRef,
156
- tabIndex: 0,
157
- style: entityStyle
132
+ onMouseUp: onMouseUp,
133
+ tabIndex: -1
158
134
  }, /*#__PURE__*/_react.default.createElement(_MemoChildren.default, {
159
135
  shouldUpdate: visible || forceRender
160
- }, modalRender ? modalRender(content) : content)), /*#__PURE__*/_react.default.createElement("div", {
161
- tabIndex: 0,
162
- ref: sentinelEndRef,
163
- style: sentinelStyle
164
- }));
136
+ }, modalRender ? modalRender(content) : content));
165
137
  });
166
138
  if (process.env.NODE_ENV !== 'production') {
167
139
  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) {
@@ -63,6 +62,7 @@ const Dialog = props => {
63
62
  const wrapperRef = (0, _react.useRef)(null);
64
63
  const contentRef = (0, _react.useRef)(null);
65
64
  const [animatedVisible, setAnimatedVisible] = React.useState(visible);
65
+ const [isFixedPos, setIsFixedPos] = React.useState(false);
66
66
 
67
67
  // ========================== Init ==========================
68
68
  const ariaId = (0, _useId.default)();
@@ -117,7 +117,7 @@ const Dialog = props => {
117
117
  const contentClickRef = (0, _react.useRef)(false);
118
118
  const contentTimeoutRef = (0, _react.useRef)(null);
119
119
 
120
- // We need record content click incase content popup out of dialog
120
+ // We need record content click in case content popup out of dialog
121
121
  const onContentMouseDown = () => {
122
122
  clearTimeout(contentTimeoutRef.current);
123
123
  contentClickRef.current = true;
@@ -146,11 +146,6 @@ const Dialog = props => {
146
146
  onInternalClose(e);
147
147
  return;
148
148
  }
149
-
150
- // keep focus inside dialog
151
- if (visible && e.keyCode === _KeyCode.default.TAB) {
152
- contentRef.current.changeActive(!e.shiftKey);
153
- }
154
149
  }
155
150
 
156
151
  // ========================= Effect =========================
@@ -158,6 +153,12 @@ const Dialog = props => {
158
153
  if (visible) {
159
154
  setAnimatedVisible(true);
160
155
  saveLastOutSideActiveElementRef();
156
+
157
+ // Calc the position style
158
+ if (wrapperRef.current) {
159
+ const computedWrapStyle = getComputedStyle(wrapperRef.current);
160
+ setIsFixedPos(computedWrapStyle.position === 'fixed');
161
+ }
161
162
  } else if (animatedVisible && contentRef.current.enableMotion() && !contentRef.current.inMotion()) {
162
163
  doClose();
163
164
  }
@@ -192,13 +193,13 @@ const Dialog = props => {
192
193
  maskProps: maskProps,
193
194
  className: modalClassNames?.mask
194
195
  }), /*#__PURE__*/React.createElement("div", _extends({
195
- tabIndex: -1,
196
196
  onKeyDown: onWrapperKeyDown,
197
197
  className: (0, _clsx.clsx)(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper),
198
198
  ref: wrapperRef,
199
199
  onClick: onWrapperClick,
200
200
  style: mergedStyle
201
201
  }, wrapProps), /*#__PURE__*/React.createElement(_Content.default, _extends({}, props, {
202
+ isFixedPos: isFixedPos,
202
203
  onMouseDown: onContentMouseDown,
203
204
  onMouseUp: onContentMouseUp,
204
205
  ref: contentRef,
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.1",
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": {