@rc-component/dialog 1.6.0 → 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.
@@ -6,6 +6,8 @@ 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;
@@ -29,7 +29,8 @@ const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
29
29
  width,
30
30
  height,
31
31
  classNames: modalClassNames,
32
- styles: modalStyles
32
+ styles: modalStyles,
33
+ isFixedPos
33
34
  } = props;
34
35
 
35
36
  // ================================= Refs =================================
@@ -38,7 +39,7 @@ const Panel = /*#__PURE__*/React.forwardRef((props, ref) => {
38
39
  } = React.useContext(RefContext);
39
40
  const internalRef = useRef(null);
40
41
  const mergedRef = useComposeRef(holderRef, panelRef, internalRef);
41
- useLockFocus(visible, () => internalRef.current);
42
+ useLockFocus(visible && isFixedPos, () => internalRef.current);
42
43
  React.useImperativeHandle(ref, () => ({
43
44
  focus: () => {
44
45
  internalRef.current?.focus({
@@ -53,6 +53,7 @@ const Dialog = props => {
53
53
  const wrapperRef = useRef(null);
54
54
  const contentRef = useRef(null);
55
55
  const [animatedVisible, setAnimatedVisible] = React.useState(visible);
56
+ const [isFixedPos, setIsFixedPos] = React.useState(false);
56
57
 
57
58
  // ========================== Init ==========================
58
59
  const ariaId = useId();
@@ -107,7 +108,7 @@ const Dialog = props => {
107
108
  const contentClickRef = useRef(false);
108
109
  const contentTimeoutRef = useRef(null);
109
110
 
110
- // We need record content click incase content popup out of dialog
111
+ // We need record content click in case content popup out of dialog
111
112
  const onContentMouseDown = () => {
112
113
  clearTimeout(contentTimeoutRef.current);
113
114
  contentClickRef.current = true;
@@ -143,6 +144,12 @@ const Dialog = props => {
143
144
  if (visible) {
144
145
  setAnimatedVisible(true);
145
146
  saveLastOutSideActiveElementRef();
147
+
148
+ // Calc the position style
149
+ if (wrapperRef.current) {
150
+ const computedWrapStyle = getComputedStyle(wrapperRef.current);
151
+ setIsFixedPos(computedWrapStyle.position === 'fixed');
152
+ }
146
153
  } else if (animatedVisible && contentRef.current.enableMotion() && !contentRef.current.inMotion()) {
147
154
  doClose();
148
155
  }
@@ -183,6 +190,7 @@ const Dialog = props => {
183
190
  onClick: onWrapperClick,
184
191
  style: mergedStyle
185
192
  }, wrapProps), /*#__PURE__*/React.createElement(Content, _extends({}, props, {
193
+ isFixedPos: isFixedPos,
186
194
  onMouseDown: onContentMouseDown,
187
195
  onMouseUp: onContentMouseUp,
188
196
  ref: contentRef,
@@ -6,6 +6,8 @@ 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;
@@ -38,7 +38,8 @@ const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
38
38
  width,
39
39
  height,
40
40
  classNames: modalClassNames,
41
- styles: modalStyles
41
+ styles: modalStyles,
42
+ isFixedPos
42
43
  } = props;
43
44
 
44
45
  // ================================= Refs =================================
@@ -47,7 +48,7 @@ const Panel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
47
48
  } = _react.default.useContext(_context.RefContext);
48
49
  const internalRef = (0, _react.useRef)(null);
49
50
  const mergedRef = (0, _ref.useComposeRef)(holderRef, panelRef, internalRef);
50
- (0, _focus.useLockFocus)(visible, () => internalRef.current);
51
+ (0, _focus.useLockFocus)(visible && isFixedPos, () => internalRef.current);
51
52
  _react.default.useImperativeHandle(ref, () => ({
52
53
  focus: () => {
53
54
  internalRef.current?.focus({
@@ -62,6 +62,7 @@ const Dialog = props => {
62
62
  const wrapperRef = (0, _react.useRef)(null);
63
63
  const contentRef = (0, _react.useRef)(null);
64
64
  const [animatedVisible, setAnimatedVisible] = React.useState(visible);
65
+ const [isFixedPos, setIsFixedPos] = React.useState(false);
65
66
 
66
67
  // ========================== Init ==========================
67
68
  const ariaId = (0, _useId.default)();
@@ -116,7 +117,7 @@ const Dialog = props => {
116
117
  const contentClickRef = (0, _react.useRef)(false);
117
118
  const contentTimeoutRef = (0, _react.useRef)(null);
118
119
 
119
- // We need record content click incase content popup out of dialog
120
+ // We need record content click in case content popup out of dialog
120
121
  const onContentMouseDown = () => {
121
122
  clearTimeout(contentTimeoutRef.current);
122
123
  contentClickRef.current = true;
@@ -152,6 +153,12 @@ const Dialog = props => {
152
153
  if (visible) {
153
154
  setAnimatedVisible(true);
154
155
  saveLastOutSideActiveElementRef();
156
+
157
+ // Calc the position style
158
+ if (wrapperRef.current) {
159
+ const computedWrapStyle = getComputedStyle(wrapperRef.current);
160
+ setIsFixedPos(computedWrapStyle.position === 'fixed');
161
+ }
155
162
  } else if (animatedVisible && contentRef.current.enableMotion() && !contentRef.current.inMotion()) {
156
163
  doClose();
157
164
  }
@@ -192,6 +199,7 @@ const Dialog = props => {
192
199
  onClick: onWrapperClick,
193
200
  style: mergedStyle
194
201
  }, wrapProps), /*#__PURE__*/React.createElement(_Content.default, _extends({}, props, {
202
+ isFixedPos: isFixedPos,
195
203
  onMouseDown: onContentMouseDown,
196
204
  onMouseUp: onContentMouseUp,
197
205
  ref: contentRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/dialog",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "dialog ui component for react",
5
5
  "keywords": [
6
6
  "react",