@rescui/dropdown 0.10.3 → 0.11.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/lib/dropdown.d.ts +7 -1
- package/lib/dropdown.js +39 -24
- package/lib/dropdown.p.module.css.js +12 -12
- package/lib/index.css +29 -29
- package/lib/use-scrollable-container.js +8 -22
- package/package.json +3 -2
package/lib/dropdown.d.ts
CHANGED
|
@@ -34,8 +34,14 @@ export interface DropdownProps {
|
|
|
34
34
|
closeOnEsc?: boolean;
|
|
35
35
|
closeOnTab?: boolean;
|
|
36
36
|
disableFocusLock?: boolean;
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Render dropdown inside trigger function or wrapper. May be useful when the trigger placed in the fixed layout.
|
|
39
|
+
* */
|
|
38
40
|
renderInTrigger?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Disable dropdown flip behavior. By default dropdown will flip its position if it's not fully visible.
|
|
43
|
+
* */
|
|
44
|
+
disableFlip?: boolean;
|
|
39
45
|
}
|
|
40
46
|
export interface DropdownImperativeHandle {
|
|
41
47
|
scheduleUpdate: () => void;
|
package/lib/dropdown.js
CHANGED
|
@@ -19,7 +19,8 @@ function getPopperOptions(_ref) {
|
|
|
19
19
|
maxHeight,
|
|
20
20
|
leastMaxHeight,
|
|
21
21
|
maxWidth,
|
|
22
|
-
minWidth
|
|
22
|
+
minWidth,
|
|
23
|
+
disableFlip = false
|
|
23
24
|
} = _ref;
|
|
24
25
|
return {
|
|
25
26
|
placement,
|
|
@@ -28,7 +29,7 @@ function getPopperOptions(_ref) {
|
|
|
28
29
|
enabled: false
|
|
29
30
|
}, {
|
|
30
31
|
name: 'flip',
|
|
31
|
-
enabled:
|
|
32
|
+
enabled: !disableFlip
|
|
32
33
|
}, {
|
|
33
34
|
name: 'offset',
|
|
34
35
|
enabled: true,
|
|
@@ -52,7 +53,7 @@ function getPopperOptions(_ref) {
|
|
|
52
53
|
const Portal = _ref2 => {
|
|
53
54
|
let {
|
|
54
55
|
children,
|
|
55
|
-
target
|
|
56
|
+
target
|
|
56
57
|
} = _ref2;
|
|
57
58
|
return target ? /*#__PURE__*/ReactDOM.createPortal(children, target) : null;
|
|
58
59
|
};
|
|
@@ -61,7 +62,8 @@ function useOnOutsideClick(_ref3) {
|
|
|
61
62
|
let {
|
|
62
63
|
onOutsideClick,
|
|
63
64
|
isEnabled,
|
|
64
|
-
ignoreElements = []
|
|
65
|
+
ignoreElements = [],
|
|
66
|
+
ownerDocument
|
|
65
67
|
} = _ref3;
|
|
66
68
|
const ignoreElementRefsExists = ignoreElements.length > 0 && ignoreElements.every(Boolean);
|
|
67
69
|
const handleDocumentClick = useCallback(e => {
|
|
@@ -75,21 +77,22 @@ function useOnOutsideClick(_ref3) {
|
|
|
75
77
|
}, [onOutsideClick, ...ignoreElements]); // eslint-disable-next-line consistent-return
|
|
76
78
|
|
|
77
79
|
useEffect(() => {
|
|
78
|
-
if (isEnabled && ignoreElementRefsExists) {
|
|
79
|
-
|
|
80
|
-
return () =>
|
|
80
|
+
if (isEnabled && ignoreElementRefsExists && ownerDocument) {
|
|
81
|
+
ownerDocument.addEventListener('click', handleDocumentClick, true);
|
|
82
|
+
return () => ownerDocument.removeEventListener('click', handleDocumentClick, true);
|
|
81
83
|
}
|
|
82
|
-
}, [handleDocumentClick, isEnabled,
|
|
84
|
+
}, [handleDocumentClick, ignoreElementRefsExists, isEnabled, ownerDocument]);
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
function useKeyPress(_ref4) {
|
|
86
88
|
let {
|
|
87
89
|
key,
|
|
88
90
|
onKeyPress,
|
|
89
|
-
isEnabled
|
|
91
|
+
isEnabled,
|
|
92
|
+
ownerDocument
|
|
90
93
|
} = _ref4;
|
|
91
94
|
useEffect(() => {
|
|
92
|
-
if (!isEnabled) {
|
|
95
|
+
if (!isEnabled || !ownerDocument) {
|
|
93
96
|
return;
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -100,12 +103,12 @@ function useKeyPress(_ref4) {
|
|
|
100
103
|
}
|
|
101
104
|
};
|
|
102
105
|
|
|
103
|
-
|
|
106
|
+
ownerDocument.addEventListener('keydown', keyDownHandler, true); // eslint-disable-next-line consistent-return
|
|
104
107
|
|
|
105
108
|
return () => {
|
|
106
|
-
|
|
109
|
+
ownerDocument.removeEventListener('keydown', keyDownHandler, true);
|
|
107
110
|
};
|
|
108
|
-
}, [key, onKeyPress,
|
|
111
|
+
}, [isEnabled, key, onKeyPress, ownerDocument]);
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
const THEME_STYLES = {
|
|
@@ -136,7 +139,8 @@ const DropdownRender = (_ref5, externalRef) => {
|
|
|
136
139
|
closeOnEsc = true,
|
|
137
140
|
closeOnTab = false,
|
|
138
141
|
disableFocusLock = false,
|
|
139
|
-
renderInTrigger = false
|
|
142
|
+
renderInTrigger = false,
|
|
143
|
+
disableFlip = false
|
|
140
144
|
} = _ref5;
|
|
141
145
|
const [popperRef, setPopperRef] = useState(null);
|
|
142
146
|
const [triggerRef, setTriggerRef] = useState(null);
|
|
@@ -154,20 +158,24 @@ const DropdownRender = (_ref5, externalRef) => {
|
|
|
154
158
|
setIsFirstRender(false);
|
|
155
159
|
}, []);
|
|
156
160
|
const isOpen = isFirstRender && !renderInTrigger ? false : isOpenFromProps;
|
|
161
|
+
const ownerDocument = triggerRef?.ownerDocument;
|
|
157
162
|
useOnOutsideClick({
|
|
158
163
|
isEnabled: isOpen,
|
|
159
164
|
onOutsideClick: onRequestClose,
|
|
160
|
-
ignoreElements: [popperRef, triggerRef]
|
|
165
|
+
ignoreElements: [popperRef, triggerRef],
|
|
166
|
+
ownerDocument
|
|
161
167
|
});
|
|
162
168
|
useKeyPress({
|
|
163
169
|
key: 'Escape',
|
|
164
170
|
isEnabled: isOpen && closeOnEsc,
|
|
165
|
-
onKeyPress: onRequestClose
|
|
171
|
+
onKeyPress: onRequestClose,
|
|
172
|
+
ownerDocument
|
|
166
173
|
});
|
|
167
174
|
useKeyPress({
|
|
168
175
|
key: 'Tab',
|
|
169
176
|
isEnabled: isOpen && closeOnTab,
|
|
170
|
-
onKeyPress: onRequestClose
|
|
177
|
+
onKeyPress: onRequestClose,
|
|
178
|
+
ownerDocument
|
|
171
179
|
});
|
|
172
180
|
const [handleAnimationEnd, dropdownState] = useDropdownState(isOpen, cancelCloseAnimation);
|
|
173
181
|
const {
|
|
@@ -179,7 +187,8 @@ const DropdownRender = (_ref5, externalRef) => {
|
|
|
179
187
|
maxHeight,
|
|
180
188
|
leastMaxHeight,
|
|
181
189
|
minWidth,
|
|
182
|
-
maxWidth
|
|
190
|
+
maxWidth,
|
|
191
|
+
disableFlip
|
|
183
192
|
}));
|
|
184
193
|
useImperativeHandle(externalRef, () => ({
|
|
185
194
|
scheduleUpdate: () => {
|
|
@@ -208,9 +217,12 @@ const DropdownRender = (_ref5, externalRef) => {
|
|
|
208
217
|
// But in this specific context, because of the nature of the state-ref "triggerRef",
|
|
209
218
|
// we are sure that the dropdown wouldn't be rendered on the first client render.
|
|
210
219
|
// Therefore, the first render on the client will be the same as on the server.
|
|
211
|
-
const triggerStyles = getComputedStyle(triggerRef);
|
|
212
|
-
|
|
213
|
-
|
|
220
|
+
const triggerStyles = ownerDocument?.defaultView?.getComputedStyle(triggerRef);
|
|
221
|
+
|
|
222
|
+
if (triggerStyles) {
|
|
223
|
+
themeFromCss = extractThemeFromCss(triggerStyles);
|
|
224
|
+
primaryColors = extractPrimaryColors(triggerStyles);
|
|
225
|
+
}
|
|
214
226
|
}
|
|
215
227
|
|
|
216
228
|
const {
|
|
@@ -223,7 +235,8 @@ const DropdownRender = (_ref5, externalRef) => {
|
|
|
223
235
|
|
|
224
236
|
useEffect(() => {
|
|
225
237
|
if (dropdownShouldBeRendered && scrollableRef.current) {
|
|
226
|
-
const
|
|
238
|
+
const ownerWindow = scrollableRef.current.ownerDocument.defaultView;
|
|
239
|
+
const isTransitionDisabled = ownerWindow?.getComputedStyle(scrollableRef.current).transitionDuration === '0s';
|
|
227
240
|
|
|
228
241
|
if (isTransitionDisabled) {
|
|
229
242
|
handleAnimationEnd();
|
|
@@ -231,7 +244,7 @@ const DropdownRender = (_ref5, externalRef) => {
|
|
|
231
244
|
}
|
|
232
245
|
}, [handleAnimationEnd, dropdownShouldBeRendered]);
|
|
233
246
|
return /*#__PURE__*/React.createElement(React.Fragment, null, triggerRenderer, dropdownShouldBeRendered && /*#__PURE__*/React.createElement(Portal, {
|
|
234
|
-
target: renderInTrigger ? triggerRef :
|
|
247
|
+
target: renderInTrigger ? triggerRef : ownerDocument?.body
|
|
235
248
|
}, /*#__PURE__*/React.createElement("div", {
|
|
236
249
|
ref: setPopperRef,
|
|
237
250
|
style: {
|
|
@@ -281,6 +294,8 @@ Dropdown.propTypes = {
|
|
|
281
294
|
minWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
282
295
|
maxWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
283
296
|
maxHeight: PropTypes.number,
|
|
284
|
-
leastMaxHeight: PropTypes.number
|
|
297
|
+
leastMaxHeight: PropTypes.number,
|
|
298
|
+
renderInTrigger: PropTypes.bool,
|
|
299
|
+
disableFlip: PropTypes.bool
|
|
285
300
|
};
|
|
286
301
|
export { Dropdown, Dropdown as default };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"themeLight": "
|
|
3
|
-
"themeDark": "
|
|
4
|
-
"dropdown": "
|
|
5
|
-
"triggerWrapper": "
|
|
6
|
-
"contentWrapper": "
|
|
7
|
-
"fadeInBottomToTop": "
|
|
8
|
-
"fadeInTopToBottom": "
|
|
9
|
-
"fadeInLeftToRight": "
|
|
10
|
-
"fadeInRightToLeft": "
|
|
11
|
-
"wrapperHidden": "
|
|
12
|
-
"modeClassic": "
|
|
13
|
-
"modeRock": "
|
|
2
|
+
"themeLight": "_themeLight_1ibsugm_59",
|
|
3
|
+
"themeDark": "_themeDark_1ibsugm_62",
|
|
4
|
+
"dropdown": "_dropdown_1ibsugm_66",
|
|
5
|
+
"triggerWrapper": "_triggerWrapper_1ibsugm_73",
|
|
6
|
+
"contentWrapper": "_contentWrapper_1ibsugm_77",
|
|
7
|
+
"fadeInBottomToTop": "_fadeInBottomToTop_1ibsugm_1",
|
|
8
|
+
"fadeInTopToBottom": "_fadeInTopToBottom_1ibsugm_1",
|
|
9
|
+
"fadeInLeftToRight": "_fadeInLeftToRight_1ibsugm_1",
|
|
10
|
+
"fadeInRightToLeft": "_fadeInRightToLeft_1ibsugm_1",
|
|
11
|
+
"wrapperHidden": "_wrapperHidden_1ibsugm_110",
|
|
12
|
+
"modeClassic": "_modeClassic_1ibsugm_130",
|
|
13
|
+
"modeRock": "_modeRock_1ibsugm_134"
|
|
14
14
|
};
|
|
15
15
|
export { styles as default };
|
package/lib/index.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@keyframes
|
|
1
|
+
@keyframes _fadeInTopToBottom_1ibsugm_1{
|
|
2
2
|
0%{
|
|
3
3
|
opacity:0;
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
transform:none;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
@keyframes
|
|
13
|
+
@keyframes _fadeInBottomToTop_1ibsugm_1{
|
|
14
14
|
0%{
|
|
15
15
|
opacity:0;
|
|
16
16
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
transform:none;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
@keyframes
|
|
25
|
+
@keyframes _fadeInLeftToRight_1ibsugm_1{
|
|
26
26
|
0%{
|
|
27
27
|
opacity:0;
|
|
28
28
|
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
transform:none;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
@keyframes
|
|
37
|
+
@keyframes _fadeInRightToLeft_1ibsugm_1{
|
|
38
38
|
0%{
|
|
39
39
|
opacity:0;
|
|
40
40
|
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
transform:none;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
.
|
|
49
|
+
._themeLight_1ibsugm_59{
|
|
50
50
|
--rs-theme-dark:0;
|
|
51
51
|
}
|
|
52
|
-
.
|
|
52
|
+
._themeDark_1ibsugm_62{
|
|
53
53
|
--rs-theme-dark:1;
|
|
54
54
|
}
|
|
55
|
-
.
|
|
55
|
+
._dropdown_1ibsugm_66{
|
|
56
56
|
--_rs-theme-dark:var(
|
|
57
57
|
--_rs-internal-force-theme-dark-consult-rescui-before-using,
|
|
58
58
|
var(--rs-theme-dark, 0)
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
--_rs-theme-light-coefficient:calc(1 - var(--_rs-theme-dark-coefficient));
|
|
63
63
|
}
|
|
64
64
|
@supports (color: color-mix(in srgb, #fff 50%, #000 50%)){
|
|
65
|
-
.
|
|
65
|
+
._dropdown_1ibsugm_66{
|
|
66
66
|
--_rs-color-primary:color-mix(in srgb, var(--rs-color-primary-light-theme, #6B57FF) calc(100%*var(--_rs-theme-light-coefficient, 1)), var(--rs-color-primary-dark-theme, #8473FF) calc(100%*var(--_rs-theme-dark-coefficient, 0)));
|
|
67
67
|
--_rs-color-primary-dim:color-mix(in srgb, var(--rs-color-primary-dim-light-theme, #8979ff) calc(100%*var(--_rs-theme-light-coefficient, 1)), var(--rs-color-primary-dim-dark-theme, #6f61d2) calc(100%*var(--_rs-theme-dark-coefficient, 0)));
|
|
68
68
|
--_rs-color-primary-fog:color-mix(in srgb, var(--rs-color-primary-fog-light-theme, #e1ddff) calc(100%*var(--_rs-theme-light-coefficient, 1)), var(--rs-color-primary-fog-dark-theme, #2e2b49) calc(100%*var(--_rs-theme-dark-coefficient, 0)));
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
@supports not (color: color-mix(in srgb, #fff 50%, #000 50%)){
|
|
74
|
-
.
|
|
74
|
+
._dropdown_1ibsugm_66{
|
|
75
75
|
--_rs-color-primary:rgb(calc(var(--_rs-theme-light-coefficient, 1)*107 + var(--_rs-theme-dark-coefficient, 0)*132), calc(var(--_rs-theme-light-coefficient, 1)*87 + var(--_rs-theme-dark-coefficient, 0)*115), 255);
|
|
76
76
|
--_rs-color-primary-dim:rgb(calc(var(--_rs-theme-light-coefficient, 1)*137 + var(--_rs-theme-dark-coefficient, 0)*111), calc(var(--_rs-theme-light-coefficient, 1)*121 + var(--_rs-theme-dark-coefficient, 0)*97), calc(var(--_rs-theme-light-coefficient, 1)*255 + var(--_rs-theme-dark-coefficient, 0)*210));
|
|
77
77
|
--_rs-color-primary-fog:rgb(calc(var(--_rs-theme-light-coefficient, 1)*225 + var(--_rs-theme-dark-coefficient, 0)*46), calc(var(--_rs-theme-light-coefficient, 1)*221 + var(--_rs-theme-dark-coefficient, 0)*43), calc(var(--_rs-theme-light-coefficient, 1)*255 + var(--_rs-theme-dark-coefficient, 0)*73));
|
|
@@ -79,14 +79,14 @@
|
|
|
79
79
|
--_rs-color-primary-t-fog:rgba(calc(var(--_rs-theme-light-coefficient, 1)*107 + var(--_rs-theme-dark-coefficient, 0)*132), calc(var(--_rs-theme-light-coefficient, 1)*87 + var(--_rs-theme-dark-coefficient, 0)*115), 255, calc(var(--_rs-theme-light-coefficient, 1)*0.2 + var(--_rs-theme-dark-coefficient, 0)*0.3));
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
.
|
|
82
|
+
._dropdown_1ibsugm_66 {
|
|
83
83
|
display:flex;
|
|
84
84
|
flex-direction:column;
|
|
85
85
|
}
|
|
86
|
-
.
|
|
86
|
+
._triggerWrapper_1ibsugm_73{
|
|
87
87
|
display:inline-block;
|
|
88
88
|
}
|
|
89
|
-
.
|
|
89
|
+
._contentWrapper_1ibsugm_77{
|
|
90
90
|
position:relative;
|
|
91
91
|
|
|
92
92
|
display:block;
|
|
@@ -100,40 +100,40 @@
|
|
|
100
100
|
|
|
101
101
|
transition:opacity var(--rs-transition-function, linear) 200ms, transform var(--rs-transition-function, linear) 200ms;
|
|
102
102
|
}
|
|
103
|
-
[data-popper-placement^='top'] .
|
|
104
|
-
animation:
|
|
103
|
+
[data-popper-placement^='top'] ._contentWrapper_1ibsugm_77{
|
|
104
|
+
animation:_fadeInBottomToTop_1ibsugm_1 var(--rs-transition-function, ease) 200ms;
|
|
105
105
|
}
|
|
106
|
-
[data-popper-placement^='bottom'] .
|
|
107
|
-
animation:
|
|
106
|
+
[data-popper-placement^='bottom'] ._contentWrapper_1ibsugm_77{
|
|
107
|
+
animation:_fadeInTopToBottom_1ibsugm_1 var(--rs-transition-function, ease) 200ms;
|
|
108
108
|
}
|
|
109
|
-
[data-popper-placement^='right'] .
|
|
110
|
-
animation:
|
|
109
|
+
[data-popper-placement^='right'] ._contentWrapper_1ibsugm_77{
|
|
110
|
+
animation:_fadeInLeftToRight_1ibsugm_1 var(--rs-transition-function, ease) 200ms;
|
|
111
111
|
}
|
|
112
|
-
[data-popper-placement^='left'] .
|
|
113
|
-
animation:
|
|
112
|
+
[data-popper-placement^='left'] ._contentWrapper_1ibsugm_77{
|
|
113
|
+
animation:_fadeInRightToLeft_1ibsugm_1 var(--rs-transition-function, ease) 200ms;
|
|
114
114
|
}
|
|
115
|
-
.
|
|
115
|
+
._wrapperHidden_1ibsugm_110{
|
|
116
116
|
opacity:0;
|
|
117
117
|
}
|
|
118
|
-
[data-popper-placement^='top'] .
|
|
118
|
+
[data-popper-placement^='top'] ._wrapperHidden_1ibsugm_110{
|
|
119
119
|
transform:translateY(10px);
|
|
120
120
|
}
|
|
121
|
-
[data-popper-placement^='bottom'] .
|
|
121
|
+
[data-popper-placement^='bottom'] ._wrapperHidden_1ibsugm_110{
|
|
122
122
|
transform:translateY(-10px);
|
|
123
123
|
}
|
|
124
|
-
[data-popper-placement^='right'] .
|
|
124
|
+
[data-popper-placement^='right'] ._wrapperHidden_1ibsugm_110{
|
|
125
125
|
transform:translateX(-10px);
|
|
126
126
|
}
|
|
127
|
-
[data-popper-placement^='left'] .
|
|
127
|
+
[data-popper-placement^='left'] ._wrapperHidden_1ibsugm_110{
|
|
128
128
|
transform:translateX(10px);
|
|
129
129
|
}
|
|
130
|
-
.
|
|
130
|
+
._modeClassic_1ibsugm_130 ._contentWrapper_1ibsugm_77{
|
|
131
131
|
background-color:rgb(calc(255 - var(--_rs-theme-dark-coefficient, 0)*230), calc(255 - var(--_rs-theme-dark-coefficient, 0)*230), calc(255 - var(--_rs-theme-dark-coefficient, 0)*227));
|
|
132
132
|
}
|
|
133
|
-
.
|
|
133
|
+
._modeRock_1ibsugm_134 ._contentWrapper_1ibsugm_77{
|
|
134
134
|
background-color:rgb(calc(25 + var(--_rs-theme-dark-coefficient, 0)*230), calc(25 + var(--_rs-theme-dark-coefficient, 0)*230), calc(28 + var(--_rs-theme-dark-coefficient, 0)*227));
|
|
135
135
|
}
|
|
136
|
-
.
|
|
136
|
+
._modeRock_1ibsugm_134{
|
|
137
137
|
--rs-parent-color-primary-light-theme:var(--rs-color-primary-light-theme);
|
|
138
138
|
--rs-parent-color-primary-dim-light-theme:var(
|
|
139
139
|
--rs-color-primary-dim-light-theme
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
--rs-color-primary-t-fog-dark-theme
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
|
-
.
|
|
165
|
+
._modeRock_1ibsugm_134 > *{
|
|
166
166
|
--rs-color-primary-dark-theme:var(--rs-parent-color-primary-light-theme);
|
|
167
167
|
--rs-color-primary-dim-dark-theme:var(
|
|
168
168
|
--rs-parent-color-primary-dim-light-theme
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
3
4
|
|
|
4
5
|
function isOverflown(element) {
|
|
5
6
|
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
|
|
@@ -15,28 +16,13 @@ function isOverflown(element) {
|
|
|
15
16
|
const useScrollableContainer = () => {
|
|
16
17
|
const [contentEl, setContentEl] = useState(null);
|
|
17
18
|
const [isScrollable, setIsScrollable] = useState(false);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const containerEl = contentEl.parentElement;
|
|
21
|
-
const resizeObserver = new ResizeObserver(entries => {
|
|
22
|
-
// @see https://stackoverflow.com/a/58701523
|
|
23
|
-
window.requestAnimationFrame(() => {
|
|
24
|
-
if (!Array.isArray(entries) || !entries.length) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
19
|
+
useResizeObserver(contentEl, () => {
|
|
20
|
+
const containerEl = contentEl.parentElement;
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
resizeObserver.disconnect();
|
|
34
|
-
};
|
|
35
|
-
} // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return () => {};
|
|
39
|
-
}, [contentEl]);
|
|
22
|
+
if (containerEl) {
|
|
23
|
+
setIsScrollable(isOverflown(containerEl));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
40
26
|
const scrollableStyles = {
|
|
41
27
|
overflowY: isScrollable ? 'scroll' : 'auto'
|
|
42
28
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
20
20
|
"@popperjs/core": "^2.11.8",
|
|
21
|
+
"@rescui/use-resize-observer": "^0.3.3",
|
|
21
22
|
"classnames": "^2.2.6",
|
|
22
23
|
"popper-max-size-modifier": "^0.2.0",
|
|
23
24
|
"react-focus-lock": "^2.8.1",
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"build": "rescui-scripts build"
|
|
41
42
|
},
|
|
42
43
|
"nx": {},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "7aade8fced69c4a1ac61078a1daf2c1cd4f5a1c9"
|
|
44
45
|
}
|