@coreui/react 5.8.0 → 5.9.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.
- package/README.md +1 -1
- package/dist/cjs/components/dropdown/CDropdown.d.ts +21 -1
- package/dist/cjs/components/dropdown/CDropdown.js +67 -33
- package/dist/cjs/components/dropdown/CDropdown.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdownHeader.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdownItemPlain.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdownMenu.js.map +1 -1
- package/dist/cjs/components/dropdown/CDropdownToggle.d.ts +7 -0
- package/dist/cjs/components/dropdown/CDropdownToggle.js +3 -2
- package/dist/cjs/components/dropdown/CDropdownToggle.js.map +1 -1
- package/dist/cjs/components/dropdown/utils.d.ts +2 -0
- package/dist/cjs/components/dropdown/utils.js +13 -0
- package/dist/cjs/components/dropdown/utils.js.map +1 -1
- package/dist/cjs/components/focus-trap/utils.js +0 -5
- package/dist/cjs/components/focus-trap/utils.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdown.d.ts +21 -1
- package/dist/esm/components/dropdown/CDropdown.js +68 -34
- package/dist/esm/components/dropdown/CDropdown.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdownHeader.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdownItemPlain.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdownMenu.js.map +1 -1
- package/dist/esm/components/dropdown/CDropdownToggle.d.ts +7 -0
- package/dist/esm/components/dropdown/CDropdownToggle.js +3 -2
- package/dist/esm/components/dropdown/CDropdownToggle.js.map +1 -1
- package/dist/esm/components/dropdown/utils.d.ts +2 -0
- package/dist/esm/components/dropdown/utils.js +13 -1
- package/dist/esm/components/dropdown/utils.js.map +1 -1
- package/dist/esm/components/focus-trap/utils.js +0 -5
- package/dist/esm/components/focus-trap/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/components/dropdown/CDropdown.tsx +126 -60
- package/src/components/dropdown/CDropdownHeader.tsx +1 -0
- package/src/components/dropdown/CDropdownItemPlain.tsx +1 -0
- package/src/components/dropdown/CDropdownMenu.tsx +1 -0
- package/src/components/dropdown/CDropdownToggle.tsx +15 -1
- package/src/components/dropdown/utils.ts +21 -0
- package/src/components/focus-trap/utils.ts +0 -6
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.
|
|
49
|
+
- [Download the latest release](https://github.com/coreui/coreui-react/archive/v5.9.0.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`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementType, HTMLAttributes } from 'react';
|
|
1
|
+
import React, { ElementType, HTMLAttributes } from 'react';
|
|
2
2
|
import type { Options } from '@popperjs/core';
|
|
3
3
|
import { PolymorphicRefForwardingComponent } from '../../helpers';
|
|
4
4
|
import type { Placements } from '../../types';
|
|
@@ -126,6 +126,26 @@ export interface CDropdownProps extends HTMLAttributes<HTMLDivElement | HTMLLIEl
|
|
|
126
126
|
* @since 4.8.0
|
|
127
127
|
*/
|
|
128
128
|
portal?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Sets the reference element for positioning the React Dropdown Menu.
|
|
131
|
+
* - `toggle` - The React Dropdown Toggle button (default).
|
|
132
|
+
* - `parent` - The React Dropdown wrapper element.
|
|
133
|
+
* - `HTMLElement` - A custom HTML element.
|
|
134
|
+
* - `React.RefObject` - A custom reference element.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* // Use the parent element as reference for positioning
|
|
138
|
+
* <CDropdown reference="parent">
|
|
139
|
+
* <CDropdownToggle>Toggle dropdown</CDropdownToggle>
|
|
140
|
+
* <CDropdownMenu>
|
|
141
|
+
* <CDropdownItem>Action</CDropdownItem>
|
|
142
|
+
* <CDropdownItem>Another Action</CDropdownItem>
|
|
143
|
+
* </CDropdownMenu>
|
|
144
|
+
* </CDropdown>
|
|
145
|
+
*
|
|
146
|
+
* @since 5.9.0
|
|
147
|
+
*/
|
|
148
|
+
reference?: 'parent' | 'toggle' | HTMLElement | React.RefObject<HTMLElement | null>;
|
|
129
149
|
/**
|
|
130
150
|
* Defines the visual variant of the React Dropdown
|
|
131
151
|
*/
|
|
@@ -11,9 +11,10 @@ var props = require('../../props.js');
|
|
|
11
11
|
var getNextActiveElement = require('../../utils/getNextActiveElement.js');
|
|
12
12
|
var isRTL = require('../../utils/isRTL.js');
|
|
13
13
|
var utils = require('./utils.js');
|
|
14
|
+
var CFocusTrap = require('../focus-trap/CFocusTrap.js');
|
|
14
15
|
|
|
15
16
|
const CDropdown = React.forwardRef((_a, ref) => {
|
|
16
|
-
var { children, alignment, as = 'div', autoClose = true, className, container, dark, direction, offset = [0, 2], onHide, onShow, placement = 'bottom-start', popper = true, popperConfig, portal = false, variant = 'btn-group', visible = false } = _a, rest = tslib_es6.__rest(_a, ["children", "alignment", "as", "autoClose", "className", "container", "dark", "direction", "offset", "onHide", "onShow", "placement", "popper", "popperConfig", "portal", "variant", "visible"]);
|
|
17
|
+
var { children, alignment, as = 'div', autoClose = true, className, container, dark, direction, offset = [0, 2], onHide, onShow, placement = 'bottom-start', popper = true, popperConfig, portal = false, reference = 'toggle', variant = 'btn-group', visible = false } = _a, rest = tslib_es6.__rest(_a, ["children", "alignment", "as", "autoClose", "className", "container", "dark", "direction", "offset", "onHide", "onShow", "placement", "popper", "popperConfig", "portal", "reference", "variant", "visible"]);
|
|
17
18
|
const dropdownRef = React.useRef(null);
|
|
18
19
|
const dropdownMenuRef = React.useRef(null);
|
|
19
20
|
const forkedRef = useForkedRef.useForkedRef(ref, dropdownRef);
|
|
@@ -51,12 +52,19 @@ const CDropdown = React.forwardRef((_a, ref) => {
|
|
|
51
52
|
}
|
|
52
53
|
}, [visible]);
|
|
53
54
|
React.useEffect(() => {
|
|
54
|
-
|
|
55
|
+
return () => {
|
|
56
|
+
if (_visible) {
|
|
57
|
+
handleHide();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
const referenceElement = utils.getReferenceElement(reference, dropdownToggleElement, dropdownRef);
|
|
55
63
|
const menuElement = dropdownMenuRef.current;
|
|
56
|
-
if (allowPopperUse && menuElement &&
|
|
57
|
-
initPopper(
|
|
64
|
+
if (allowPopperUse && menuElement && referenceElement && _visible) {
|
|
65
|
+
initPopper(referenceElement, menuElement, computedPopperConfig);
|
|
58
66
|
}
|
|
59
|
-
}, [dropdownToggleElement]);
|
|
67
|
+
}, [dropdownToggleElement, reference]);
|
|
60
68
|
React.useEffect(() => {
|
|
61
69
|
if (pendingKeyDownEvent !== null) {
|
|
62
70
|
handleKeydown(pendingKeyDownEvent);
|
|
@@ -65,19 +73,22 @@ const CDropdown = React.forwardRef((_a, ref) => {
|
|
|
65
73
|
}, [pendingKeyDownEvent]);
|
|
66
74
|
const handleHide = React.useCallback(() => {
|
|
67
75
|
setVisible(false);
|
|
68
|
-
const toggleElement = dropdownToggleElement;
|
|
69
76
|
const menuElement = dropdownMenuRef.current;
|
|
77
|
+
const toggleElement = dropdownToggleElement;
|
|
70
78
|
if (allowPopperUse) {
|
|
71
79
|
destroyPopper();
|
|
72
80
|
}
|
|
73
|
-
toggleElement === null || toggleElement === void 0 ? void 0 : toggleElement.removeEventListener('keydown', handleKeydown);
|
|
74
81
|
menuElement === null || menuElement === void 0 ? void 0 : menuElement.removeEventListener('keydown', handleKeydown);
|
|
75
|
-
|
|
82
|
+
toggleElement === null || toggleElement === void 0 ? void 0 : toggleElement.removeEventListener('keydown', handleKeydown);
|
|
83
|
+
window.removeEventListener('click', handleClick);
|
|
76
84
|
window.removeEventListener('keyup', handleKeyup);
|
|
77
85
|
onHide === null || onHide === void 0 ? void 0 : onHide();
|
|
78
|
-
}, [
|
|
86
|
+
}, [allowPopperUse, dropdownToggleElement, destroyPopper, onHide]);
|
|
79
87
|
const handleKeydown = React.useCallback((event) => {
|
|
80
|
-
if (dropdownMenuRef.current
|
|
88
|
+
if (!dropdownMenuRef.current) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
81
92
|
event.preventDefault();
|
|
82
93
|
const target = event.target;
|
|
83
94
|
const items = [
|
|
@@ -94,35 +105,44 @@ const CDropdown = React.forwardRef((_a, ref) => {
|
|
|
94
105
|
handleHide();
|
|
95
106
|
dropdownToggleElement === null || dropdownToggleElement === void 0 ? void 0 : dropdownToggleElement.focus();
|
|
96
107
|
}
|
|
97
|
-
}, [autoClose, handleHide]);
|
|
98
|
-
const
|
|
108
|
+
}, [autoClose, dropdownToggleElement, handleHide]);
|
|
109
|
+
const handleClick = React.useCallback((event) => {
|
|
99
110
|
if (!dropdownToggleElement || !dropdownMenuRef.current) {
|
|
100
111
|
return;
|
|
101
112
|
}
|
|
102
|
-
if (
|
|
113
|
+
if (event.button === 2) {
|
|
103
114
|
return;
|
|
104
115
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
!dropdownMenuRef.current.contains(event.target))) {
|
|
110
|
-
setTimeout(() => handleHide(), 1);
|
|
116
|
+
const composedPath = event.composedPath();
|
|
117
|
+
const isOnToggle = composedPath.includes(dropdownToggleElement);
|
|
118
|
+
const isOnMenu = composedPath.includes(dropdownMenuRef.current);
|
|
119
|
+
if (isOnToggle) {
|
|
111
120
|
return;
|
|
112
121
|
}
|
|
122
|
+
const target = event.target;
|
|
123
|
+
const FORM_TAG_RE = /^(input|select|option|textarea|form|button|label)$/i;
|
|
124
|
+
if (isOnMenu && target && FORM_TAG_RE.test(target.tagName)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (autoClose === true ||
|
|
128
|
+
(autoClose === 'inside' && isOnMenu) ||
|
|
129
|
+
(autoClose === 'outside' && !isOnMenu)) {
|
|
130
|
+
handleHide();
|
|
131
|
+
}
|
|
113
132
|
}, [autoClose, dropdownToggleElement, handleHide]);
|
|
114
133
|
const handleShow = React.useCallback((event) => {
|
|
115
|
-
const toggleElement = dropdownToggleElement;
|
|
116
134
|
const menuElement = dropdownMenuRef.current;
|
|
117
|
-
|
|
135
|
+
const referenceElement = utils.getReferenceElement(reference, dropdownToggleElement, dropdownRef);
|
|
136
|
+
const toggleElement = dropdownToggleElement;
|
|
137
|
+
if (menuElement && referenceElement && toggleElement) {
|
|
118
138
|
setVisible(true);
|
|
119
139
|
if (allowPopperUse) {
|
|
120
|
-
initPopper(
|
|
140
|
+
initPopper(referenceElement, menuElement, computedPopperConfig);
|
|
121
141
|
}
|
|
122
142
|
toggleElement.focus();
|
|
123
143
|
toggleElement.addEventListener('keydown', handleKeydown);
|
|
124
144
|
menuElement.addEventListener('keydown', handleKeydown);
|
|
125
|
-
window.addEventListener('
|
|
145
|
+
window.addEventListener('click', handleClick);
|
|
126
146
|
window.addEventListener('keyup', handleKeyup);
|
|
127
147
|
if (event && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
|
128
148
|
setPendingKeyDownEvent(event);
|
|
@@ -130,16 +150,17 @@ const CDropdown = React.forwardRef((_a, ref) => {
|
|
|
130
150
|
onShow === null || onShow === void 0 ? void 0 : onShow();
|
|
131
151
|
}
|
|
132
152
|
}, [
|
|
133
|
-
dropdownToggleElement,
|
|
134
153
|
allowPopperUse,
|
|
135
|
-
initPopper,
|
|
136
154
|
computedPopperConfig,
|
|
155
|
+
dropdownToggleElement,
|
|
156
|
+
reference,
|
|
157
|
+
handleClick,
|
|
137
158
|
handleKeydown,
|
|
138
|
-
handleMouseUp,
|
|
139
159
|
handleKeyup,
|
|
160
|
+
initPopper,
|
|
140
161
|
onShow,
|
|
141
162
|
]);
|
|
142
|
-
const contextValues = {
|
|
163
|
+
const contextValues = React.useMemo(() => ({
|
|
143
164
|
alignment,
|
|
144
165
|
container,
|
|
145
166
|
dark,
|
|
@@ -151,12 +172,25 @@ const CDropdown = React.forwardRef((_a, ref) => {
|
|
|
151
172
|
portal,
|
|
152
173
|
variant,
|
|
153
174
|
visible: _visible,
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
}), [
|
|
176
|
+
alignment,
|
|
177
|
+
container,
|
|
178
|
+
dark,
|
|
179
|
+
dropdownMenuRef,
|
|
180
|
+
dropdownToggleRef,
|
|
181
|
+
handleHide,
|
|
182
|
+
handleShow,
|
|
183
|
+
allowPopperUse,
|
|
184
|
+
portal,
|
|
185
|
+
variant,
|
|
186
|
+
_visible,
|
|
187
|
+
]);
|
|
188
|
+
return (React.createElement(CDropdownContext.CDropdownContext.Provider, { value: contextValues },
|
|
189
|
+
React.createElement(CFocusTrap.CFocusTrap, { active: portal && _visible, additionalContainer: dropdownMenuRef, restoreFocus: true }, variant === 'input-group' ? (React.createElement(React.Fragment, null, children)) : (React.createElement(Component, Object.assign({ className: index.default(variant === 'nav-item' ? 'nav-item dropdown' : variant, {
|
|
190
|
+
'dropdown-center': direction === 'center',
|
|
191
|
+
'dropup dropup-center': direction === 'dropup-center',
|
|
192
|
+
[`${direction}`]: direction && direction !== 'center' && direction !== 'dropup-center',
|
|
193
|
+
}, className) }, rest, { ref: forkedRef }), children)))));
|
|
160
194
|
});
|
|
161
195
|
const alignmentDirection = PropTypes.oneOf(['start', 'end']);
|
|
162
196
|
CDropdown.propTypes = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CDropdown.js","sources":["../../../../src/components/dropdown/CDropdown.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","useRef","useForkedRef","useState","usePopper","useCallback","useMemo","getPlacement","isRTL","useEffect","getNextActiveElement","CDropdownContext","classNames","placementPropType"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CDropdown.js","sources":["../../../../src/components/dropdown/CDropdown.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","useRef","useForkedRef","useState","usePopper","useCallback","useMemo","getPlacement","isRTL","useEffect","getReferenceElement","getNextActiveElement","CDropdownContext","CFocusTrap","classNames","placementPropType"],"mappings":";;;;;;;;;;;;;;;AA8MO,MAAM,SAAS,GAA6DA,gBAAU,CAI3F,CACE,EAoBC,EACD,GAAG,KACD;AAtBF,IAAA,IAAA,EACE,QAAQ,EACR,SAAS,EACT,EAAE,GAAG,KAAK,EACV,SAAS,GAAG,IAAI,EAChB,SAAS,EACT,SAAS,EACT,IAAI,EACJ,SAAS,EACT,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACf,MAAM,EACN,MAAM,EACN,SAAS,GAAG,cAAc,EAC1B,MAAM,GAAG,IAAI,EACb,YAAY,EACZ,MAAM,GAAG,KAAK,EACd,SAAS,GAAG,QAAQ,EACpB,OAAO,GAAG,WAAW,EACrB,OAAO,GAAG,KAAK,EAAA,GAAA,EAEhB,EADI,IAAI,GAAAC,gBAAA,CAAA,EAAA,EAnBT,6MAoBC,CADQ;AAIT,IAAA,MAAM,WAAW,GAAGC,YAAM,CAAiB,IAAI,CAAC;AAChD,IAAA,MAAM,eAAe,GAAGA,YAAM,CAAoC,IAAI,CAAC;IACvE,MAAM,SAAS,GAAGC,yBAAY,CAAC,GAAG,EAAE,WAAW,CAAC;IAChD,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAGC,cAAQ,CAAqB,IAAI,CAAC;IAC5F,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAGA,cAAQ,CAAuB,IAAI,CAAC;IAC1F,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAC,OAAO,CAAC;IAChD,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAGC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;IACxB,SAAS,EAAE,SAAS,CAAC,MAAM;IAC3B,IAAI,EAAE,SAAS,CAAC,IAAI;AACpB,IAAA,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AACzF,IAAA,MAAM,EAAE,SAAS,CAAC,GAAG;IACrB,MAAM,EAAE,SAAS,CAAC,IAAI;IACtB,MAAM,EAAE,SAAS,CAAC,IAAI;AACtB,IAAA,SAAS,EAAEC,uBAAiB;IAC5B,MAAM,EAAE,SAAS,CAAC,IAAI;AACtB,IAAA,YAAY,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACrE,MAAM,EAAE,SAAS,CAAC,IAAI;AACtB,IAAA,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IAC9E,OAAO,EAAE,SAAS,CAAC,IAAI;CACxB;AAED,SAAS,CAAC,WAAW,GAAG,WAAW;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CDropdownHeader.js","sources":["../../../../src/components/dropdown/CDropdownHeader.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","classNames"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"CDropdownHeader.js","sources":["../../../../src/components/dropdown/CDropdownHeader.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","classNames"],"mappings":";;;;;;;AAkBO,MAAM,eAAe,GAC1BA,gBAAU,CACR,CAAC,EAAsD,EAAE,GAAG,KAAI;AAA/D,IAAA,IAAA,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI,EAAE,SAAS,EAAA,GAAA,EAAW,EAAN,IAAI,GAAAC,gBAAA,CAAA,EAAA,EAApD,+BAAsD,CAAF;IACnD,QACE,oBAAC,SAAS,EAAA,MAAA,CAAA,MAAA,CAAA,EAAC,SAAS,EAAEC,aAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC,EAAA,EAAM,IAAI,IAAE,GAAG,EAAE,GAAG,EAAA,CAAA,EAC/E,QAAQ,CACC;AAEhB,CAAC;AAGL,eAAe,CAAC,SAAS,GAAG;IAC1B,EAAE,EAAE,SAAS,CAAC,WAAW;IACzB,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,SAAS,EAAE,SAAS,CAAC,MAAM;CAC5B;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CDropdownItemPlain.js","sources":["../../../../src/components/dropdown/CDropdownItemPlain.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","classNames"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"CDropdownItemPlain.js","sources":["../../../../src/components/dropdown/CDropdownItemPlain.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","classNames"],"mappings":";;;;;;;AAkBO,MAAM,kBAAkB,GAG3BA,gBAAU,CACZ,CAAC,EAAwD,EAAE,GAAG,KAAI;AAAjE,IAAA,IAAA,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,GAAG,MAAM,EAAE,SAAS,EAAA,GAAA,EAAW,EAAN,IAAI,GAAAC,gBAAA,CAAA,EAAA,EAAtD,+BAAwD,CAAF;IACrD,QACE,oBAAC,SAAS,EAAA,MAAA,CAAA,MAAA,CAAA,EAAC,SAAS,EAAEC,aAAU,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAA,EAAM,IAAI,IAAE,GAAG,EAAE,GAAG,EAAA,CAAA,EAClF,QAAQ,CACC;AAEhB,CAAC;AAGH,kBAAkB,CAAC,SAAS,GAAG;IAC7B,EAAE,EAAE,SAAS,CAAC,WAAW;IACzB,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,SAAS,EAAE,SAAS,CAAC,MAAM;CAC5B;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CDropdownMenu.js","sources":["../../../../src/components/dropdown/CDropdownMenu.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","useContext","CDropdownContext","useForkedRef","CConditionalPortal","classNames","getAlignmentClassNames"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"CDropdownMenu.js","sources":["../../../../src/components/dropdown/CDropdownMenu.tsx"],"sourcesContent":[null],"names":["forwardRef","__rest","useContext","CDropdownContext","useForkedRef","CConditionalPortal","classNames","getAlignmentClassNames"],"mappings":";;;;;;;;;;;;AAwBO,MAAM,aAAa,GACxBA,gBAAU,CACR,CAAC,EAAsD,EAAE,GAAG,KAAI;AAA/D,IAAA,IAAA,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI,EAAE,SAAS,EAAA,GAAA,EAAW,EAAN,IAAI,GAAAC,gBAAA,CAAA,EAAA,EAApD,+BAAsD,CAAF;IACnD,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAC5EC,gBAAU,CAACC,iCAAgB,CAAC;IAE9B,MAAM,SAAS,GAAGC,yBAAY,CAAC,GAAG,EAAE,eAAe,CAAC;AAEpD,IAAA,QACE,KAAA,CAAA,aAAA,CAACC,qCAAkB,EAAA,EAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,MAAA,GAAN,MAAM,GAAI,KAAK,EAAA;AAC/D,QAAA,KAAA,CAAA,aAAA,CAAC,SAAS,EAAA,MAAA,CAAA,MAAA,CAAA,EACR,SAAS,EAAEC,aAAU,CACnB,eAAe,EACf;AACE,gBAAA,IAAI,EAAE,OAAO;AACd,aAAA,EACD,SAAS,IAAIC,4BAAsB,CAAC,SAAS,CAAC,EAC9C,SAAS,CACV,EACD,GAAG,EAAE,SAAS,EACd,IAAI,EAAC,MAAM,EAAA,GACN,CAAC,MAAM,IAAI,EAAE,oBAAoB,EAAE,QAAQ,EAAE,IAC7C,IAAI,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,GACxC,IAAI,CAAA,EAEP,SAAS,KAAK;AACb,cAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAI;AAC5C,gBAAA,IAAI,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;AAC/B,oBAAA,OAAO,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAI,GAAG,EAAE,KAAK,EAAA,EAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAM;gBACzD;gBACA;AACF,YAAA,CAAC;AACH,cAAE,QAAQ,CACF,CACO;AAEzB,CAAC;AAGL,aAAa,CAAC,SAAS,GAAG;IACxB,EAAE,EAAE,SAAS,CAAC,WAAW;IACzB,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,SAAS,EAAE,SAAS,CAAC,MAAM;CAC5B;AAED,aAAa,CAAC,WAAW,GAAG,eAAe;;;;"}
|
|
@@ -23,6 +23,13 @@ export interface CDropdownToggleProps extends Omit<CButtonProps, 'type'> {
|
|
|
23
23
|
* className for proper spacing around the dropdown caret.
|
|
24
24
|
*/
|
|
25
25
|
split?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Screen reader label for split button dropdown toggle.
|
|
28
|
+
*
|
|
29
|
+
* @default 'Toggle Dropdown'
|
|
30
|
+
* @since 5.9.0
|
|
31
|
+
*/
|
|
32
|
+
splitLabel?: string;
|
|
26
33
|
/**
|
|
27
34
|
* Sets which event handlers you'd like provided to your toggle prop. You can
|
|
28
35
|
* specify one trigger or an array of them.
|
|
@@ -9,7 +9,7 @@ var CDropdownContext = require('./CDropdownContext.js');
|
|
|
9
9
|
var props = require('../../props.js');
|
|
10
10
|
|
|
11
11
|
const CDropdownToggle = (_a) => {
|
|
12
|
-
var { children, caret = true, custom, className, navLink = true, split, trigger = 'click' } = _a, rest = tslib_es6.__rest(_a, ["children", "caret", "custom", "className", "navLink", "split", "trigger"]);
|
|
12
|
+
var { children, caret = true, custom, className, navLink = true, split, splitLabel = 'Toggle Dropdown', trigger = 'click' } = _a, rest = tslib_es6.__rest(_a, ["children", "caret", "custom", "className", "navLink", "split", "splitLabel", "trigger"]);
|
|
13
13
|
const { dropdownToggleRef, handleHide, handleShow, variant, visible } = React.useContext(CDropdownContext.CDropdownContext);
|
|
14
14
|
const triggers = Object.assign(Object.assign(Object.assign({}, ((trigger === 'click' || trigger.includes('click')) && {
|
|
15
15
|
onClick: (event) => {
|
|
@@ -44,7 +44,7 @@ const CDropdownToggle = (_a) => {
|
|
|
44
44
|
}
|
|
45
45
|
return (React.createElement(CButton.CButton, Object.assign({}, togglerProps, { tabIndex: 0 }, rest, { ref: dropdownToggleRef }),
|
|
46
46
|
children,
|
|
47
|
-
split && React.createElement("span", { className: "visually-hidden" },
|
|
47
|
+
split && React.createElement("span", { className: "visually-hidden" }, splitLabel)));
|
|
48
48
|
};
|
|
49
49
|
CDropdownToggle.propTypes = {
|
|
50
50
|
caret: PropTypes.bool,
|
|
@@ -52,6 +52,7 @@ CDropdownToggle.propTypes = {
|
|
|
52
52
|
className: PropTypes.string,
|
|
53
53
|
custom: PropTypes.bool,
|
|
54
54
|
split: PropTypes.bool,
|
|
55
|
+
splitLabel: PropTypes.string,
|
|
55
56
|
trigger: props.triggerPropType,
|
|
56
57
|
};
|
|
57
58
|
CDropdownToggle.displayName = 'CDropdownToggle';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CDropdownToggle.js","sources":["../../../../src/components/dropdown/CDropdownToggle.tsx"],"sourcesContent":[null],"names":["__rest","useContext","CDropdownContext","classNames","CButton","triggerPropType"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"CDropdownToggle.js","sources":["../../../../src/components/dropdown/CDropdownToggle.tsx"],"sourcesContent":[null],"names":["__rest","useContext","CDropdownContext","classNames","CButton","triggerPropType"],"mappings":";;;;;;;;;;AAqDO,MAAM,eAAe,GAA6B,CAAC,EAUzD,KAAI;AAVqD,IAAA,IAAA,EACxD,QAAQ,EACR,KAAK,GAAG,IAAI,EACZ,MAAM,EACN,SAAS,EACT,OAAO,GAAG,IAAI,EACd,KAAK,EACL,UAAU,GAAG,iBAAiB,EAC9B,OAAO,GAAG,OAAO,EAAA,GAAA,EAElB,EADI,IAAI,GAAAA,gBAAA,CAAA,EAAA,EATiD,CAAA,UAAA,EAAA,OAAA,EAAA,QAAA,EAAA,WAAA,EAAA,SAAA,EAAA,OAAA,EAAA,YAAA,EAAA,SAAA,CAUzD,CADQ;AAEP,IAAA,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,GACnEC,gBAAU,CAACC,iCAAgB,CAAC;AAE9B,IAAA,MAAM,QAAQ,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,GACR,CAAC,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK;AACxD,QAAA,OAAO,EAAE,CAAC,KAAoC,KAAI;YAChD,KAAK,CAAC,cAAc,EAAE;YAEtB,IAAI,OAAO,EAAE;AACX,gBAAA,UAAU,KAAA,IAAA,IAAV,UAAU,KAAA,MAAA,GAAA,MAAA,GAAV,UAAU,EAAI;YAChB;iBAAO;AACL,gBAAA,UAAU,KAAA,IAAA,IAAV,UAAU,KAAA,MAAA,GAAA,MAAA,GAAV,UAAU,EAAI;YAChB;QACF,CAAC;AACF,KAAA,EAAC,GACE,CAAC,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK;QACxD,OAAO,EAAE,MAAM,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AAiB,EAAA,CAAA,CACtB,CACD;IAEP;AAEA,IAAA,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,EAAE;QACrC,QACE,yCAAG,IAAI,EAAC,GAAG,EAAA,EAAK,YAAY,IAAE,IAAI,EAAC,QAAQ,EAAA,EAAK,IAAI,IAAE,GAAG,EAAE,iBAAiB,EAAA,CAAA,EACzE,QAAQ,CACP;IAER;AAEA,IAAA,QACE,KAAA,CAAA,aAAA,CAACC,eAAO,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAK,YAAY,EAAA,EAAE,QAAQ,EAAE,CAAC,EAAA,EAAM,IAAI,EAAA,EAAE,GAAG,EAAE,iBAAiB,EAAA,CAAA;QACrE,QAAQ;QACR,KAAK,IAAI,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,iBAAiB,IAAE,UAAU,CAAQ,CACvD;AAEd;AAEA,eAAe,CAAC,SAAS,GAAG;IAC1B,KAAK,EAAE,SAAS,CAAC,IAAI;IACrB,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,SAAS,EAAE,SAAS,CAAC,MAAM;IAC3B,MAAM,EAAE,SAAS,CAAC,IAAI;IACtB,KAAK,EAAE,SAAS,CAAC,IAAI;IACrB,UAAU,EAAE,SAAS,CAAC,MAAM;AAC5B,IAAA,OAAO,EAAEC,qBAAe;CACzB;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB;;;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { Placement } from '@popperjs/core';
|
|
2
3
|
import type { Placements } from '../../types';
|
|
3
4
|
import type { Alignments } from './types';
|
|
4
5
|
export declare const getAlignmentClassNames: (alignment: Alignments) => string[];
|
|
5
6
|
export declare const getPlacement: (placement: Placement, direction: string | undefined, alignment: Alignments | string | undefined, isRTL: boolean) => Placements;
|
|
7
|
+
export declare const getReferenceElement: (reference: "parent" | "toggle" | React.RefObject<HTMLElement | null> | HTMLElement, dropdownToggleElement: HTMLElement | null, dropdownRef: React.RefObject<HTMLElement | null>) => HTMLElement | null;
|
|
@@ -31,7 +31,20 @@ const getPlacement = (placement, direction, alignment, isRTL) => {
|
|
|
31
31
|
}
|
|
32
32
|
return _placement;
|
|
33
33
|
};
|
|
34
|
+
const getReferenceElement = (reference, dropdownToggleElement, dropdownRef) => {
|
|
35
|
+
if (reference === 'parent') {
|
|
36
|
+
return dropdownRef.current;
|
|
37
|
+
}
|
|
38
|
+
if (reference instanceof HTMLElement) {
|
|
39
|
+
return reference;
|
|
40
|
+
}
|
|
41
|
+
if (reference instanceof Object && 'current' in reference) {
|
|
42
|
+
return reference.current;
|
|
43
|
+
}
|
|
44
|
+
return dropdownToggleElement;
|
|
45
|
+
};
|
|
34
46
|
|
|
35
47
|
exports.getAlignmentClassNames = getAlignmentClassNames;
|
|
36
48
|
exports.getPlacement = getPlacement;
|
|
49
|
+
exports.getReferenceElement = getReferenceElement;
|
|
37
50
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/components/dropdown/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/components/dropdown/utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKO,MAAM,sBAAsB,GAAG,CAAC,SAAqB,KAAI;IAC9D,MAAM,UAAU,GAAa,EAAE;AAC/B,IAAA,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;AACjC,QAAA,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE;YAC3B,UAAU,CAAC,IAAI,CACb,CAAA,aAAA,EAAgB,GAAG,KAAK,IAAI,GAAG,EAAE,GAAG,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE,CAAA,CAAA,EAAI,SAAS,CAAC,GAAwB,CAAC,CAAA,CAAE,CACvF;QACH;IACF;AAEA,IAAA,IAAI,OAAO,SAAS,KAAK,QAAQ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if ('jquery' in object && object.jquery !== undefined) {
|
|
53
|
-
const jQueryObject = object;
|
|
54
|
-
return isElement(jQueryObject[0]);
|
|
55
|
-
}
|
|
56
51
|
return 'nodeType' in object && typeof object.nodeType === 'number';
|
|
57
52
|
};
|
|
58
53
|
/**
|
|
@@ -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,0BAA0B;QAC1B,wBAAwB;QACxB,SAAS;QACT,iCAAiC;QACjC,0BAA0B;AAC3B,KAAA,CAAC,IAAI,CAAC,GAAG,CAAC;IAEX,MAAM,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAc,kBAAkB,CAAC,CAAkB;IAEhG,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC;AAClE;AAEA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAAC,OAAoB,KAAa;IAC1D,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,EAAE;AACtD,QAAA,OAAO,IAAI;IACb;IAEA,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;AAC1C,QAAA,OAAO,IAAI;IACb;IAEA,IAAI,UAAU,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE;QAClE,OAAO,OAAO,CAAC,QAAQ;IACzB;AAEA,IAAA,OAAO,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,OAA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AO,GAAG,IAAI;YAC7C;AAAE,YAAA,OAAA,EAAA,EAAM;;YAER;QACF;AACF,IAAA,CAAC,CAAC;AACJ;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementType, HTMLAttributes } from 'react';
|
|
1
|
+
import React, { ElementType, HTMLAttributes } from 'react';
|
|
2
2
|
import type { Options } from '@popperjs/core';
|
|
3
3
|
import { PolymorphicRefForwardingComponent } from '../../helpers';
|
|
4
4
|
import type { Placements } from '../../types';
|
|
@@ -126,6 +126,26 @@ export interface CDropdownProps extends HTMLAttributes<HTMLDivElement | HTMLLIEl
|
|
|
126
126
|
* @since 4.8.0
|
|
127
127
|
*/
|
|
128
128
|
portal?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Sets the reference element for positioning the React Dropdown Menu.
|
|
131
|
+
* - `toggle` - The React Dropdown Toggle button (default).
|
|
132
|
+
* - `parent` - The React Dropdown wrapper element.
|
|
133
|
+
* - `HTMLElement` - A custom HTML element.
|
|
134
|
+
* - `React.RefObject` - A custom reference element.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* // Use the parent element as reference for positioning
|
|
138
|
+
* <CDropdown reference="parent">
|
|
139
|
+
* <CDropdownToggle>Toggle dropdown</CDropdownToggle>
|
|
140
|
+
* <CDropdownMenu>
|
|
141
|
+
* <CDropdownItem>Action</CDropdownItem>
|
|
142
|
+
* <CDropdownItem>Another Action</CDropdownItem>
|
|
143
|
+
* </CDropdownMenu>
|
|
144
|
+
* </CDropdown>
|
|
145
|
+
*
|
|
146
|
+
* @since 5.9.0
|
|
147
|
+
*/
|
|
148
|
+
reference?: 'parent' | 'toggle' | HTMLElement | React.RefObject<HTMLElement | null>;
|
|
129
149
|
/**
|
|
130
150
|
* Defines the visual variant of the React Dropdown
|
|
131
151
|
*/
|
|
@@ -8,10 +8,11 @@ import { usePopper } from '../../hooks/usePopper.js';
|
|
|
8
8
|
import { placementPropType } from '../../props.js';
|
|
9
9
|
import getNextActiveElement from '../../utils/getNextActiveElement.js';
|
|
10
10
|
import isRTL from '../../utils/isRTL.js';
|
|
11
|
-
import { getPlacement } from './utils.js';
|
|
11
|
+
import { getPlacement, getReferenceElement } from './utils.js';
|
|
12
|
+
import { CFocusTrap } from '../focus-trap/CFocusTrap.js';
|
|
12
13
|
|
|
13
14
|
const CDropdown = forwardRef((_a, ref) => {
|
|
14
|
-
var { children, alignment, as = 'div', autoClose = true, className, container, dark, direction, offset = [0, 2], onHide, onShow, placement = 'bottom-start', popper = true, popperConfig, portal = false, variant = 'btn-group', visible = false } = _a, rest = __rest(_a, ["children", "alignment", "as", "autoClose", "className", "container", "dark", "direction", "offset", "onHide", "onShow", "placement", "popper", "popperConfig", "portal", "variant", "visible"]);
|
|
15
|
+
var { children, alignment, as = 'div', autoClose = true, className, container, dark, direction, offset = [0, 2], onHide, onShow, placement = 'bottom-start', popper = true, popperConfig, portal = false, reference = 'toggle', variant = 'btn-group', visible = false } = _a, rest = __rest(_a, ["children", "alignment", "as", "autoClose", "className", "container", "dark", "direction", "offset", "onHide", "onShow", "placement", "popper", "popperConfig", "portal", "reference", "variant", "visible"]);
|
|
15
16
|
const dropdownRef = useRef(null);
|
|
16
17
|
const dropdownMenuRef = useRef(null);
|
|
17
18
|
const forkedRef = useForkedRef(ref, dropdownRef);
|
|
@@ -49,12 +50,19 @@ const CDropdown = forwardRef((_a, ref) => {
|
|
|
49
50
|
}
|
|
50
51
|
}, [visible]);
|
|
51
52
|
useEffect(() => {
|
|
52
|
-
|
|
53
|
+
return () => {
|
|
54
|
+
if (_visible) {
|
|
55
|
+
handleHide();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}, []);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const referenceElement = getReferenceElement(reference, dropdownToggleElement, dropdownRef);
|
|
53
61
|
const menuElement = dropdownMenuRef.current;
|
|
54
|
-
if (allowPopperUse && menuElement &&
|
|
55
|
-
initPopper(
|
|
62
|
+
if (allowPopperUse && menuElement && referenceElement && _visible) {
|
|
63
|
+
initPopper(referenceElement, menuElement, computedPopperConfig);
|
|
56
64
|
}
|
|
57
|
-
}, [dropdownToggleElement]);
|
|
65
|
+
}, [dropdownToggleElement, reference]);
|
|
58
66
|
useEffect(() => {
|
|
59
67
|
if (pendingKeyDownEvent !== null) {
|
|
60
68
|
handleKeydown(pendingKeyDownEvent);
|
|
@@ -63,19 +71,22 @@ const CDropdown = forwardRef((_a, ref) => {
|
|
|
63
71
|
}, [pendingKeyDownEvent]);
|
|
64
72
|
const handleHide = useCallback(() => {
|
|
65
73
|
setVisible(false);
|
|
66
|
-
const toggleElement = dropdownToggleElement;
|
|
67
74
|
const menuElement = dropdownMenuRef.current;
|
|
75
|
+
const toggleElement = dropdownToggleElement;
|
|
68
76
|
if (allowPopperUse) {
|
|
69
77
|
destroyPopper();
|
|
70
78
|
}
|
|
71
|
-
toggleElement === null || toggleElement === void 0 ? void 0 : toggleElement.removeEventListener('keydown', handleKeydown);
|
|
72
79
|
menuElement === null || menuElement === void 0 ? void 0 : menuElement.removeEventListener('keydown', handleKeydown);
|
|
73
|
-
|
|
80
|
+
toggleElement === null || toggleElement === void 0 ? void 0 : toggleElement.removeEventListener('keydown', handleKeydown);
|
|
81
|
+
window.removeEventListener('click', handleClick);
|
|
74
82
|
window.removeEventListener('keyup', handleKeyup);
|
|
75
83
|
onHide === null || onHide === void 0 ? void 0 : onHide();
|
|
76
|
-
}, [
|
|
84
|
+
}, [allowPopperUse, dropdownToggleElement, destroyPopper, onHide]);
|
|
77
85
|
const handleKeydown = useCallback((event) => {
|
|
78
|
-
if (dropdownMenuRef.current
|
|
86
|
+
if (!dropdownMenuRef.current) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
79
90
|
event.preventDefault();
|
|
80
91
|
const target = event.target;
|
|
81
92
|
const items = [
|
|
@@ -92,35 +103,44 @@ const CDropdown = forwardRef((_a, ref) => {
|
|
|
92
103
|
handleHide();
|
|
93
104
|
dropdownToggleElement === null || dropdownToggleElement === void 0 ? void 0 : dropdownToggleElement.focus();
|
|
94
105
|
}
|
|
95
|
-
}, [autoClose, handleHide]);
|
|
96
|
-
const
|
|
106
|
+
}, [autoClose, dropdownToggleElement, handleHide]);
|
|
107
|
+
const handleClick = useCallback((event) => {
|
|
97
108
|
if (!dropdownToggleElement || !dropdownMenuRef.current) {
|
|
98
109
|
return;
|
|
99
110
|
}
|
|
100
|
-
if (
|
|
111
|
+
if (event.button === 2) {
|
|
101
112
|
return;
|
|
102
113
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
!dropdownMenuRef.current.contains(event.target))) {
|
|
108
|
-
setTimeout(() => handleHide(), 1);
|
|
114
|
+
const composedPath = event.composedPath();
|
|
115
|
+
const isOnToggle = composedPath.includes(dropdownToggleElement);
|
|
116
|
+
const isOnMenu = composedPath.includes(dropdownMenuRef.current);
|
|
117
|
+
if (isOnToggle) {
|
|
109
118
|
return;
|
|
110
119
|
}
|
|
120
|
+
const target = event.target;
|
|
121
|
+
const FORM_TAG_RE = /^(input|select|option|textarea|form|button|label)$/i;
|
|
122
|
+
if (isOnMenu && target && FORM_TAG_RE.test(target.tagName)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (autoClose === true ||
|
|
126
|
+
(autoClose === 'inside' && isOnMenu) ||
|
|
127
|
+
(autoClose === 'outside' && !isOnMenu)) {
|
|
128
|
+
handleHide();
|
|
129
|
+
}
|
|
111
130
|
}, [autoClose, dropdownToggleElement, handleHide]);
|
|
112
131
|
const handleShow = useCallback((event) => {
|
|
113
|
-
const toggleElement = dropdownToggleElement;
|
|
114
132
|
const menuElement = dropdownMenuRef.current;
|
|
115
|
-
|
|
133
|
+
const referenceElement = getReferenceElement(reference, dropdownToggleElement, dropdownRef);
|
|
134
|
+
const toggleElement = dropdownToggleElement;
|
|
135
|
+
if (menuElement && referenceElement && toggleElement) {
|
|
116
136
|
setVisible(true);
|
|
117
137
|
if (allowPopperUse) {
|
|
118
|
-
initPopper(
|
|
138
|
+
initPopper(referenceElement, menuElement, computedPopperConfig);
|
|
119
139
|
}
|
|
120
140
|
toggleElement.focus();
|
|
121
141
|
toggleElement.addEventListener('keydown', handleKeydown);
|
|
122
142
|
menuElement.addEventListener('keydown', handleKeydown);
|
|
123
|
-
window.addEventListener('
|
|
143
|
+
window.addEventListener('click', handleClick);
|
|
124
144
|
window.addEventListener('keyup', handleKeyup);
|
|
125
145
|
if (event && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
|
126
146
|
setPendingKeyDownEvent(event);
|
|
@@ -128,16 +148,17 @@ const CDropdown = forwardRef((_a, ref) => {
|
|
|
128
148
|
onShow === null || onShow === void 0 ? void 0 : onShow();
|
|
129
149
|
}
|
|
130
150
|
}, [
|
|
131
|
-
dropdownToggleElement,
|
|
132
151
|
allowPopperUse,
|
|
133
|
-
initPopper,
|
|
134
152
|
computedPopperConfig,
|
|
153
|
+
dropdownToggleElement,
|
|
154
|
+
reference,
|
|
155
|
+
handleClick,
|
|
135
156
|
handleKeydown,
|
|
136
|
-
handleMouseUp,
|
|
137
157
|
handleKeyup,
|
|
158
|
+
initPopper,
|
|
138
159
|
onShow,
|
|
139
160
|
]);
|
|
140
|
-
const contextValues = {
|
|
161
|
+
const contextValues = useMemo(() => ({
|
|
141
162
|
alignment,
|
|
142
163
|
container,
|
|
143
164
|
dark,
|
|
@@ -149,12 +170,25 @@ const CDropdown = forwardRef((_a, ref) => {
|
|
|
149
170
|
portal,
|
|
150
171
|
variant,
|
|
151
172
|
visible: _visible,
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
173
|
+
}), [
|
|
174
|
+
alignment,
|
|
175
|
+
container,
|
|
176
|
+
dark,
|
|
177
|
+
dropdownMenuRef,
|
|
178
|
+
dropdownToggleRef,
|
|
179
|
+
handleHide,
|
|
180
|
+
handleShow,
|
|
181
|
+
allowPopperUse,
|
|
182
|
+
portal,
|
|
183
|
+
variant,
|
|
184
|
+
_visible,
|
|
185
|
+
]);
|
|
186
|
+
return (React.createElement(CDropdownContext.Provider, { value: contextValues },
|
|
187
|
+
React.createElement(CFocusTrap, { active: portal && _visible, additionalContainer: dropdownMenuRef, restoreFocus: true }, variant === 'input-group' ? (React.createElement(React.Fragment, null, children)) : (React.createElement(Component, Object.assign({ className: classNames(variant === 'nav-item' ? 'nav-item dropdown' : variant, {
|
|
188
|
+
'dropdown-center': direction === 'center',
|
|
189
|
+
'dropup dropup-center': direction === 'dropup-center',
|
|
190
|
+
[`${direction}`]: direction && direction !== 'center' && direction !== 'dropup-center',
|
|
191
|
+
}, className) }, rest, { ref: forkedRef }), children)))));
|
|
158
192
|
});
|
|
159
193
|
const alignmentDirection = PropTypes.oneOf(['start', 'end']);
|
|
160
194
|
CDropdown.propTypes = {
|