@rc-component/dialog 1.6.1 → 1.7.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.
@@ -36,6 +36,9 @@ const Content = /*#__PURE__*/React.forwardRef((props, ref) => {
36
36
  contentStyle.transformOrigin = transformOrigin;
37
37
  }
38
38
  function onPrepare() {
39
+ if (!dialogRef.current?.nativeElement) {
40
+ return;
41
+ }
39
42
  const elementOffset = offset(dialogRef.current.nativeElement);
40
43
  setTransformOrigin(mousePosition && (mousePosition.x || mousePosition.y) ? `${mousePosition.x - elementOffset.left}px ${mousePosition.y - elementOffset.top}px` : '');
41
44
  }
@@ -2,7 +2,6 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  import { clsx } from 'clsx';
3
3
  import contains from "@rc-component/util/es/Dom/contains";
4
4
  import useId from "@rc-component/util/es/hooks/useId";
5
- import KeyCode from "@rc-component/util/es/KeyCode";
6
5
  import pickAttrs from "@rc-component/util/es/pickAttrs";
7
6
  import * as React from 'react';
8
7
  import { useEffect, useRef } from 'react';
@@ -15,10 +14,7 @@ const Dialog = props => {
15
14
  prefixCls = 'rc-dialog',
16
15
  zIndex,
17
16
  visible = false,
18
- keyboard = true,
19
17
  focusTriggerAfterClose = true,
20
- // scrollLocker,
21
- // Wrapper
22
18
  wrapStyle,
23
19
  wrapClassName,
24
20
  wrapProps,
@@ -131,13 +127,6 @@ const Dialog = props => {
131
127
  }
132
128
  };
133
129
  }
134
- function onWrapperKeyDown(e) {
135
- if (keyboard && e.keyCode === KeyCode.ESC) {
136
- e.stopPropagation();
137
- onInternalClose(e);
138
- return;
139
- }
140
- }
141
130
 
142
131
  // ========================= Effect =========================
143
132
  useEffect(() => {
@@ -184,7 +173,6 @@ const Dialog = props => {
184
173
  maskProps: maskProps,
185
174
  className: modalClassNames?.mask
186
175
  }), /*#__PURE__*/React.createElement("div", _extends({
187
- onKeyDown: onWrapperKeyDown,
188
176
  className: clsx(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper),
189
177
  ref: wrapperRef,
190
178
  onClick: onWrapperClick,
package/es/DialogWrap.js CHANGED
@@ -20,12 +20,24 @@ const DialogWrap = props => {
20
20
  destroyOnHidden = false,
21
21
  afterClose,
22
22
  closable,
23
- panelRef
23
+ panelRef,
24
+ keyboard = true,
25
+ onClose
24
26
  } = props;
25
27
  const [animatedVisible, setAnimatedVisible] = React.useState(visible);
26
28
  const refContext = React.useMemo(() => ({
27
29
  panel: panelRef
28
30
  }), [panelRef]);
31
+ const onEsc = ({
32
+ top,
33
+ event
34
+ }) => {
35
+ if (top && keyboard) {
36
+ event.stopPropagation();
37
+ onClose?.(event);
38
+ return;
39
+ }
40
+ };
29
41
  React.useEffect(() => {
30
42
  if (visible) {
31
43
  setAnimatedVisible(true);
@@ -40,6 +52,7 @@ const DialogWrap = props => {
40
52
  value: refContext
41
53
  }, /*#__PURE__*/React.createElement(Portal, {
42
54
  open: visible || forceRender || animatedVisible,
55
+ onEsc: onEsc,
43
56
  autoDestroy: false,
44
57
  getContainer: getContainer,
45
58
  autoLock: visible || animatedVisible
@@ -17,7 +17,7 @@ export type IDialogPropTypes = {
17
17
  children?: React.ReactNode;
18
18
  afterClose?: () => any;
19
19
  afterOpenChange?: (open: boolean) => void;
20
- onClose?: (e: SyntheticEvent) => any;
20
+ onClose?: (e: SyntheticEvent | KeyboardEvent) => any;
21
21
  closable?: boolean | (ClosableType & React.AriaAttributes);
22
22
  maskClosable?: boolean;
23
23
  visible?: boolean;
@@ -45,6 +45,9 @@ const Content = /*#__PURE__*/React.forwardRef((props, ref) => {
45
45
  contentStyle.transformOrigin = transformOrigin;
46
46
  }
47
47
  function onPrepare() {
48
+ if (!dialogRef.current?.nativeElement) {
49
+ return;
50
+ }
48
51
  const elementOffset = (0, _util.offset)(dialogRef.current.nativeElement);
49
52
  setTransformOrigin(mousePosition && (mousePosition.x || mousePosition.y) ? `${mousePosition.x - elementOffset.left}px ${mousePosition.y - elementOffset.top}px` : '');
50
53
  }
@@ -7,7 +7,6 @@ exports.default = void 0;
7
7
  var _clsx = require("clsx");
8
8
  var _contains = _interopRequireDefault(require("@rc-component/util/lib/Dom/contains"));
9
9
  var _useId = _interopRequireDefault(require("@rc-component/util/lib/hooks/useId"));
10
- var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
11
10
  var _pickAttrs = _interopRequireDefault(require("@rc-component/util/lib/pickAttrs"));
12
11
  var _react = _interopRequireWildcard(require("react"));
13
12
  var React = _react;
@@ -24,10 +23,7 @@ const Dialog = props => {
24
23
  prefixCls = 'rc-dialog',
25
24
  zIndex,
26
25
  visible = false,
27
- keyboard = true,
28
26
  focusTriggerAfterClose = true,
29
- // scrollLocker,
30
- // Wrapper
31
27
  wrapStyle,
32
28
  wrapClassName,
33
29
  wrapProps,
@@ -140,13 +136,6 @@ const Dialog = props => {
140
136
  }
141
137
  };
142
138
  }
143
- function onWrapperKeyDown(e) {
144
- if (keyboard && e.keyCode === _KeyCode.default.ESC) {
145
- e.stopPropagation();
146
- onInternalClose(e);
147
- return;
148
- }
149
- }
150
139
 
151
140
  // ========================= Effect =========================
152
141
  (0, _react.useEffect)(() => {
@@ -193,7 +182,6 @@ const Dialog = props => {
193
182
  maskProps: maskProps,
194
183
  className: modalClassNames?.mask
195
184
  }), /*#__PURE__*/React.createElement("div", _extends({
196
- onKeyDown: onWrapperKeyDown,
197
185
  className: (0, _clsx.clsx)(`${prefixCls}-wrap`, wrapClassName, modalClassNames?.wrapper),
198
186
  ref: wrapperRef,
199
187
  onClick: onWrapperClick,
package/lib/DialogWrap.js CHANGED
@@ -29,12 +29,24 @@ const DialogWrap = props => {
29
29
  destroyOnHidden = false,
30
30
  afterClose,
31
31
  closable,
32
- panelRef
32
+ panelRef,
33
+ keyboard = true,
34
+ onClose
33
35
  } = props;
34
36
  const [animatedVisible, setAnimatedVisible] = React.useState(visible);
35
37
  const refContext = React.useMemo(() => ({
36
38
  panel: panelRef
37
39
  }), [panelRef]);
40
+ const onEsc = ({
41
+ top,
42
+ event
43
+ }) => {
44
+ if (top && keyboard) {
45
+ event.stopPropagation();
46
+ onClose?.(event);
47
+ return;
48
+ }
49
+ };
38
50
  React.useEffect(() => {
39
51
  if (visible) {
40
52
  setAnimatedVisible(true);
@@ -49,6 +61,7 @@ const DialogWrap = props => {
49
61
  value: refContext
50
62
  }, /*#__PURE__*/React.createElement(_portal.default, {
51
63
  open: visible || forceRender || animatedVisible,
64
+ onEsc: onEsc,
52
65
  autoDestroy: false,
53
66
  getContainer: getContainer,
54
67
  autoLock: visible || animatedVisible
@@ -17,7 +17,7 @@ export type IDialogPropTypes = {
17
17
  children?: React.ReactNode;
18
18
  afterClose?: () => any;
19
19
  afterOpenChange?: (open: boolean) => void;
20
- onClose?: (e: SyntheticEvent) => any;
20
+ onClose?: (e: SyntheticEvent | KeyboardEvent) => any;
21
21
  closable?: boolean | (ClosableType & React.AriaAttributes);
22
22
  maskClosable?: boolean;
23
23
  visible?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/dialog",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "dialog ui component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@rc-component/motion": "^1.1.3",
54
- "@rc-component/portal": "^2.0.0",
54
+ "@rc-component/portal": "^2.1.0",
55
55
  "@rc-component/util": "^1.5.0",
56
56
  "clsx": "^2.1.1"
57
57
  },
@@ -67,10 +67,10 @@
67
67
  "@types/node": "^24.0.8",
68
68
  "@types/react": "^19.1.4",
69
69
  "@types/react-dom": "^19.1.5",
70
- "@umijs/fabric": "^3.0.0",
70
+ "@umijs/fabric": "^4.0.0",
71
71
  "bootstrap": "^5.3.7",
72
72
  "dumi": "^2.1.3",
73
- "eslint": "^7.1.0",
73
+ "eslint": "8.x",
74
74
  "father": "^4.1.5",
75
75
  "gh-pages": "^6.1.1",
76
76
  "glob": "^11.0.0",
@@ -88,4 +88,4 @@
88
88
  "react": ">=18.0.0",
89
89
  "react-dom": ">=18.0.0"
90
90
  }
91
- }
91
+ }