@semcore/dropdown 17.0.0-prerelease.36 → 17.0.0-prerelease.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/lib/esm/AbstractDropdown.mjs +13 -22
- package/lib/esm/Dropdown.mjs +2 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -37,9 +37,8 @@ class AbstractDropdown extends Component {
|
|
|
37
37
|
this.setupObserver();
|
|
38
38
|
}
|
|
39
39
|
componentWillUnmount() {
|
|
40
|
-
var _a;
|
|
41
40
|
this.cleanupScroll();
|
|
42
|
-
|
|
41
|
+
this.scrollObserver?.disconnect();
|
|
43
42
|
}
|
|
44
43
|
get childRole() {
|
|
45
44
|
if (this.role === "listbox") {
|
|
@@ -60,12 +59,12 @@ class AbstractDropdown extends Component {
|
|
|
60
59
|
afterOpenPopper() {
|
|
61
60
|
let highlightedIndex = this.asProps.highlightedIndex ?? 0;
|
|
62
61
|
const elementProps = this.itemProps[highlightedIndex];
|
|
63
|
-
if (elementProps
|
|
62
|
+
if (elementProps?.disabled) {
|
|
64
63
|
highlightedIndex = this.itemProps.findIndex((p) => !p.disabled);
|
|
65
64
|
}
|
|
66
65
|
if (highlightedIndex === -1) return;
|
|
67
66
|
const element = this.itemRefs[highlightedIndex];
|
|
68
|
-
element
|
|
67
|
+
element?.focus();
|
|
69
68
|
if (this.role === "menu") {
|
|
70
69
|
this.handlers.highlightedIndex(highlightedIndex);
|
|
71
70
|
}
|
|
@@ -164,7 +163,7 @@ class AbstractDropdown extends Component {
|
|
|
164
163
|
this.highlightedItem = node;
|
|
165
164
|
}
|
|
166
165
|
setTimeout(() => {
|
|
167
|
-
if (node
|
|
166
|
+
if (node?.scrollIntoView) {
|
|
168
167
|
if (this.asProps.highlightedIndex !== this.prevHighlightedIndex) {
|
|
169
168
|
this.prevHighlightedIndex = this.asProps.highlightedIndex;
|
|
170
169
|
node.scrollIntoView({
|
|
@@ -190,16 +189,14 @@ class AbstractDropdown extends Component {
|
|
|
190
189
|
});
|
|
191
190
|
}
|
|
192
191
|
cleanupScroll() {
|
|
193
|
-
var _a;
|
|
194
192
|
clearTimeout(this.scrollTimeoutId);
|
|
195
193
|
if (this.highlightedItem) {
|
|
196
|
-
|
|
194
|
+
this.scrollObserver?.unobserve(this.highlightedItem);
|
|
197
195
|
}
|
|
198
196
|
this.scrollResolve = null;
|
|
199
197
|
}
|
|
200
198
|
scrollToNodeAsync(node, withAnimation = false) {
|
|
201
199
|
return new Promise((resolve) => {
|
|
202
|
-
var _a;
|
|
203
200
|
this.cleanupScroll();
|
|
204
201
|
if (!node) {
|
|
205
202
|
resolve();
|
|
@@ -211,13 +208,12 @@ class AbstractDropdown extends Component {
|
|
|
211
208
|
resolve();
|
|
212
209
|
}, 3e3);
|
|
213
210
|
this.scrollResolve = () => {
|
|
214
|
-
var _a2;
|
|
215
211
|
clearTimeout(this.scrollTimeoutId);
|
|
216
|
-
|
|
212
|
+
this.scrollObserver?.unobserve(node);
|
|
217
213
|
this.scrollResolve = null;
|
|
218
214
|
resolve();
|
|
219
215
|
};
|
|
220
|
-
|
|
216
|
+
this.scrollObserver?.observe(node);
|
|
221
217
|
requestAnimationFrame(() => {
|
|
222
218
|
node.scrollIntoView({
|
|
223
219
|
block: "nearest",
|
|
@@ -228,13 +224,12 @@ class AbstractDropdown extends Component {
|
|
|
228
224
|
});
|
|
229
225
|
}
|
|
230
226
|
getHighlightedIndex(amount) {
|
|
231
|
-
var _a;
|
|
232
227
|
const {
|
|
233
228
|
highlightedIndex,
|
|
234
229
|
itemsCount
|
|
235
230
|
} = this.asProps;
|
|
236
231
|
const itemsLastIndex = (itemsCount ?? this.itemProps.length) - 1;
|
|
237
|
-
const selectedIndex = this.itemProps.findIndex((item) => item
|
|
232
|
+
const selectedIndex = this.itemProps.findIndex((item) => item?.selected);
|
|
238
233
|
if (itemsLastIndex < 0) return -1;
|
|
239
234
|
let innerHighlightedIndex;
|
|
240
235
|
if (highlightedIndex == null) {
|
|
@@ -254,7 +249,7 @@ class AbstractDropdown extends Component {
|
|
|
254
249
|
} else if (newIndex > itemsLastIndex) {
|
|
255
250
|
newIndex = newIndex - itemsLastIndex - 1;
|
|
256
251
|
}
|
|
257
|
-
if (
|
|
252
|
+
if (this.itemProps[newIndex]?.disabled) {
|
|
258
253
|
return this.getHighlightedIndex(amount < 0 ? amount - 1 : amount + 1);
|
|
259
254
|
} else if (!this.itemProps[newIndex]) {
|
|
260
255
|
return -1;
|
|
@@ -279,8 +274,7 @@ class AbstractDropdown extends Component {
|
|
|
279
274
|
}
|
|
280
275
|
}
|
|
281
276
|
itemRef(props, index, node) {
|
|
282
|
-
|
|
283
|
-
if ((_a = node == null ? void 0 : node.getAttribute("role")) == null ? void 0 : _a.startsWith(this.childRole)) {
|
|
277
|
+
if (node?.getAttribute("role")?.startsWith(this.childRole)) {
|
|
284
278
|
this.itemRefs[index] = node;
|
|
285
279
|
this.itemProps[index] = props;
|
|
286
280
|
}
|
|
@@ -299,8 +293,7 @@ class AbstractDropdown extends Component {
|
|
|
299
293
|
}
|
|
300
294
|
}
|
|
301
295
|
handleOpenKeyDown(e) {
|
|
302
|
-
|
|
303
|
-
if (["Enter", " ", "ArrowDown", "ArrowUp"].includes(e.key) && !((_a = e.currentTarget.getAttribute("role")) == null ? void 0 : _a.startsWith(this.childRole))) {
|
|
296
|
+
if (["Enter", " ", "ArrowDown", "ArrowUp"].includes(e.key) && !e.currentTarget.getAttribute("role")?.startsWith(this.childRole)) {
|
|
304
297
|
if (this.asProps.visible !== true) {
|
|
305
298
|
if (["ArrowDown", "ArrowUp"].includes(e.key)) {
|
|
306
299
|
e.preventDefault();
|
|
@@ -320,7 +313,6 @@ class AbstractDropdown extends Component {
|
|
|
320
313
|
}
|
|
321
314
|
}
|
|
322
315
|
handleArrowKeyDown(e) {
|
|
323
|
-
var _a;
|
|
324
316
|
const amountCount = e.shiftKey ? 5 : 1;
|
|
325
317
|
const {
|
|
326
318
|
highlightedIndex,
|
|
@@ -370,7 +362,7 @@ class AbstractDropdown extends Component {
|
|
|
370
362
|
if (newHighlightedIndex !== -1) {
|
|
371
363
|
this.handlers.highlightedIndex(newHighlightedIndex, e);
|
|
372
364
|
if (this.role === "menu") {
|
|
373
|
-
|
|
365
|
+
this.itemRefs[newHighlightedIndex]?.focus();
|
|
374
366
|
}
|
|
375
367
|
}
|
|
376
368
|
}
|
|
@@ -386,12 +378,11 @@ class AbstractDropdown extends Component {
|
|
|
386
378
|
setFocus(trigger);
|
|
387
379
|
}
|
|
388
380
|
getBasicListProps() {
|
|
389
|
-
var _a;
|
|
390
381
|
const {
|
|
391
382
|
size,
|
|
392
383
|
uid
|
|
393
384
|
} = this.asProps;
|
|
394
|
-
const triggerId =
|
|
385
|
+
const triggerId = this.triggerRef.current?.id;
|
|
395
386
|
const triggerElement = triggerId ? document.getElementById(triggerId) : null;
|
|
396
387
|
return {
|
|
397
388
|
size,
|
package/lib/esm/Dropdown.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
-
import { sstyled,
|
|
4
|
-
import { Popper,
|
|
3
|
+
import { sstyled, Component, assignProps, createComponent } from "@semcore/core";
|
|
4
|
+
import { Popper, isInputTriggerTag, Box, Flex } from "@semcore/base-components";
|
|
5
5
|
import capitalizeFirstLetter from "@semcore/core/lib/utils/capitalizeFirstLetter";
|
|
6
6
|
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
7
7
|
import uniqueIDEnhancement, { useUID } from "@semcore/core/lib/utils/uniqueID";
|
|
@@ -9,7 +9,6 @@ import { hasFocusableIn } from "@semcore/core/lib/utils/use/useFocusLock";
|
|
|
9
9
|
import React from "react";
|
|
10
10
|
import { DropdownItem } from "./DropdownItem.mjs";
|
|
11
11
|
import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
|
|
12
|
-
/*!__reshadow-styles__:"./style/dropdown.shadow.css"*/
|
|
13
12
|
const style = (
|
|
14
13
|
/*__reshadow_css_start__*/
|
|
15
14
|
(sstyled.insert(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/dropdown",
|
|
3
3
|
"description": "Semrush Dropdown Component",
|
|
4
|
-
"version": "17.0.0-prerelease.
|
|
4
|
+
"version": "17.0.0-prerelease.37",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"directory": "semcore/dropdown"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@semcore/core": "17.0.0-prerelease.
|
|
26
|
-
"@semcore/
|
|
27
|
-
"@semcore/
|
|
25
|
+
"@semcore/core": "17.0.0-prerelease.37",
|
|
26
|
+
"@semcore/testing-utils": "1.0.0",
|
|
27
|
+
"@semcore/base-components": "17.0.0-prerelease.37"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "pnpm semcore-builder --source=js && pnpm vite build"
|