@coreui/react 5.9.0 → 5.9.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/README.md +1 -1
- package/dist/cjs/components/focus-trap/CFocusTrap.js +23 -6
- package/dist/cjs/components/focus-trap/CFocusTrap.js.map +1 -1
- package/dist/cjs/components/focus-trap/utils.d.ts +10 -0
- package/dist/cjs/components/focus-trap/utils.js +25 -0
- package/dist/cjs/components/focus-trap/utils.js.map +1 -1
- package/dist/cjs/components/modal/CModal.js +10 -11
- package/dist/cjs/components/modal/CModal.js.map +1 -1
- package/dist/esm/components/focus-trap/CFocusTrap.js +24 -7
- package/dist/esm/components/focus-trap/CFocusTrap.js.map +1 -1
- package/dist/esm/components/focus-trap/utils.d.ts +10 -0
- package/dist/esm/components/focus-trap/utils.js +25 -1
- package/dist/esm/components/focus-trap/utils.js.map +1 -1
- package/dist/esm/components/modal/CModal.js +10 -11
- package/dist/esm/components/modal/CModal.js.map +1 -1
- package/package.json +9 -9
- package/src/components/focus-trap/CFocusTrap.tsx +33 -8
- package/src/components/focus-trap/utils.ts +24 -0
- package/src/components/modal/CModal.tsx +30 -31
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
Several quick start options are available:
|
|
48
48
|
|
|
49
|
-
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.9.
|
|
49
|
+
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.9.1.zip)
|
|
50
50
|
- Clone the repo: `git clone https://github.com/coreui/coreui-react.git`
|
|
51
51
|
- Install with [npm](https://www.npmjs.com/): `npm install @coreui/react`
|
|
52
52
|
- Install with [yarn](https://yarnpkg.com/): `yarn add @coreui/react`
|
|
@@ -64,8 +64,9 @@ const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstEl
|
|
|
64
64
|
const elements = utils.focusableChildren(container);
|
|
65
65
|
if (elements.length === 0) {
|
|
66
66
|
container.focus({ preventScroll: true });
|
|
67
|
+
return;
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
if (lastTabNavDirectionRef.current === 'backward') {
|
|
69
70
|
(_a = elements.at(-1)) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
70
71
|
}
|
|
71
72
|
else {
|
|
@@ -79,17 +80,30 @@ const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstEl
|
|
|
79
80
|
}
|
|
80
81
|
tabEventSourceRef.current = container;
|
|
81
82
|
lastTabNavDirectionRef.current = event.shiftKey ? 'backward' : 'forward';
|
|
82
|
-
if (!_additionalContainer) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
83
|
const containerElements = utils.focusableChildren(container);
|
|
86
|
-
const additionalElements = utils.focusableChildren(_additionalContainer);
|
|
84
|
+
const additionalElements = _additionalContainer ? utils.focusableChildren(_additionalContainer) : [];
|
|
87
85
|
if (containerElements.length === 0 && additionalElements.length === 0) {
|
|
88
86
|
// No focusable elements, prevent tab
|
|
89
87
|
event.preventDefault();
|
|
90
88
|
return;
|
|
91
89
|
}
|
|
90
|
+
const focusableElements = [...containerElements, ...additionalElements];
|
|
91
|
+
const firstFocusableElement = focusableElements[0];
|
|
92
|
+
const lastFocusableElement = focusableElements.at(-1);
|
|
92
93
|
const activeElement = document.activeElement;
|
|
94
|
+
if (event.shiftKey && activeElement === firstFocusableElement) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
lastFocusableElement.focus();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!event.shiftKey && activeElement === lastFocusableElement) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
firstFocusableElement.focus();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!_additionalContainer) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
93
107
|
const isInContainer = containerElements.includes(activeElement);
|
|
94
108
|
const isInAdditional = additionalElements.includes(activeElement);
|
|
95
109
|
// Handle tab navigation between container and additional elements
|
|
@@ -151,7 +165,10 @@ const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstEl
|
|
|
151
165
|
}, [active, additionalContainer, focusFirstElement, onActivate, onDeactivate, restoreFocus]);
|
|
152
166
|
// Attach our ref to the ONLY child — no extra wrappers
|
|
153
167
|
const onlyChild = React.Children.only(children);
|
|
154
|
-
|
|
168
|
+
// Handle different ref access patterns between React versions
|
|
169
|
+
// React 19+: ref is accessed via element.props.ref
|
|
170
|
+
// React 18 and earlier: ref is accessed via element.ref
|
|
171
|
+
const childRef = utils.getChildRef(onlyChild);
|
|
155
172
|
const mergedRef = utils.mergeRefs(childRef, (node) => {
|
|
156
173
|
containerRef.current = node;
|
|
157
174
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CFocusTrap.js","sources":["../../../../src/components/focus-trap/CFocusTrap.tsx"],"sourcesContent":[null],"names":["useRef","useEffect","focusableChildren","mergeRefs","cloneElement"],"mappings":";;;;;AAmEO,MAAM,UAAU,GAAwB,CAAC,EAC9C,MAAM,GAAG,IAAI,EACb,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,GAAG,KAAK,EACzB,UAAU,EACV,YAAY,EACZ,YAAY,GAAG,IAAI,GACpB,KAAI;AACH,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAqB,IAAI,CAAC;AACrD,IAAA,MAAM,cAAc,GAAGA,YAAM,CAAqB,IAAI,CAAC;AACvD,IAAA,MAAM,WAAW,GAAGA,YAAM,CAAU,KAAK,CAAC;AAC1C,IAAA,MAAM,sBAAsB,GAAGA,YAAM,CAAyB,SAAS,CAAC;AACxE,IAAA,MAAM,iBAAiB,GAAGA,YAAM,CAAqB,IAAI,CAAC;IAE1DC,eAAS,CAAC,MAAK;;AACb,QAAA,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO;AACtC,QAAA,MAAM,oBAAoB,GAAG,CAAA,mBAAmB,KAAA,IAAA,IAAnB,mBAAmB,KAAA,MAAA,GAAA,MAAA,GAAnB,mB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AO,KAAK,iBAAiB,CAAC,OAAO,EAAE;gBACtD;YACF;AAEA,YAAA,MAAM,MAAM,GAAG,KAAK,CAAC,MAAc;;AAGnC,YAAA,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBAC7E;YACF;;AAGA,YAAA,IACE,oBAAoB;AACpB,iBAAC,MAAM,KAAK,oBAAoB,IAAI,oBAAoB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAC1E;gBACA;YACF;;AAGA,YAAA,MAAM,QAAQ,GAAGA,uBAAiB,CAAC,SAAS,CAAC;AAE7C,YAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBACzB,SAAS,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"CFocusTrap.js","sources":["../../../../src/components/focus-trap/CFocusTrap.tsx"],"sourcesContent":[null],"names":["useRef","useEffect","focusableChildren","getChildRef","mergeRefs","cloneElement"],"mappings":";;;;;AAmEO,MAAM,UAAU,GAAwB,CAAC,EAC9C,MAAM,GAAG,IAAI,EACb,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,GAAG,KAAK,EACzB,UAAU,EACV,YAAY,EACZ,YAAY,GAAG,IAAI,GACpB,KAAI;AACH,IAAA,MAAM,YAAY,GAAGA,YAAM,CAAqB,IAAI,CAAC;AACrD,IAAA,MAAM,cAAc,GAAGA,YAAM,CAAqB,IAAI,CAAC;AACvD,IAAA,MAAM,WAAW,GAAGA,YAAM,CAAU,KAAK,CAAC;AAC1C,IAAA,MAAM,sBAAsB,GAAGA,YAAM,CAAyB,SAAS,CAAC;AACxE,IAAA,MAAM,iBAAiB,GAAGA,YAAM,CAAqB,IAAI,CAAC;IAE1DC,eAAS,CAAC,MAAK;;AACb,QAAA,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO;AACtC,QAAA,MAAM,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AAC;IAE3E,MAAM,SAAS,GAAGC,eAAS,CAAC,QAAQ,EAAE,CAAC,IAAwB,KAAI;AACjE,QAAA,YAAY,CAAC,OAAO,GAAG,IAAI;AAC7B,IAAA,CAAC,CAAC;IAEF,OAAOC,kBAAY,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,EAAqC,CAAC;AACvF;;;;"}
|
|
@@ -6,6 +6,16 @@ import React from 'react';
|
|
|
6
6
|
* @returns Array of focusable HTML elements
|
|
7
7
|
*/
|
|
8
8
|
export declare const focusableChildren: (element: HTMLElement) => HTMLElement[];
|
|
9
|
+
/**
|
|
10
|
+
* Extracts the ref from a React element, handling version differences between React 18 and 19+.
|
|
11
|
+
*
|
|
12
|
+
* In React 18 and earlier, refs are stored directly on the element object.
|
|
13
|
+
* In React 19+, refs are stored in the element's props object due to changes in React's internals.
|
|
14
|
+
* This function automatically detects the React version and uses the appropriate access pattern.
|
|
15
|
+
* @param child - The React element to extract the ref from
|
|
16
|
+
* @returns The ref attached to the element, or undefined if no ref is present
|
|
17
|
+
*/
|
|
18
|
+
export declare const getChildRef: (child: React.ReactElement) => React.Ref<HTMLElement> | undefined;
|
|
9
19
|
/**
|
|
10
20
|
* Checks if an element is disabled.
|
|
11
21
|
* Considers various ways an element can be disabled including CSS classes and attributes.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Gets all focusable child elements within a container.
|
|
5
7
|
* Uses a comprehensive selector to find elements that can receive focus.
|
|
@@ -20,6 +22,28 @@ const focusableChildren = (element) => {
|
|
|
20
22
|
const elements = [...element.querySelectorAll(focusableSelectors)];
|
|
21
23
|
return elements.filter((el) => !isDisabled(el) && isVisible(el));
|
|
22
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Extracts the ref from a React element, handling version differences between React 18 and 19+.
|
|
27
|
+
*
|
|
28
|
+
* In React 18 and earlier, refs are stored directly on the element object.
|
|
29
|
+
* In React 19+, refs are stored in the element's props object due to changes in React's internals.
|
|
30
|
+
* This function automatically detects the React version and uses the appropriate access pattern.
|
|
31
|
+
* @param child - The React element to extract the ref from
|
|
32
|
+
* @returns The ref attached to the element, or undefined if no ref is present
|
|
33
|
+
*/
|
|
34
|
+
const getChildRef = (child) => {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const major = Number((_c = (_b = (_a = React.version) === null || _a === void 0 ? void 0 : _a.split) === null || _b === void 0 ? void 0 : _b.call(_a, '.')[0]) !== null && _c !== void 0 ? _c : 18);
|
|
37
|
+
// React 18 stores ref directly on the element
|
|
38
|
+
if (major <= 18 && 'ref' in child && child.ref !== undefined) {
|
|
39
|
+
return child.ref;
|
|
40
|
+
}
|
|
41
|
+
// React 19 stores ref in props
|
|
42
|
+
if (child.props && typeof child.props === 'object' && 'ref' in child.props) {
|
|
43
|
+
return child.props.ref;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
23
47
|
/**
|
|
24
48
|
* Checks if an element is disabled.
|
|
25
49
|
* Considers various ways an element can be disabled including CSS classes and attributes.
|
|
@@ -101,6 +125,7 @@ const mergeRefs = (...refs) => (node) => {
|
|
|
101
125
|
};
|
|
102
126
|
|
|
103
127
|
exports.focusableChildren = focusableChildren;
|
|
128
|
+
exports.getChildRef = getChildRef;
|
|
104
129
|
exports.isDisabled = isDisabled;
|
|
105
130
|
exports.isElement = isElement;
|
|
106
131
|
exports.isVisible = isVisible;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/components/focus-trap/utils.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/components/focus-trap/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAEA;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,OAAoB,KAAmB;AACvE,IAAA,MAAM,kB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AAa,EAAE;AACzC,YAAA,OAAO,KAAK;QACd;IACF;AAEA,IAAA,OAAO,gBAAgB;AACzB;AAEA;;;;;AAKG;AACI,MAAM,SAAS,GACpB,CAAI,GAAG,IAAkC,KACzC,CAAC,IAAO,KAAI;AACV,IAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACnB,QAAA,IAAI,CAAC,GAAG;YAAE;AACV,QAAA,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;YAC7B,GAAG,CAAC,IAAI,CAAC;QACX;aAAO;AACL,YAAA,IAAI;gBACF;AAAE,gBAAA,GAA0B,CAAC,OAAO,GAAG,IAAI;YAC7C;AAAE,YAAA,OAAA,EAAA,EAAM;;YAER;QACF;AACF,IAAA,CAAC,CAAC;AACJ;;;;;;;;;"}
|
|
@@ -17,7 +17,6 @@ var Transition = require('../../node_modules/react-transition-group/esm/Transiti
|
|
|
17
17
|
const CModal = React.forwardRef((_a, ref) => {
|
|
18
18
|
var { children, alignment, backdrop = true, className, container, duration = 150, focus = true, fullscreen, keyboard = true, onClose, onClosePrevented, onShow, portal = true, scrollable, size, transition = true, unmountOnClose = true, visible } = _a, rest = tslib_es6.__rest(_a, ["children", "alignment", "backdrop", "className", "container", "duration", "focus", "fullscreen", "keyboard", "onClose", "onClosePrevented", "onShow", "portal", "scrollable", "size", "transition", "unmountOnClose", "visible"]);
|
|
19
19
|
const modalRef = React.useRef(null);
|
|
20
|
-
const modalContentRef = React.useRef(null);
|
|
21
20
|
const forkedRef = useForkedRef.useForkedRef(ref, modalRef);
|
|
22
21
|
const [_visible, setVisible] = React.useState(visible);
|
|
23
22
|
const [staticBackdrop, setStaticBackdrop] = React.useState(false);
|
|
@@ -85,16 +84,16 @@ const CModal = React.forwardRef((_a, ref) => {
|
|
|
85
84
|
return (React.createElement(React.Fragment, null,
|
|
86
85
|
React.createElement(Transition.default, { in: _visible, mountOnEnter: true, nodeRef: modalRef, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: transition ? duration : 0 }, (state) => (React.createElement(CConditionalPortal.CConditionalPortal, { container: container, portal: portal },
|
|
87
86
|
React.createElement(CModalContext.CModalContext.Provider, { value: contextValues },
|
|
88
|
-
React.createElement(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
React.createElement(
|
|
97
|
-
React.createElement(CModalContent.CModalContent,
|
|
87
|
+
React.createElement(CFocusTrap.CFocusTrap, { active: focus && state === 'entered' },
|
|
88
|
+
React.createElement("div", Object.assign({ className: index.default('modal', {
|
|
89
|
+
'modal-static': staticBackdrop,
|
|
90
|
+
fade: transition,
|
|
91
|
+
show: state === 'entered',
|
|
92
|
+
}, className), tabIndex: -1 }, (_visible
|
|
93
|
+
? { 'aria-modal': true, role: 'dialog' }
|
|
94
|
+
: { 'aria-hidden': 'true' }), { style: Object.assign({}, (state !== 'exited' && { display: 'block' })) }, rest, { ref: forkedRef }),
|
|
95
|
+
React.createElement(CModalDialog.CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
|
|
96
|
+
React.createElement(CModalContent.CModalContent, null, children)))))))),
|
|
98
97
|
backdrop && (React.createElement(CConditionalPortal.CConditionalPortal, { container: container, portal: portal },
|
|
99
98
|
React.createElement(CBackdrop.CBackdrop, { visible: _visible })))));
|
|
100
99
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CModal.js","sources":["../../../../src/components/modal/CModal.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","useRef","useForkedRef","useState","useEffect","useLayoutEffect","Transition","CConditionalPortal","CModalContext","
|
|
1
|
+
{"version":3,"file":"CModal.js","sources":["../../../../src/components/modal/CModal.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","useRef","useForkedRef","useState","useEffect","useLayoutEffect","Transition","CConditionalPortal","CModalContext","CFocusTrap","classNames","CModalDialog","CModalContent","CBackdrop"],"mappings":";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AAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtF,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,SAAS,EAAE,SAAS,CAAC,MAAM;AAC3B,IAAA,SAAS,EAAE,SAAS,CAAC,GAAG;IACxB,QAAQ,EAAE,SAAS,CAAC,MAAM;IAC1B,KAAK,EAAE,SAAS,CAAC,IAAI;AACrB,IAAA,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC;AAC9B,QAAA,SAAS,CAAC,IAAI;AACd,QAAA,SAAS,CAAC,KAAK,CAAoC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;KACpF,CAAC;IACF,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,OAAO,EAAE,SAAS,CAAC,IAAI;IACvB,gBAAgB,EAAE,SAAS,CAAC,IAAI;IAChC,MAAM,EAAE,SAAS,CAAC,IAAI;IACtB,MAAM,EAAE,SAAS,CAAC,IAAI;IACtB,UAAU,EAAE,SAAS,CAAC,IAAI;AAC1B,IAAA,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACzC,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,cAAc,EAAE,SAAS,CAAC,IAAI;IAC9B,OAAO,EAAE,SAAS,CAAC,IAAI;CACxB;AAED,MAAM,CAAC,WAAW,GAAG,QAAQ;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useRef, useEffect, cloneElement } from 'react';
|
|
2
|
-
import { focusableChildren, mergeRefs } from './utils.js';
|
|
2
|
+
import { focusableChildren, getChildRef, mergeRefs } from './utils.js';
|
|
3
3
|
|
|
4
4
|
const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstElement = false, onActivate, onDeactivate, restoreFocus = true, }) => {
|
|
5
5
|
const containerRef = useRef(null);
|
|
@@ -62,8 +62,9 @@ const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstEl
|
|
|
62
62
|
const elements = focusableChildren(container);
|
|
63
63
|
if (elements.length === 0) {
|
|
64
64
|
container.focus({ preventScroll: true });
|
|
65
|
+
return;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
+
if (lastTabNavDirectionRef.current === 'backward') {
|
|
67
68
|
(_a = elements.at(-1)) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
68
69
|
}
|
|
69
70
|
else {
|
|
@@ -77,17 +78,30 @@ const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstEl
|
|
|
77
78
|
}
|
|
78
79
|
tabEventSourceRef.current = container;
|
|
79
80
|
lastTabNavDirectionRef.current = event.shiftKey ? 'backward' : 'forward';
|
|
80
|
-
if (!_additionalContainer) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
81
|
const containerElements = focusableChildren(container);
|
|
84
|
-
const additionalElements = focusableChildren(_additionalContainer);
|
|
82
|
+
const additionalElements = _additionalContainer ? focusableChildren(_additionalContainer) : [];
|
|
85
83
|
if (containerElements.length === 0 && additionalElements.length === 0) {
|
|
86
84
|
// No focusable elements, prevent tab
|
|
87
85
|
event.preventDefault();
|
|
88
86
|
return;
|
|
89
87
|
}
|
|
88
|
+
const focusableElements = [...containerElements, ...additionalElements];
|
|
89
|
+
const firstFocusableElement = focusableElements[0];
|
|
90
|
+
const lastFocusableElement = focusableElements.at(-1);
|
|
90
91
|
const activeElement = document.activeElement;
|
|
92
|
+
if (event.shiftKey && activeElement === firstFocusableElement) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
lastFocusableElement.focus();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!event.shiftKey && activeElement === lastFocusableElement) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
firstFocusableElement.focus();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!_additionalContainer) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
91
105
|
const isInContainer = containerElements.includes(activeElement);
|
|
92
106
|
const isInAdditional = additionalElements.includes(activeElement);
|
|
93
107
|
// Handle tab navigation between container and additional elements
|
|
@@ -149,7 +163,10 @@ const CFocusTrap = ({ active = true, additionalContainer, children, focusFirstEl
|
|
|
149
163
|
}, [active, additionalContainer, focusFirstElement, onActivate, onDeactivate, restoreFocus]);
|
|
150
164
|
// Attach our ref to the ONLY child — no extra wrappers
|
|
151
165
|
const onlyChild = React.Children.only(children);
|
|
152
|
-
|
|
166
|
+
// Handle different ref access patterns between React versions
|
|
167
|
+
// React 19+: ref is accessed via element.props.ref
|
|
168
|
+
// React 18 and earlier: ref is accessed via element.ref
|
|
169
|
+
const childRef = getChildRef(onlyChild);
|
|
153
170
|
const mergedRef = mergeRefs(childRef, (node) => {
|
|
154
171
|
containerRef.current = node;
|
|
155
172
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CFocusTrap.js","sources":["../../../../src/components/focus-trap/CFocusTrap.tsx"],"sourcesContent":[null],"names":[],"mappings":";;;AAmEO,MAAM,UAAU,GAAwB,CAAC,EAC9C,MAAM,GAAG,IAAI,EACb,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,GAAG,KAAK,EACzB,UAAU,EACV,YAAY,EACZ,YAAY,GAAG,IAAI,GACpB,KAAI;AACH,IAAA,MAAM,YAAY,GAAG,MAAM,CAAqB,IAAI,CAAC;AACrD,IAAA,MAAM,cAAc,GAAG,MAAM,CAAqB,IAAI,CAAC;AACvD,IAAA,MAAM,WAAW,GAAG,MAAM,CAAU,KAAK,CAAC;AAC1C,IAAA,MAAM,sBAAsB,GAAG,MAAM,CAAyB,SAAS,CAAC;AACxE,IAAA,MAAM,iBAAiB,GAAG,MAAM,CAAqB,IAAI,CAAC;IAE1D,SAAS,CAAC,MAAK;;AACb,QAAA,MAAM,SAAS,GAAG,YA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CAAC;;;;AAK/C,IAAA,MAAM,QAAQ,GAAuC,WAAW,CAAC,SAAS,CAAC;IAE3E,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,IAAwB,KAAI;AACjE,QAAA,YAAY,CAAC,OAAO,GAAG,IAAI;AAC7B,IAAA,CAAC,CAAC;IAEF,OAAO,YAAY,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,EAAqC,CAAC;AACvF;;;;"}
|
|
@@ -6,6 +6,16 @@ import React from 'react';
|
|
|
6
6
|
* @returns Array of focusable HTML elements
|
|
7
7
|
*/
|
|
8
8
|
export declare const focusableChildren: (element: HTMLElement) => HTMLElement[];
|
|
9
|
+
/**
|
|
10
|
+
* Extracts the ref from a React element, handling version differences between React 18 and 19+.
|
|
11
|
+
*
|
|
12
|
+
* In React 18 and earlier, refs are stored directly on the element object.
|
|
13
|
+
* In React 19+, refs are stored in the element's props object due to changes in React's internals.
|
|
14
|
+
* This function automatically detects the React version and uses the appropriate access pattern.
|
|
15
|
+
* @param child - The React element to extract the ref from
|
|
16
|
+
* @returns The ref attached to the element, or undefined if no ref is present
|
|
17
|
+
*/
|
|
18
|
+
export declare const getChildRef: (child: React.ReactElement) => React.Ref<HTMLElement> | undefined;
|
|
9
19
|
/**
|
|
10
20
|
* Checks if an element is disabled.
|
|
11
21
|
* Considers various ways an element can be disabled including CSS classes and attributes.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Gets all focusable child elements within a container.
|
|
3
5
|
* Uses a comprehensive selector to find elements that can receive focus.
|
|
@@ -18,6 +20,28 @@ const focusableChildren = (element) => {
|
|
|
18
20
|
const elements = [...element.querySelectorAll(focusableSelectors)];
|
|
19
21
|
return elements.filter((el) => !isDisabled(el) && isVisible(el));
|
|
20
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the ref from a React element, handling version differences between React 18 and 19+.
|
|
25
|
+
*
|
|
26
|
+
* In React 18 and earlier, refs are stored directly on the element object.
|
|
27
|
+
* In React 19+, refs are stored in the element's props object due to changes in React's internals.
|
|
28
|
+
* This function automatically detects the React version and uses the appropriate access pattern.
|
|
29
|
+
* @param child - The React element to extract the ref from
|
|
30
|
+
* @returns The ref attached to the element, or undefined if no ref is present
|
|
31
|
+
*/
|
|
32
|
+
const getChildRef = (child) => {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
const major = Number((_c = (_b = (_a = React.version) === null || _a === void 0 ? void 0 : _a.split) === null || _b === void 0 ? void 0 : _b.call(_a, '.')[0]) !== null && _c !== void 0 ? _c : 18);
|
|
35
|
+
// React 18 stores ref directly on the element
|
|
36
|
+
if (major <= 18 && 'ref' in child && child.ref !== undefined) {
|
|
37
|
+
return child.ref;
|
|
38
|
+
}
|
|
39
|
+
// React 19 stores ref in props
|
|
40
|
+
if (child.props && typeof child.props === 'object' && 'ref' in child.props) {
|
|
41
|
+
return child.props.ref;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
21
45
|
/**
|
|
22
46
|
* Checks if an element is disabled.
|
|
23
47
|
* Considers various ways an element can be disabled including CSS classes and attributes.
|
|
@@ -98,5 +122,5 @@ const mergeRefs = (...refs) => (node) => {
|
|
|
98
122
|
});
|
|
99
123
|
};
|
|
100
124
|
|
|
101
|
-
export { focusableChildren, isDisabled, isElement, isVisible, mergeRefs };
|
|
125
|
+
export { focusableChildren, getChildRef, isDisabled, isElement, isVisible, mergeRefs };
|
|
102
126
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/components/focus-trap/utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,OAAoB,KAAmB;AACvE,IAAA,MAAM,kBAAkB,GAAG;QACzB,SAAS;QACT,wBAAwB;QACxB,uBAAuB;QACvB,0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,KAAK;IACd;AAEA,IAAA,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,SAAS;;IAG/F,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC;IAE5D,IAAI,CAAC,aAAa,EAAE;AAClB,QAAA,OAAO,gBAAgB;IACzB;AAEA,IAAA,IAAI,aAAa,KAAK,OAAO,EAAE;QAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;;QAG1C,IAAI,CAAA,OAAO,KAAA,IAAA,IAAP,OAAO,KAAA,MAAA,GAAA,MAAA,GAAP,OAAO,CAAE,UAAU,MAAK,aAAa,EAAE;AACzC,YAAA,OAAO,KAAK;QACd;IACF;AAEA,IAAA,OAAO,gBAAgB;AACzB;AAEA;;;;;AAKG;AACI,MAAM,SAAS,GACpB,CAAI,GAAG,IAAkC,KACzC,CAAC,IAAO,KAAI;AACV,IAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACnB,QAAA,IAAI,CAAC,GAAG;YAAE;AACV,QAAA,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;YAC7B,GAAG,CAAC,IAAI,CAAC;QACX;aAAO;AACL,YAAA,IAAI;gBACF;AAAE,gBAAA,GAA0B,CAAC,OAAO,GAAG,IAAI;YAC7C;AAAE,YAAA,OAAA,EAAA,EAAM;;YAER;QACF;AACF,IAAA,CAAC,CAAC;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/components/focus-trap/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,OAAoB,KAAmB;AACvE,IAAA,MAAM,kBAAkB,GAAG;QACzB,SAAS;QACT,wBAAwB;QACxB,uBAAuB;QACvB,0BAA0B;QAC1B,wBAAwB;QACxB,SAAS;QACT,iCAAiC;QACjC,0BAA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AAI,GAAG,IAAkC,KACzC,CAAC,IAAO,KAAI;AACV,IAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACnB,QAAA,IAAI,CAAC,GAAG;YAAE;AACV,QAAA,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;YAC7B,GAAG,CAAC,IAAI,CAAC;QACX;aAAO;AACL,YAAA,IAAI;gBACF;AAAE,gBAAA,GAA0B,CAAC,OAAO,GAAG,IAAI;YAC7C;AAAE,YAAA,OAAA,EAAA,EAAM;;YAER;QACF;AACF,IAAA,CAAC,CAAC;AACJ;;;;"}
|
|
@@ -15,7 +15,6 @@ import Transition from '../../node_modules/react-transition-group/esm/Transition
|
|
|
15
15
|
const CModal = forwardRef((_a, ref) => {
|
|
16
16
|
var { children, alignment, backdrop = true, className, container, duration = 150, focus = true, fullscreen, keyboard = true, onClose, onClosePrevented, onShow, portal = true, scrollable, size, transition = true, unmountOnClose = true, visible } = _a, rest = __rest(_a, ["children", "alignment", "backdrop", "className", "container", "duration", "focus", "fullscreen", "keyboard", "onClose", "onClosePrevented", "onShow", "portal", "scrollable", "size", "transition", "unmountOnClose", "visible"]);
|
|
17
17
|
const modalRef = useRef(null);
|
|
18
|
-
const modalContentRef = useRef(null);
|
|
19
18
|
const forkedRef = useForkedRef(ref, modalRef);
|
|
20
19
|
const [_visible, setVisible] = useState(visible);
|
|
21
20
|
const [staticBackdrop, setStaticBackdrop] = useState(false);
|
|
@@ -83,16 +82,16 @@ const CModal = forwardRef((_a, ref) => {
|
|
|
83
82
|
return (React.createElement(React.Fragment, null,
|
|
84
83
|
React.createElement(Transition, { in: _visible, mountOnEnter: true, nodeRef: modalRef, onEnter: onShow, onExit: onClose, unmountOnExit: unmountOnClose, timeout: transition ? duration : 0 }, (state) => (React.createElement(CConditionalPortal, { container: container, portal: portal },
|
|
85
84
|
React.createElement(CModalContext.Provider, { value: contextValues },
|
|
86
|
-
React.createElement(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
React.createElement(
|
|
95
|
-
React.createElement(CModalContent,
|
|
85
|
+
React.createElement(CFocusTrap, { active: focus && state === 'entered' },
|
|
86
|
+
React.createElement("div", Object.assign({ className: classNames('modal', {
|
|
87
|
+
'modal-static': staticBackdrop,
|
|
88
|
+
fade: transition,
|
|
89
|
+
show: state === 'entered',
|
|
90
|
+
}, className), tabIndex: -1 }, (_visible
|
|
91
|
+
? { 'aria-modal': true, role: 'dialog' }
|
|
92
|
+
: { 'aria-hidden': 'true' }), { style: Object.assign({}, (state !== 'exited' && { display: 'block' })) }, rest, { ref: forkedRef }),
|
|
93
|
+
React.createElement(CModalDialog, { alignment: alignment, fullscreen: fullscreen, scrollable: scrollable, size: size },
|
|
94
|
+
React.createElement(CModalContent, null, children)))))))),
|
|
96
95
|
backdrop && (React.createElement(CConditionalPortal, { container: container, portal: portal },
|
|
97
96
|
React.createElement(CBackdrop, { visible: _visible })))));
|
|
98
97
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CModal.js","sources":["../../../../src/components/modal/CModal.tsx"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;AAgGO,MAAM,MAAM,GAAG,UAAU,CAC9B,CACE,EAoBC,EACD,GAAG,KACD;QAtBF,EACE,QAAQ,EACR,SAAS,EACT,QAAQ,GAAG,IAAI,EACf,SAAS,EACT,SAAS,EACT,QAAQ,GAAG,GAAG,EACd,KAAK,GAAG,IAAI,EACZ,UAAU,EACV,QAAQ,GAAG,IAAI,EACf,OAAO,EACP,gBAAgB,EAChB,MAAM,EACN,MAAM,GAAG,IAAI,EACb,UAAU,EACV,IAAI,EACJ,UAAU,GAAG,IAAI,EACjB,cAAc,GAAG,IAAI,EACrB,OAAO,EAAA,GAAA,EAER,EADI,IAAI,GAAA,MAAA,CAAA,EAAA,EAnBT,CAAA,UAAA,EAAA,WAAA,EAAA,UAAA,EAAA,WA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,IAAI;CACxB;AAED,MAAM,CAAC,WAAW,GAAG,QAAQ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/react",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.1",
|
|
4
4
|
"description": "UI Components Library for React.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -47,27 +47,27 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
50
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
50
|
+
"@rollup/plugin-node-resolve": "^16.0.2",
|
|
51
51
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
52
52
|
"@testing-library/dom": "^10.4.1",
|
|
53
|
-
"@testing-library/jest-dom": "^6.
|
|
53
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
54
54
|
"@testing-library/react": "^16.3.0",
|
|
55
55
|
"@types/jest": "^29.5.14",
|
|
56
56
|
"@types/prop-types": "15.7.15",
|
|
57
|
-
"@types/react": "^19.
|
|
58
|
-
"@types/react-dom": "^19.
|
|
57
|
+
"@types/react": "^19.2.0",
|
|
58
|
+
"@types/react-dom": "^19.2.0",
|
|
59
59
|
"@types/react-transition-group": "^4.4.12",
|
|
60
60
|
"classnames": "^2.5.1",
|
|
61
|
-
"cross-env": "^10.
|
|
61
|
+
"cross-env": "^10.1.0",
|
|
62
62
|
"jest": "^29.7.0",
|
|
63
63
|
"jest-environment-jsdom": "^29.7.0",
|
|
64
64
|
"react": "^18.3.1",
|
|
65
65
|
"react-dom": "^18.3.1",
|
|
66
66
|
"react-transition-group": "^4.4.5",
|
|
67
|
-
"rollup": "^4.
|
|
68
|
-
"ts-jest": "^29.4.
|
|
67
|
+
"rollup": "^4.52.4",
|
|
68
|
+
"ts-jest": "^29.4.4",
|
|
69
69
|
"tslib": "^2.8.1",
|
|
70
|
-
"typescript": "^5.9.
|
|
70
|
+
"typescript": "^5.9.3"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"react": ">=17",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC, ReactElement, cloneElement, useEffect, useRef } from 'react'
|
|
2
|
-
import { mergeRefs, focusableChildren } from './utils'
|
|
2
|
+
import { mergeRefs, focusableChildren, getChildRef } from './utils'
|
|
3
3
|
|
|
4
4
|
export interface CFocusTrapProps {
|
|
5
5
|
/**
|
|
@@ -146,7 +146,10 @@ export const CFocusTrap: FC<CFocusTrapProps> = ({
|
|
|
146
146
|
|
|
147
147
|
if (elements.length === 0) {
|
|
148
148
|
container.focus({ preventScroll: true })
|
|
149
|
-
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (lastTabNavDirectionRef.current === 'backward') {
|
|
150
153
|
elements.at(-1)?.focus({ preventScroll: true })
|
|
151
154
|
} else {
|
|
152
155
|
elements[0].focus({ preventScroll: true })
|
|
@@ -161,12 +164,8 @@ export const CFocusTrap: FC<CFocusTrapProps> = ({
|
|
|
161
164
|
tabEventSourceRef.current = container
|
|
162
165
|
lastTabNavDirectionRef.current = event.shiftKey ? 'backward' : 'forward'
|
|
163
166
|
|
|
164
|
-
if (!_additionalContainer) {
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
|
|
168
167
|
const containerElements = focusableChildren(container)
|
|
169
|
-
const additionalElements = focusableChildren(_additionalContainer)
|
|
168
|
+
const additionalElements = _additionalContainer ? focusableChildren(_additionalContainer) : []
|
|
170
169
|
|
|
171
170
|
if (containerElements.length === 0 && additionalElements.length === 0) {
|
|
172
171
|
// No focusable elements, prevent tab
|
|
@@ -174,7 +173,28 @@ export const CFocusTrap: FC<CFocusTrapProps> = ({
|
|
|
174
173
|
return
|
|
175
174
|
}
|
|
176
175
|
|
|
176
|
+
const focusableElements = [...containerElements, ...additionalElements]
|
|
177
|
+
|
|
178
|
+
const firstFocusableElement = focusableElements[0] as HTMLElement
|
|
179
|
+
const lastFocusableElement = focusableElements.at(-1) as HTMLElement
|
|
177
180
|
const activeElement = document.activeElement as HTMLElement
|
|
181
|
+
|
|
182
|
+
if (event.shiftKey && activeElement === firstFocusableElement) {
|
|
183
|
+
event.preventDefault()
|
|
184
|
+
lastFocusableElement.focus()
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!event.shiftKey && activeElement === lastFocusableElement) {
|
|
189
|
+
event.preventDefault()
|
|
190
|
+
firstFocusableElement.focus()
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!_additionalContainer) {
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
|
|
178
198
|
const isInContainer = containerElements.includes(activeElement)
|
|
179
199
|
const isInAdditional = additionalElements.includes(activeElement)
|
|
180
200
|
|
|
@@ -245,7 +265,12 @@ export const CFocusTrap: FC<CFocusTrapProps> = ({
|
|
|
245
265
|
|
|
246
266
|
// Attach our ref to the ONLY child — no extra wrappers
|
|
247
267
|
const onlyChild = React.Children.only(children)
|
|
248
|
-
|
|
268
|
+
|
|
269
|
+
// Handle different ref access patterns between React versions
|
|
270
|
+
// React 19+: ref is accessed via element.props.ref
|
|
271
|
+
// React 18 and earlier: ref is accessed via element.ref
|
|
272
|
+
const childRef: React.Ref<HTMLElement> | undefined = getChildRef(onlyChild)
|
|
273
|
+
|
|
249
274
|
const mergedRef = mergeRefs(childRef, (node: HTMLElement | null) => {
|
|
250
275
|
containerRef.current = node
|
|
251
276
|
})
|
|
@@ -23,6 +23,30 @@ export const focusableChildren = (element: HTMLElement): HTMLElement[] => {
|
|
|
23
23
|
return elements.filter((el) => !isDisabled(el) && isVisible(el))
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the ref from a React element, handling version differences between React 18 and 19+.
|
|
28
|
+
*
|
|
29
|
+
* In React 18 and earlier, refs are stored directly on the element object.
|
|
30
|
+
* In React 19+, refs are stored in the element's props object due to changes in React's internals.
|
|
31
|
+
* This function automatically detects the React version and uses the appropriate access pattern.
|
|
32
|
+
* @param child - The React element to extract the ref from
|
|
33
|
+
* @returns The ref attached to the element, or undefined if no ref is present
|
|
34
|
+
*/
|
|
35
|
+
export const getChildRef = (child: React.ReactElement): React.Ref<HTMLElement> | undefined => {
|
|
36
|
+
const major = Number(React.version?.split?.('.')[0] ?? 18)
|
|
37
|
+
// React 18 stores ref directly on the element
|
|
38
|
+
if (major <= 18 && 'ref' in child && child.ref !== undefined) {
|
|
39
|
+
return (child as React.ReactElement & { ref?: React.Ref<HTMLElement> }).ref
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// React 19 stores ref in props
|
|
43
|
+
if (child.props && typeof child.props === 'object' && 'ref' in child.props) {
|
|
44
|
+
return (child.props as { ref?: React.Ref<HTMLElement> }).ref
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
26
50
|
/**
|
|
27
51
|
* Checks if an element is disabled.
|
|
28
52
|
* Considers various ways an element can be disabled including CSS classes and attributes.
|
|
@@ -120,7 +120,6 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
|
|
|
120
120
|
ref
|
|
121
121
|
) => {
|
|
122
122
|
const modalRef = useRef<HTMLDivElement>(null)
|
|
123
|
-
const modalContentRef = useRef<HTMLDivElement>(null)
|
|
124
123
|
const forkedRef = useForkedRef(ref, modalRef)
|
|
125
124
|
|
|
126
125
|
const [_visible, setVisible] = useState(visible)
|
|
@@ -213,37 +212,37 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
|
|
|
213
212
|
{(state) => (
|
|
214
213
|
<CConditionalPortal container={container} portal={portal}>
|
|
215
214
|
<CModalContext.Provider value={contextValues}>
|
|
216
|
-
<
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
<CModalDialog
|
|
237
|
-
alignment={alignment}
|
|
238
|
-
fullscreen={fullscreen}
|
|
239
|
-
scrollable={scrollable}
|
|
240
|
-
size={size}
|
|
215
|
+
<CFocusTrap active={focus && state === 'entered'}>
|
|
216
|
+
<div
|
|
217
|
+
className={classNames(
|
|
218
|
+
'modal',
|
|
219
|
+
{
|
|
220
|
+
'modal-static': staticBackdrop,
|
|
221
|
+
fade: transition,
|
|
222
|
+
show: state === 'entered',
|
|
223
|
+
},
|
|
224
|
+
className
|
|
225
|
+
)}
|
|
226
|
+
tabIndex={-1}
|
|
227
|
+
{...(_visible
|
|
228
|
+
? { 'aria-modal': true, role: 'dialog' }
|
|
229
|
+
: { 'aria-hidden': 'true' })}
|
|
230
|
+
style={{
|
|
231
|
+
...(state !== 'exited' && { display: 'block' }),
|
|
232
|
+
}}
|
|
233
|
+
{...rest}
|
|
234
|
+
ref={forkedRef}
|
|
241
235
|
>
|
|
242
|
-
<
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
<CModalDialog
|
|
237
|
+
alignment={alignment}
|
|
238
|
+
fullscreen={fullscreen}
|
|
239
|
+
scrollable={scrollable}
|
|
240
|
+
size={size}
|
|
241
|
+
>
|
|
242
|
+
<CModalContent>{children}</CModalContent>
|
|
243
|
+
</CModalDialog>
|
|
244
|
+
</div>
|
|
245
|
+
</CFocusTrap>
|
|
247
246
|
</CModalContext.Provider>
|
|
248
247
|
</CConditionalPortal>
|
|
249
248
|
)}
|