rsuite 5.73.0 → 5.73.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.
- package/CHANGELOG.md +16 -0
- package/CheckTree/styles/index.css +0 -1
- package/CheckTree/styles/index.less +0 -1
- package/CheckTreePicker/styles/index.css +0 -1
- package/Checkbox/styles/mixin.less +1 -1
- package/RadioTile/styles/index.css +69 -0
- package/RadioTile/styles/index.less +3 -1
- package/Rate/styles/index.less +1 -1
- package/Slider/styles/index.less +1 -1
- package/TagInput/styles/index.css +0 -3
- package/TagPicker/styles/index.css +0 -3
- package/TagPicker/styles/index.less +0 -2
- package/Tree/styles/index.css +0 -3
- package/Tree/styles/index.less +0 -6
- package/TreePicker/styles/index.css +0 -3
- package/cjs/Calendar/hooks/useCalendarState.d.ts +1 -1
- package/cjs/Calendar/hooks/useCalendarState.js +15 -8
- package/cjs/Drawer/Drawer.js +6 -15
- package/cjs/FormControl/hooks/useField.js +3 -0
- package/cjs/Modal/Modal.d.ts +4 -0
- package/cjs/Modal/Modal.js +12 -13
- package/cjs/Modal/ModalBody.js +6 -5
- package/cjs/Modal/ModalContext.d.ts +4 -0
- package/cjs/Modal/ModalHeader.js +4 -4
- package/cjs/internals/hooks/useFocusVirtualListItem.d.ts +5 -2
- package/cjs/internals/hooks/useFocusVirtualListItem.js +23 -7
- package/dist/rsuite-no-reset-rtl.css +0 -7
- package/dist/rsuite-no-reset-rtl.min.css +1 -1
- package/dist/rsuite-no-reset-rtl.min.css.map +1 -1
- package/dist/rsuite-no-reset.css +0 -7
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite-no-reset.min.css.map +1 -1
- package/dist/rsuite-rtl.css +0 -7
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +0 -7
- package/dist/rsuite.js +7 -18
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Calendar/hooks/useCalendarState.d.ts +1 -1
- package/esm/Calendar/hooks/useCalendarState.js +16 -9
- package/esm/Drawer/Drawer.js +6 -13
- package/esm/FormControl/hooks/useField.js +4 -1
- package/esm/Modal/Modal.d.ts +4 -0
- package/esm/Modal/Modal.js +13 -14
- package/esm/Modal/ModalBody.js +6 -5
- package/esm/Modal/ModalContext.d.ts +4 -0
- package/esm/Modal/ModalHeader.js +4 -4
- package/esm/internals/hooks/useFocusVirtualListItem.d.ts +5 -2
- package/esm/internals/hooks/useFocusVirtualListItem.js +23 -7
- package/package.json +1 -1
- package/cjs/Drawer/DrawerContext.d.ts +0 -9
- package/cjs/Drawer/DrawerContext.js +0 -9
- package/esm/Drawer/DrawerContext.d.ts +0 -9
- package/esm/Drawer/DrawerContext.js +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
3
|
import { addMonths } from "../../internals/utils/date/index.js";
|
|
4
4
|
import { useEventCallback } from "../../internals/hooks/index.js";
|
|
5
5
|
export var CalendarState = /*#__PURE__*/function (CalendarState) {
|
|
@@ -11,9 +11,16 @@ export var useCalendarState = function useCalendarState(props) {
|
|
|
11
11
|
var _useState = useState(props.defaultState),
|
|
12
12
|
calendarState = _useState[0],
|
|
13
13
|
setCalendarState = _useState[1];
|
|
14
|
-
var reset =
|
|
14
|
+
var reset = useEventCallback(function () {
|
|
15
15
|
setCalendarState(undefined);
|
|
16
|
-
|
|
16
|
+
if (calendarState === CalendarState.TIME) {
|
|
17
|
+
var _props$onToggleTimeDr;
|
|
18
|
+
(_props$onToggleTimeDr = props.onToggleTimeDropdown) === null || _props$onToggleTimeDr === void 0 ? void 0 : _props$onToggleTimeDr.call(props, false);
|
|
19
|
+
} else if (calendarState === CalendarState.MONTH) {
|
|
20
|
+
var _props$onToggleMonthD;
|
|
21
|
+
(_props$onToggleMonthD = props.onToggleMonthDropdown) === null || _props$onToggleMonthD === void 0 ? void 0 : _props$onToggleMonthD.call(props, false);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
17
24
|
var onMoveForward = useEventCallback(function () {
|
|
18
25
|
var _props$onMoveForward;
|
|
19
26
|
(_props$onMoveForward = props.onMoveForward) === null || _props$onMoveForward === void 0 ? void 0 : _props$onMoveForward.call(props, addMonths(props.calendarDate, 1));
|
|
@@ -23,22 +30,22 @@ export var useCalendarState = function useCalendarState(props) {
|
|
|
23
30
|
(_props$onMoveBackward = props.onMoveBackward) === null || _props$onMoveBackward === void 0 ? void 0 : _props$onMoveBackward.call(props, addMonths(props.calendarDate, -1));
|
|
24
31
|
});
|
|
25
32
|
var onToggleTimeDropdown = useEventCallback(function () {
|
|
26
|
-
var _props$
|
|
33
|
+
var _props$onToggleTimeDr2;
|
|
27
34
|
if (calendarState === CalendarState.TIME) {
|
|
28
|
-
|
|
35
|
+
setCalendarState(undefined);
|
|
29
36
|
} else {
|
|
30
37
|
setCalendarState(CalendarState.TIME);
|
|
31
38
|
}
|
|
32
|
-
(_props$
|
|
39
|
+
(_props$onToggleTimeDr2 = props.onToggleTimeDropdown) === null || _props$onToggleTimeDr2 === void 0 ? void 0 : _props$onToggleTimeDr2.call(props, calendarState !== CalendarState.TIME);
|
|
33
40
|
});
|
|
34
41
|
var onToggleMonthDropdown = useEventCallback(function () {
|
|
35
|
-
var _props$
|
|
42
|
+
var _props$onToggleMonthD2;
|
|
36
43
|
if (calendarState === CalendarState.MONTH) {
|
|
37
|
-
|
|
44
|
+
setCalendarState(undefined);
|
|
38
45
|
} else {
|
|
39
46
|
setCalendarState(CalendarState.MONTH);
|
|
40
47
|
}
|
|
41
|
-
(_props$
|
|
48
|
+
(_props$onToggleMonthD2 = props.onToggleMonthDropdown) === null || _props$onToggleMonthD2 === void 0 ? void 0 : _props$onToggleMonthD2.call(props, calendarState !== CalendarState.MONTH);
|
|
42
49
|
});
|
|
43
50
|
var handlers = useMemo(function () {
|
|
44
51
|
return {
|
package/esm/Drawer/Drawer.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
4
|
var _excluded = ["className", "placement", "classPrefix", "animation", "closeButton"];
|
|
5
|
-
import React
|
|
5
|
+
import React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import Slide from "../Animation/Slide.js";
|
|
8
8
|
import Modal from "../Modal/index.js";
|
|
9
9
|
import { useClassNames } from "../internals/hooks/index.js";
|
|
10
10
|
import { deprecateComponent } from "../internals/utils/index.js";
|
|
11
|
-
import DrawerContext from "./DrawerContext.js";
|
|
12
11
|
import { oneOf } from "../internals/propTypes/index.js";
|
|
13
12
|
import DrawerBody from "./DrawerBody.js";
|
|
14
13
|
import DrawerHeader from "./DrawerHeader.js";
|
|
@@ -37,22 +36,16 @@ var Drawer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
37
36
|
var animationProps = {
|
|
38
37
|
placement: placement
|
|
39
38
|
};
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
closeButton: closeButton,
|
|
43
|
-
isDrawer: true
|
|
44
|
-
};
|
|
45
|
-
}, [closeButton]);
|
|
46
|
-
return /*#__PURE__*/React.createElement(DrawerContext.Provider, {
|
|
47
|
-
value: contextValue
|
|
48
|
-
}, /*#__PURE__*/React.createElement(Modal, _extends({}, rest, {
|
|
39
|
+
return /*#__PURE__*/React.createElement(Modal, _extends({}, rest, {
|
|
49
40
|
ref: ref,
|
|
50
41
|
overflow: false,
|
|
51
42
|
classPrefix: classPrefix,
|
|
52
43
|
className: classes,
|
|
53
44
|
animation: animation,
|
|
54
|
-
animationProps: animationProps
|
|
55
|
-
|
|
45
|
+
animationProps: animationProps,
|
|
46
|
+
isDrawer: true,
|
|
47
|
+
closeButton: closeButton
|
|
48
|
+
}));
|
|
56
49
|
});
|
|
57
50
|
DrawerBody.displayName = 'DrawerBody';
|
|
58
51
|
DrawerHeader.displayName = 'DrawerHeader';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { isValidElement, useCallback, useMemo } from 'react';
|
|
4
4
|
import get from 'lodash/get';
|
|
5
5
|
import set from 'lodash/set';
|
|
6
6
|
import { nameToPath } from "../utils.js";
|
|
@@ -17,6 +17,9 @@ function getErrorMessage(error) {
|
|
|
17
17
|
if (error !== null && error !== void 0 && error.array && ((_error$array = error.array) === null || _error$array === void 0 ? void 0 : _error$array.length) > 0) {
|
|
18
18
|
return error.array[0].errorMessage;
|
|
19
19
|
}
|
|
20
|
+
if ( /*#__PURE__*/isValidElement(error)) {
|
|
21
|
+
return error;
|
|
22
|
+
}
|
|
20
23
|
return error === null || error === void 0 ? void 0 : error.errorMessage;
|
|
21
24
|
}
|
|
22
25
|
function useField(props) {
|
package/esm/Modal/Modal.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export interface ModalProps extends BaseModalProps, Pick<React.HTMLAttributes<HT
|
|
|
27
27
|
dialogAs?: React.ElementType;
|
|
28
28
|
/** Automatically sets the height when the body content is too long. */
|
|
29
29
|
overflow?: boolean;
|
|
30
|
+
/** Indicates if the component should be displayed as a drawer */
|
|
31
|
+
isDrawer?: boolean;
|
|
32
|
+
/** Custom close button, used when rendered as a Drawer */
|
|
33
|
+
closeButton?: React.ReactNode | boolean;
|
|
30
34
|
}
|
|
31
35
|
interface ModalComponent extends RsRefForwardingComponent<'div', ModalProps> {
|
|
32
36
|
Body: typeof ModalBody;
|
package/esm/Modal/Modal.js
CHANGED
|
@@ -3,9 +3,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
3
3
|
import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
|
|
4
4
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
5
|
var _templateObject, _templateObject2, _templateObject3;
|
|
6
|
-
var _excluded = ["animation", "animationProps", "animationTimeout", "aria-labelledby", "aria-describedby", "backdropClassName", "backdrop", "className", "children", "classPrefix", "dialogClassName", "dialogStyle", "dialogAs", "enforceFocus", "full", "overflow", "open", "onClose", "onEntered", "onEntering", "onExited", "role", "size", "id"],
|
|
6
|
+
var _excluded = ["animation", "animationProps", "animationTimeout", "aria-labelledby", "aria-describedby", "backdropClassName", "backdrop", "className", "children", "classPrefix", "dialogClassName", "dialogStyle", "dialogAs", "enforceFocus", "full", "overflow", "open", "onClose", "onEntered", "onEntering", "onExited", "role", "size", "id", "isDrawer", "closeButton"],
|
|
7
7
|
_excluded2 = ["className"];
|
|
8
|
-
import React, { useRef, useMemo, useState, useCallback
|
|
8
|
+
import React, { useRef, useMemo, useState, useCallback } from 'react';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import pick from 'lodash/pick';
|
|
11
11
|
import on from 'dom-lib/on';
|
|
@@ -22,7 +22,6 @@ import ModalTitle from "./ModalTitle.js";
|
|
|
22
22
|
import ModalFooter from "./ModalFooter.js";
|
|
23
23
|
import { useBodyStyles } from "./utils.js";
|
|
24
24
|
import { deprecatePropType, oneOf } from "../internals/propTypes/index.js";
|
|
25
|
-
import DrawerContext from "../Drawer/DrawerContext.js";
|
|
26
25
|
var modalSizes = ['xs', 'sm', 'md', 'lg', 'full'];
|
|
27
26
|
/**
|
|
28
27
|
* The `Modal` component is used to show content in a layer above the app.
|
|
@@ -62,6 +61,9 @@ var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
62
61
|
_props$size = props.size,
|
|
63
62
|
size = _props$size === void 0 ? 'sm' : _props$size,
|
|
64
63
|
idProp = props.id,
|
|
64
|
+
_props$isDrawer = props.isDrawer,
|
|
65
|
+
isDrawer = _props$isDrawer === void 0 ? false : _props$isDrawer,
|
|
66
|
+
closeButton = props.closeButton,
|
|
65
67
|
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
66
68
|
var inClass = {
|
|
67
69
|
in: open && !animation
|
|
@@ -78,11 +80,6 @@ var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
78
80
|
var dialogRef = useRef(null);
|
|
79
81
|
var transitionEndListener = useRef();
|
|
80
82
|
|
|
81
|
-
// Render Modal as Drawer
|
|
82
|
-
var _ref = useContext(DrawerContext) || {},
|
|
83
|
-
_ref$isDrawer = _ref.isDrawer,
|
|
84
|
-
isDrawer = _ref$isDrawer === void 0 ? false : _ref$isDrawer;
|
|
85
|
-
|
|
86
83
|
// The style of the Modal body will be updated with the size of the window or container.
|
|
87
84
|
var _useBodyStyles = useBodyStyles(dialogRef, {
|
|
88
85
|
overflow: overflow,
|
|
@@ -99,9 +96,11 @@ var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
99
96
|
onModalClose: onClose,
|
|
100
97
|
getBodyStyles: function getBodyStyles() {
|
|
101
98
|
return bodyStyles;
|
|
102
|
-
}
|
|
99
|
+
},
|
|
100
|
+
closeButton: closeButton,
|
|
101
|
+
isDrawer: isDrawer
|
|
103
102
|
};
|
|
104
|
-
}, [dialogId, onClose, bodyStyles]);
|
|
103
|
+
}, [dialogId, onClose, closeButton, isDrawer, bodyStyles]);
|
|
105
104
|
var handleExited = useCallback(function (node) {
|
|
106
105
|
var _transitionEndListene;
|
|
107
106
|
onExited === null || onExited === void 0 ? void 0 : onExited(node);
|
|
@@ -157,8 +156,8 @@ var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
157
156
|
});
|
|
158
157
|
var sizeKey = 'width';
|
|
159
158
|
if (isDrawer) {
|
|
160
|
-
var
|
|
161
|
-
placement =
|
|
159
|
+
var _ref = animationProps || {},
|
|
160
|
+
placement = _ref.placement;
|
|
162
161
|
// The width or height of the drawer depends on the placement.
|
|
163
162
|
sizeKey = placement === 'top' || placement === 'bottom' ? 'height' : 'width';
|
|
164
163
|
}
|
|
@@ -199,7 +198,7 @@ var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
199
198
|
onClick: backdrop ? handleBackdropClick : undefined,
|
|
200
199
|
onMouseDown: handleMouseDown
|
|
201
200
|
}), function (transitionProps, transitionRef) {
|
|
202
|
-
var
|
|
201
|
+
var _ref2;
|
|
203
202
|
var transitionClassName = transitionProps.className,
|
|
204
203
|
transitionRest = _objectWithoutPropertiesLoose(transitionProps, _excluded2);
|
|
205
204
|
return /*#__PURE__*/React.createElement(Dialog, _extends({
|
|
@@ -207,7 +206,7 @@ var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
207
206
|
id: dialogId,
|
|
208
207
|
"aria-labelledby": ariaLabelledby !== null && ariaLabelledby !== void 0 ? ariaLabelledby : dialogId + "-title",
|
|
209
208
|
"aria-describedby": ariaDescribedby,
|
|
210
|
-
style: (
|
|
209
|
+
style: (_ref2 = {}, _ref2[sizeKey] = modalSizes.includes(size) ? undefined : size, _ref2)
|
|
211
210
|
}, transitionRest, pick(rest, Object.keys(modalDialogPropTypes)), {
|
|
212
211
|
ref: mergeRefs(dialogRef, transitionRef),
|
|
213
212
|
classPrefix: classPrefix,
|
package/esm/Modal/ModalBody.js
CHANGED
|
@@ -8,9 +8,7 @@ import { useClassNames } from "../internals/hooks/index.js";
|
|
|
8
8
|
import { ModalContext } from "./ModalContext.js";
|
|
9
9
|
import IconButton from "../IconButton/index.js";
|
|
10
10
|
import Close from '@rsuite/icons/Close';
|
|
11
|
-
import DrawerContext from "../Drawer/DrawerContext.js";
|
|
12
11
|
var ModalBody = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
13
|
-
var _context$getBodyStyle, _useContext;
|
|
14
12
|
var _props$as = props.as,
|
|
15
13
|
Component = _props$as === void 0 ? 'div' : _props$as,
|
|
16
14
|
_props$classPrefix = props.classPrefix,
|
|
@@ -25,8 +23,11 @@ var ModalBody = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
25
23
|
prefix = _useClassNames.prefix;
|
|
26
24
|
var classes = merge(className, withClassPrefix());
|
|
27
25
|
var context = useContext(ModalContext);
|
|
28
|
-
var
|
|
29
|
-
|
|
26
|
+
var _ref = context || {},
|
|
27
|
+
getBodyStyles = _ref.getBodyStyles,
|
|
28
|
+
closeButton = _ref.closeButton,
|
|
29
|
+
onModalClose = _ref.onModalClose;
|
|
30
|
+
var bodyStyles = getBodyStyles === null || getBodyStyles === void 0 ? void 0 : getBodyStyles();
|
|
30
31
|
var buttonElement = null;
|
|
31
32
|
if (closeButton) {
|
|
32
33
|
buttonElement = typeof closeButton === 'boolean' ? /*#__PURE__*/React.createElement(IconButton, {
|
|
@@ -34,7 +35,7 @@ var ModalBody = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
34
35
|
appearance: "subtle",
|
|
35
36
|
size: "sm",
|
|
36
37
|
className: prefix('close'),
|
|
37
|
-
onClick:
|
|
38
|
+
onClick: onModalClose
|
|
38
39
|
}) : closeButton;
|
|
39
40
|
}
|
|
40
41
|
return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
@@ -6,5 +6,9 @@ export interface ModalContextProps {
|
|
|
6
6
|
onModalClose?: (event: React.MouseEvent<Element, MouseEvent>) => void;
|
|
7
7
|
/** Pass the latest style to body. */
|
|
8
8
|
getBodyStyles?: () => React.CSSProperties | null;
|
|
9
|
+
/** Indicates if the component should be displayed as a drawer */
|
|
10
|
+
isDrawer?: boolean;
|
|
11
|
+
/** Custom close button used when rendered as a Drawer */
|
|
12
|
+
closeButton?: React.ReactNode | boolean;
|
|
9
13
|
}
|
|
10
14
|
export declare const ModalContext: React.Context<ModalContextProps | null>;
|
package/esm/Modal/ModalHeader.js
CHANGED
|
@@ -10,9 +10,7 @@ import { ModalContext } from "./ModalContext.js";
|
|
|
10
10
|
import CloseButton from "../internals/CloseButton/index.js";
|
|
11
11
|
import Close from '@rsuite/icons/Close';
|
|
12
12
|
import IconButton from "../IconButton/index.js";
|
|
13
|
-
import DrawerContext from "../Drawer/DrawerContext.js";
|
|
14
13
|
var ModalHeader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
15
|
-
var _useContext, _useContext2;
|
|
16
14
|
var _props$as = props.as,
|
|
17
15
|
Component = _props$as === void 0 ? 'div' : _props$as,
|
|
18
16
|
_props$classPrefix = props.classPrefix,
|
|
@@ -28,8 +26,10 @@ var ModalHeader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
28
26
|
withClassPrefix = _useClassNames.withClassPrefix,
|
|
29
27
|
prefix = _useClassNames.prefix;
|
|
30
28
|
var classes = merge(className, withClassPrefix());
|
|
31
|
-
var
|
|
32
|
-
var
|
|
29
|
+
var context = useContext(ModalContext);
|
|
30
|
+
var _ref = context || {},
|
|
31
|
+
isDrawer = _ref.isDrawer,
|
|
32
|
+
onModalClose = _ref.onModalClose;
|
|
33
33
|
var buttonElement = isDrawer ? /*#__PURE__*/React.createElement(IconButton, {
|
|
34
34
|
icon: /*#__PURE__*/React.createElement(Close, null),
|
|
35
35
|
appearance: "subtle",
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Ensures that a virtualized list item retains focus after scrolling or clicking on options,
|
|
4
|
+
* preventing unnecessary re-renders and loss of focus. If the current focus is on an interactive
|
|
5
|
+
* element (such as input, textarea, select, button, or contenteditable), the focus is not shifted.
|
|
6
|
+
* @param focused - Boolean indicating if the item should be focused.
|
|
7
|
+
* @returns A ref to be attached to the list item element.
|
|
5
8
|
*/
|
|
6
9
|
export declare function useFocusVirtualListItem<T extends HTMLElement>(focused?: boolean): import("react").RefObject<T>;
|
|
7
10
|
export default useFocusVirtualListItem;
|
|
@@ -2,19 +2,35 @@
|
|
|
2
2
|
import { useRef, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Ensures that a virtualized list item retains focus after scrolling or clicking on options,
|
|
6
|
+
* preventing unnecessary re-renders and loss of focus. If the current focus is on an interactive
|
|
7
|
+
* element (such as input, textarea, select, button, or contenteditable), the focus is not shifted.
|
|
8
|
+
* @param focused - Boolean indicating if the item should be focused.
|
|
9
|
+
* @returns A ref to be attached to the list item element.
|
|
7
10
|
*/
|
|
8
11
|
export function useFocusVirtualListItem(focused) {
|
|
9
12
|
var itemRef = useRef(null);
|
|
10
13
|
useEffect(function () {
|
|
11
|
-
if (!focused) {
|
|
14
|
+
if (!focused || !itemRef.current) {
|
|
12
15
|
return;
|
|
13
16
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
var activeElement = document.activeElement;
|
|
18
|
+
|
|
19
|
+
// Helper function to determine if the element should retain focus
|
|
20
|
+
var isInteractiveElement = function isInteractiveElement(element) {
|
|
21
|
+
var tagName = element.tagName;
|
|
22
|
+
return tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT' || tagName === 'BUTTON' || element.isContentEditable || element.tabIndex >= 0 // Elements with tabindex are considered focusable
|
|
23
|
+
;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// If the active element is an interactive one, don't shift focus.
|
|
27
|
+
if (activeElement && isInteractiveElement(activeElement)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If the currently focused element is not the target item, focus it.
|
|
32
|
+
if (activeElement !== itemRef.current) {
|
|
33
|
+
itemRef.current.focus();
|
|
18
34
|
}
|
|
19
35
|
}, [focused]);
|
|
20
36
|
return itemRef;
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export interface DrawerContextProps {
|
|
3
|
-
/** Custom close button */
|
|
4
|
-
closeButton?: React.ReactNode | boolean;
|
|
5
|
-
/** Render Modal as Drawer */
|
|
6
|
-
isDrawer: boolean;
|
|
7
|
-
}
|
|
8
|
-
declare const DrawerContext: React.Context<DrawerContextProps | null>;
|
|
9
|
-
export default DrawerContext;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var DrawerContext = /*#__PURE__*/_react.default.createContext(null);
|
|
9
|
-
var _default = exports.default = DrawerContext;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export interface DrawerContextProps {
|
|
3
|
-
/** Custom close button */
|
|
4
|
-
closeButton?: React.ReactNode | boolean;
|
|
5
|
-
/** Render Modal as Drawer */
|
|
6
|
-
isDrawer: boolean;
|
|
7
|
-
}
|
|
8
|
-
declare const DrawerContext: React.Context<DrawerContextProps | null>;
|
|
9
|
-
export default DrawerContext;
|