@semcore/dropdown-menu 17.0.0-prerelease.34 → 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/DropdownMenu.mjs +12 -17
- package/lib/esm/components/VirtualList.mjs +4 -7
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
package/lib/esm/DropdownMenu.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 { Flex, Box
|
|
3
|
+
import { sstyled, assignProps, lastInteraction, createComponent } from "@semcore/core";
|
|
4
|
+
import { ScrollArea, Flex, Box } from "@semcore/base-components";
|
|
5
5
|
import ButtonComponent from "@semcore/button";
|
|
6
6
|
import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
|
|
7
7
|
import { isAdvanceMode } from "@semcore/core/lib/utils/findComponent";
|
|
@@ -9,13 +9,12 @@ import { isFocusInside } from "@semcore/core/lib/utils/focus-lock/isFocusInside"
|
|
|
9
9
|
import { setFocus } from "@semcore/core/lib/utils/focus-lock/setFocus";
|
|
10
10
|
import { forkRef } from "@semcore/core/lib/utils/ref";
|
|
11
11
|
import { useUID } from "@semcore/core/lib/utils/uniqueID";
|
|
12
|
-
import Dropdown, {
|
|
12
|
+
import Dropdown, { AbstractDropdown, selectedIndexContext, enhance } from "@semcore/dropdown";
|
|
13
13
|
import { Text } from "@semcore/typography";
|
|
14
14
|
import React from "react";
|
|
15
15
|
import { ListBoxContextProvider } from "./components/Context.mjs";
|
|
16
16
|
import { VirtualList } from "./components/VirtualList.mjs";
|
|
17
17
|
import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
|
|
18
|
-
/*!__reshadow-styles__:"./style/dropdown-menu.shadow.css"*/
|
|
19
18
|
const style = (
|
|
20
19
|
/*__reshadow_css_start__*/
|
|
21
20
|
(sstyled.insert(
|
|
@@ -79,13 +78,12 @@ class DropdownMenuRoot extends AbstractDropdown {
|
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
80
|
focusAndScrollToSelected() {
|
|
82
|
-
var _a;
|
|
83
81
|
let {
|
|
84
82
|
selected,
|
|
85
83
|
options
|
|
86
84
|
} = this.menuElements;
|
|
87
85
|
const isFocusAlreadyInPopper = isFocusInside(this.popperRef.current);
|
|
88
|
-
if (!selected || !options ||
|
|
86
|
+
if (!selected || !options || this.menuRef.current?.dataset.isVirtual || isFocusAlreadyInPopper) return;
|
|
89
87
|
this.scrollToNodeAsync(selected, true).then(() => {
|
|
90
88
|
if (this.asProps.visible) {
|
|
91
89
|
selected.focus({
|
|
@@ -99,14 +97,13 @@ class DropdownMenuRoot extends AbstractDropdown {
|
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
afterOpenPopper() {
|
|
102
|
-
var _a;
|
|
103
100
|
const {
|
|
104
101
|
selected,
|
|
105
102
|
options
|
|
106
103
|
} = this.menuElements;
|
|
107
104
|
const isFocusAlreadyInPopper = isFocusInside(this.popperRef.current);
|
|
108
105
|
if (isFocusAlreadyInPopper) return;
|
|
109
|
-
if (selected && options && !
|
|
106
|
+
if (selected && options && !this.menuRef.current?.dataset.isVirtual) return;
|
|
110
107
|
super.afterOpenPopper();
|
|
111
108
|
}
|
|
112
109
|
itemRef(props, index, node) {
|
|
@@ -204,33 +201,31 @@ class DropdownMenuRoot extends AbstractDropdown {
|
|
|
204
201
|
}
|
|
205
202
|
handleKeyDownForMenu(place) {
|
|
206
203
|
return (e) => {
|
|
207
|
-
var _a, _b;
|
|
208
204
|
const {
|
|
209
205
|
visible,
|
|
210
206
|
placement,
|
|
211
207
|
inlineActions
|
|
212
208
|
} = this.asProps;
|
|
213
|
-
if (place === "list" && !
|
|
209
|
+
if (place === "list" && !this.menuRef.current?.contains(e.target) && !inlineActions) {
|
|
214
210
|
e.stopPropagation();
|
|
215
211
|
return false;
|
|
216
212
|
}
|
|
217
|
-
const show = e.key === "ArrowRight" &&
|
|
218
|
-
const hide = e.key === "ArrowLeft" &&
|
|
219
|
-
const isMenuItem =
|
|
213
|
+
const show = e.key === "ArrowRight" && placement?.startsWith("right") || e.key === "ArrowLeft" && placement?.startsWith("left") || (e.key === "Enter" || e.key === " ") && !inlineActions;
|
|
214
|
+
const hide = e.key === "ArrowLeft" && placement?.startsWith("right") || e.key === "ArrowRight" && placement?.startsWith("left") || e.key === "Escape";
|
|
215
|
+
const isMenuItem = e.target.getAttribute("role")?.startsWith(super.childRole);
|
|
220
216
|
if (place === "trigger" && show && isMenuItem) {
|
|
221
217
|
this.handlers.visible(true);
|
|
222
218
|
this.handlers.highlightedIndex(0);
|
|
223
219
|
setTimeout(() => {
|
|
224
|
-
var _a2;
|
|
225
220
|
let {
|
|
226
221
|
highlightedIndex
|
|
227
222
|
} = this.asProps;
|
|
228
223
|
const highlightedIndexProps = this.itemProps[highlightedIndex];
|
|
229
|
-
if (highlightedIndexProps
|
|
224
|
+
if (highlightedIndexProps?.disabled) {
|
|
230
225
|
highlightedIndex = this.itemProps.findIndex((p) => !p.disabled);
|
|
231
226
|
}
|
|
232
227
|
if (highlightedIndex === -1) return;
|
|
233
|
-
|
|
228
|
+
this.itemRefs[highlightedIndex]?.focus();
|
|
234
229
|
}, 0);
|
|
235
230
|
e.preventDefault();
|
|
236
231
|
e.stopPropagation();
|
|
@@ -453,7 +448,7 @@ function ItemContent({
|
|
|
453
448
|
const [describedby, setDescribedby] = React.useState(new Set(menuItemCtxValue.ariaDescribes));
|
|
454
449
|
React.useEffect(() => {
|
|
455
450
|
const element = ref.current;
|
|
456
|
-
const parent = element
|
|
451
|
+
const parent = element?.parentElement;
|
|
457
452
|
if (parent.getAttribute("aria-haspopup") === "true" && parent.getAttribute("aria-describedby")) {
|
|
458
453
|
setDescribedby((prev) => {
|
|
459
454
|
prev.add(parent.getAttribute("aria-describedby"));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import {
|
|
2
|
+
import { sstyled, Component, assignProps, createComponent } from "@semcore/core";
|
|
3
3
|
import { ScrollArea, Box } from "@semcore/base-components";
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { ListBoxContextProvider } from "./Context.mjs";
|
|
6
|
-
/*!__reshadow-styles__:"../style/dropdown-menu.shadow.css"*/
|
|
7
6
|
const style = (
|
|
8
7
|
/*__reshadow_css_start__*/
|
|
9
8
|
(sstyled.insert(
|
|
@@ -57,9 +56,8 @@ class VirtualListRoot extends Component {
|
|
|
57
56
|
rowsBuffer
|
|
58
57
|
} = this.asProps;
|
|
59
58
|
setTimeout(() => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(_b = this.containerRef.current) == null ? void 0 : _b.scrollTo({
|
|
59
|
+
const listHeight = (this.listRef.current?.getBoundingClientRect().height ?? 0) / 2;
|
|
60
|
+
this.containerRef.current?.scrollTo({
|
|
63
61
|
top: index * rowHeight - listHeight + rowHeight / 2
|
|
64
62
|
});
|
|
65
63
|
if (index <= rowsBuffer) {
|
|
@@ -68,7 +66,6 @@ class VirtualListRoot extends Component {
|
|
|
68
66
|
}, 10);
|
|
69
67
|
}
|
|
70
68
|
render() {
|
|
71
|
-
var _a;
|
|
72
69
|
var _ref = this.asProps, _ref2;
|
|
73
70
|
const SDropdownMenuList = ScrollArea;
|
|
74
71
|
const SBar = ScrollArea.Bar;
|
|
@@ -84,7 +81,7 @@ class VirtualListRoot extends Component {
|
|
|
84
81
|
renderRow: RenderRow,
|
|
85
82
|
customData
|
|
86
83
|
} = this.asProps;
|
|
87
|
-
const offsetHeight =
|
|
84
|
+
const offsetHeight = this.listRef.current?.offsetHeight ?? 0;
|
|
88
85
|
const prevPrepared = scrollDirection === "down" ? rowsBuffer / 2 : rowsBuffer;
|
|
89
86
|
const nextPrepared = scrollDirection === "up" ? rowsBuffer / 2 : rowsBuffer;
|
|
90
87
|
const startIndex = Math.max(Math.floor(scrollTop / rowHeight) - prevPrepared, 0);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/dropdown-menu",
|
|
3
3
|
"description": "Semrush DropdownMenu 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",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"types": "./lib/types/index.d.ts"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@semcore/button": "^17.0.0-prerelease.
|
|
18
|
-
"@semcore/dropdown": "^17.0.0-prerelease.
|
|
19
|
-
"@semcore/typography": "^17.0.0-prerelease.
|
|
17
|
+
"@semcore/button": "^17.0.0-prerelease.37",
|
|
18
|
+
"@semcore/dropdown": "^17.0.0-prerelease.37",
|
|
19
|
+
"@semcore/typography": "^17.0.0-prerelease.37",
|
|
20
20
|
"classnames": "2.2.6"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/classnames": "2.2.6",
|
|
33
|
-
"@semcore/
|
|
34
|
-
"@semcore/
|
|
35
|
-
"@semcore/base-trigger": "17.0.0-prerelease.34",
|
|
33
|
+
"@semcore/core": "17.0.0-prerelease.37",
|
|
34
|
+
"@semcore/base-components": "17.0.0-prerelease.37",
|
|
36
35
|
"@semcore/testing-utils": "1.0.0",
|
|
37
|
-
"@semcore/
|
|
38
|
-
"@semcore/
|
|
36
|
+
"@semcore/base-trigger": "17.0.0-prerelease.37",
|
|
37
|
+
"@semcore/button": "17.0.0-prerelease.37",
|
|
38
|
+
"@semcore/icon": "16.7.2-prerelease.37"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "pnpm semcore-builder --source=js,ts && pnpm vite build"
|