@bifrostui/react 2.0.0-alpha.25 → 2.0.0-alpha.26

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.
@@ -75,8 +75,6 @@ const Modal = /* @__PURE__ */ React.forwardRef((props, ref) => {
75
75
  container,
76
76
  disablePortal = false,
77
77
  disableScrollLock = false,
78
- disableAutoFocus = false,
79
- disableRestoreFocus = false,
80
78
  hideBackdrop = false,
81
79
  onClose,
82
80
  keepMounted = false
@@ -88,8 +86,6 @@ const Modal = /* @__PURE__ */ React.forwardRef((props, ref) => {
88
86
  "container",
89
87
  "disablePortal",
90
88
  "disableScrollLock",
91
- "disableAutoFocus",
92
- "disableRestoreFocus",
93
89
  "hideBackdrop",
94
90
  "onClose",
95
91
  "keepMounted"
@@ -104,9 +100,7 @@ const Modal = /* @__PURE__ */ React.forwardRef((props, ref) => {
104
100
  } = (0, import_useModal.useModal)(__spreadProps(__spreadValues({}, props), {
105
101
  container,
106
102
  disableScrollLock,
107
- disableAutoFocus,
108
- disableRestoreFocus,
109
- children,
103
+ children: React.isValidElement(children) ? children : void 0,
110
104
  open,
111
105
  onClose,
112
106
  rootRef: ref
@@ -10,9 +10,7 @@ declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
10
10
  disableScrollLock?: boolean;
11
11
  disablePortal?: boolean;
12
12
  keepMounted?: boolean;
13
- disableAutoFocus?: boolean;
14
- disableRestoreFocus?: boolean;
15
13
  } & import("@bifrostui/types").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
16
14
  ref?: React.Ref<HTMLDivElement>;
17
- }, "open" | "container" | keyof import("@bifrostui/types").ICommonProps | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted" | "disableAutoFocus" | "disableRestoreFocus">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, "open" | "container" | keyof import("@bifrostui/types").ICommonProps | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
18
16
  export default Modal;
@@ -39,19 +39,6 @@ export type ModalProps<D extends React.ElementType = 'div', P = {}> = OverridePr
39
39
  * 是否保持挂载状态
40
40
  */
41
41
  keepMounted?: boolean;
42
- /**
43
- * 是否禁用自动焦点管理
44
- * 仅web端生效
45
- * @default false
46
- *
47
- */
48
- disableAutoFocus?: boolean;
49
- /**
50
- * 是否禁用在关闭时恢复焦点到触发元素
51
- * 仅web端生效
52
- * @default false
53
- */
54
- disableRestoreFocus?: boolean;
55
42
  };
56
43
  defaultComponent: D;
57
44
  }, D>;
@@ -2,8 +2,6 @@ import React from 'react';
2
2
  export interface UseModalParameters {
3
3
  container?: Element | (() => Element | null) | null;
4
4
  disableScrollLock?: boolean;
5
- disableAutoFocus?: boolean;
6
- disableRestoreFocus?: boolean;
7
5
  onClose?: (event: React.SyntheticEvent<Element, Event>, detail?: {
8
6
  from: 'backdropClick' | 'escapeKeyDown';
9
7
  }) => void;
@@ -53,8 +53,6 @@ function useModal(parameters) {
53
53
  const {
54
54
  container,
55
55
  disableScrollLock = false,
56
- disableAutoFocus = false,
57
- disableRestoreFocus = false,
58
56
  onClose,
59
57
  open,
60
58
  rootRef,
@@ -69,7 +67,6 @@ function useModal(parameters) {
69
67
  const handleRef = (0, import_utils.useForkRef)(modalRef, rootRef);
70
68
  const [exited, setExited] = (0, import_react.useState)(!open);
71
69
  const hasTransition = getHasTransition(children);
72
- const lastFocusedElement = (0, import_react.useRef)(null);
73
70
  let ariaHiddenProp = true;
74
71
  if (parameters["aria-hidden"] === "false" || parameters["aria-hidden"] === false) {
75
72
  ariaHiddenProp = false;
@@ -123,38 +120,6 @@ function useModal(parameters) {
123
120
  handleClose();
124
121
  }
125
122
  }, [open, handleClose, hasTransition, handleOpen]);
126
- (0, import_react.useEffect)(() => {
127
- if (open && modalRef.current) {
128
- const doc = modalRef.current.ownerDocument || document;
129
- if (!lastFocusedElement.current) {
130
- lastFocusedElement.current = doc.activeElement;
131
- }
132
- if (!disableAutoFocus) {
133
- if (!modalRef.current.contains(doc.activeElement)) {
134
- if (!modalRef.current.hasAttribute("tabIndex")) {
135
- modalRef.current.setAttribute("tabIndex", "-1");
136
- }
137
- const autoFocusElement = modalRef.current.querySelector(
138
- '[autofocus], [tabindex="-1"]'
139
- );
140
- if (autoFocusElement) {
141
- autoFocusElement.focus();
142
- } else {
143
- modalRef.current.focus();
144
- }
145
- }
146
- }
147
- return () => {
148
- if (!disableRestoreFocus && lastFocusedElement.current) {
149
- if (lastFocusedElement.current && typeof lastFocusedElement.current.focus === "function") {
150
- lastFocusedElement.current.focus();
151
- }
152
- lastFocusedElement.current = null;
153
- }
154
- };
155
- }
156
- return void 0;
157
- }, [open, disableAutoFocus, disableRestoreFocus]);
158
123
  const createHandleBackdropClick = (backdropHandlers = {}) => (event) => {
159
124
  var _a;
160
125
  (_a = backdropHandlers.onClick) == null ? void 0 : _a.call(backdropHandlers, event);
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { DatePickerProps } from './DatePicker.types';
3
- declare const DatePicker: React.ForwardRefExoticComponent<Omit<DatePickerProps<"div", Omit<import("../Picker").PickerProps<"div", import("..").DrawerProps>, "defaultValue" | "onChange" | "value" | "onClose" | "onConfirm">>, "ref"> & React.RefAttributes<HTMLDivElement>>;
3
+ declare const DatePicker: React.ForwardRefExoticComponent<Omit<DatePickerProps<"div", Omit<import("../Picker").PickerProps<"div", import("..").DrawerProps>, "value" | "defaultValue" | "onChange" | "onClose" | "onConfirm">>, "ref"> & React.RefAttributes<HTMLDivElement>>;
4
4
  export default DatePicker;
package/es/Modal/Modal.js CHANGED
@@ -45,8 +45,6 @@ const Modal = /* @__PURE__ */ React.forwardRef((props, ref) => {
45
45
  container,
46
46
  disablePortal = false,
47
47
  disableScrollLock = false,
48
- disableAutoFocus = false,
49
- disableRestoreFocus = false,
50
48
  hideBackdrop = false,
51
49
  onClose,
52
50
  keepMounted = false
@@ -58,8 +56,6 @@ const Modal = /* @__PURE__ */ React.forwardRef((props, ref) => {
58
56
  "container",
59
57
  "disablePortal",
60
58
  "disableScrollLock",
61
- "disableAutoFocus",
62
- "disableRestoreFocus",
63
59
  "hideBackdrop",
64
60
  "onClose",
65
61
  "keepMounted"
@@ -74,9 +70,7 @@ const Modal = /* @__PURE__ */ React.forwardRef((props, ref) => {
74
70
  } = useModal(__spreadProps(__spreadValues({}, props), {
75
71
  container,
76
72
  disableScrollLock,
77
- disableAutoFocus,
78
- disableRestoreFocus,
79
- children,
73
+ children: React.isValidElement(children) ? children : void 0,
80
74
  open,
81
75
  onClose,
82
76
  rootRef: ref
@@ -10,9 +10,7 @@ declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
10
10
  disableScrollLock?: boolean;
11
11
  disablePortal?: boolean;
12
12
  keepMounted?: boolean;
13
- disableAutoFocus?: boolean;
14
- disableRestoreFocus?: boolean;
15
13
  } & import("@bifrostui/types").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
16
14
  ref?: React.Ref<HTMLDivElement>;
17
- }, keyof import("@bifrostui/types").ICommonProps | "open" | "container" | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted" | "disableAutoFocus" | "disableRestoreFocus">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, "open" | "container" | keyof import("@bifrostui/types").ICommonProps | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
18
16
  export default Modal;
@@ -39,19 +39,6 @@ export type ModalProps<D extends React.ElementType = 'div', P = {}> = OverridePr
39
39
  * 是否保持挂载状态
40
40
  */
41
41
  keepMounted?: boolean;
42
- /**
43
- * 是否禁用自动焦点管理
44
- * 仅web端生效
45
- * @default false
46
- *
47
- */
48
- disableAutoFocus?: boolean;
49
- /**
50
- * 是否禁用在关闭时恢复焦点到触发元素
51
- * 仅web端生效
52
- * @default false
53
- */
54
- disableRestoreFocus?: boolean;
55
42
  };
56
43
  defaultComponent: D;
57
44
  }, D>;
@@ -2,8 +2,6 @@ import React from 'react';
2
2
  export interface UseModalParameters {
3
3
  container?: Element | (() => Element | null) | null;
4
4
  disableScrollLock?: boolean;
5
- disableAutoFocus?: boolean;
6
- disableRestoreFocus?: boolean;
7
5
  onClose?: (event: React.SyntheticEvent<Element, Event>, detail?: {
8
6
  from: 'backdropClick' | 'escapeKeyDown';
9
7
  }) => void;
@@ -33,8 +33,6 @@ function useModal(parameters) {
33
33
  const {
34
34
  container,
35
35
  disableScrollLock = false,
36
- disableAutoFocus = false,
37
- disableRestoreFocus = false,
38
36
  onClose,
39
37
  open,
40
38
  rootRef,
@@ -49,7 +47,6 @@ function useModal(parameters) {
49
47
  const handleRef = useForkRef(modalRef, rootRef);
50
48
  const [exited, setExited] = useState(!open);
51
49
  const hasTransition = getHasTransition(children);
52
- const lastFocusedElement = useRef(null);
53
50
  let ariaHiddenProp = true;
54
51
  if (parameters["aria-hidden"] === "false" || parameters["aria-hidden"] === false) {
55
52
  ariaHiddenProp = false;
@@ -103,38 +100,6 @@ function useModal(parameters) {
103
100
  handleClose();
104
101
  }
105
102
  }, [open, handleClose, hasTransition, handleOpen]);
106
- useEffect(() => {
107
- if (open && modalRef.current) {
108
- const doc = modalRef.current.ownerDocument || document;
109
- if (!lastFocusedElement.current) {
110
- lastFocusedElement.current = doc.activeElement;
111
- }
112
- if (!disableAutoFocus) {
113
- if (!modalRef.current.contains(doc.activeElement)) {
114
- if (!modalRef.current.hasAttribute("tabIndex")) {
115
- modalRef.current.setAttribute("tabIndex", "-1");
116
- }
117
- const autoFocusElement = modalRef.current.querySelector(
118
- '[autofocus], [tabindex="-1"]'
119
- );
120
- if (autoFocusElement) {
121
- autoFocusElement.focus();
122
- } else {
123
- modalRef.current.focus();
124
- }
125
- }
126
- }
127
- return () => {
128
- if (!disableRestoreFocus && lastFocusedElement.current) {
129
- if (lastFocusedElement.current && typeof lastFocusedElement.current.focus === "function") {
130
- lastFocusedElement.current.focus();
131
- }
132
- lastFocusedElement.current = null;
133
- }
134
- };
135
- }
136
- return void 0;
137
- }, [open, disableAutoFocus, disableRestoreFocus]);
138
103
  const createHandleBackdropClick = (backdropHandlers = {}) => (event) => {
139
104
  var _a;
140
105
  (_a = backdropHandlers.onClick) == null ? void 0 : _a.call(backdropHandlers, event);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/react",
3
- "version": "2.0.0-alpha.25",
3
+ "version": "2.0.0-alpha.26",
4
4
  "description": "React components for building mobile application",
5
5
  "homepage": "http://bui.taopiaopiao.com",
6
6
  "license": "MIT",
@@ -43,10 +43,10 @@
43
43
  "clsx": "^2.1.1",
44
44
  "dayjs": "^1.11.7",
45
45
  "swiper": "^8.1.5",
46
- "@bifrostui/icons": "2.0.0-alpha.25",
47
- "@bifrostui/types": "2.0.0-alpha.25",
48
- "@bifrostui/styles": "2.0.0-alpha.25",
49
- "@bifrostui/utils": "2.0.0-alpha.25"
46
+ "@bifrostui/icons": "2.0.0-alpha.26",
47
+ "@bifrostui/styles": "2.0.0-alpha.26",
48
+ "@bifrostui/types": "2.0.0-alpha.26",
49
+ "@bifrostui/utils": "2.0.0-alpha.26"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@tarojs/components": "^3.0.0",