@snack-uikit/list 0.21.5 → 0.21.6
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 +11 -0
- package/dist/cjs/components/Items/utils.js +1 -1
- package/dist/cjs/components/Lists/ListPrivate/ListPrivate.d.ts +1 -2
- package/dist/cjs/components/Lists/ListPrivate/ListPrivate.js +14 -4
- package/dist/esm/components/Items/utils.js +2 -2
- package/dist/esm/components/Lists/ListPrivate/ListPrivate.d.ts +1 -2
- package/dist/esm/components/Lists/ListPrivate/ListPrivate.js +11 -4
- package/package.json +2 -2
- package/src/components/Items/utils.ts +2 -2
- package/src/components/Lists/ListPrivate/ListPrivate.tsx +15 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.21.6 (2024-11-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-5827:** scroll to selected item into center, make it work for all cases in list/droplist ([a63d432](https://github.com/cloud-ru-tech/snack-uikit/commit/a63d432b9718f7c99638acb940d06138c03c2421))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.21.5 (2024-11-14)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -129,7 +129,7 @@ function kindFlattenItems(_ref) {
|
|
|
129
129
|
allChildIds: focusChildren,
|
|
130
130
|
disabled: (item.type === 'collapse' || item.type === 'next-list') && item.disabled,
|
|
131
131
|
type: item.type,
|
|
132
|
-
itemRef:
|
|
132
|
+
itemRef: !isGroupItem(item) ? (_b = item.itemRef) !== null && _b !== void 0 ? _b : (0, react_1.createRef)() : undefined
|
|
133
133
|
};
|
|
134
134
|
return {
|
|
135
135
|
id: itemId,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FlattenBaseItem } from '../../Items';
|
|
2
1
|
export declare const ListPrivate: import("react").ForwardRefExoticComponent<Omit<import("../types").ListProps, "items" | "hasListInFocusChain" | "pinTop" | "pinBottom"> & {
|
|
3
2
|
nested?: boolean;
|
|
4
3
|
active?: boolean;
|
|
@@ -7,7 +6,7 @@ export declare const ListPrivate: import("react").ForwardRefExoticComponent<Omit
|
|
|
7
6
|
onBlur?(e: import("react").FocusEvent<HTMLElement>): void;
|
|
8
7
|
onKeyDown?(e: import("react").KeyboardEvent<HTMLElement>): void;
|
|
9
8
|
limitedScrollHeight?: boolean;
|
|
10
|
-
searchItem?: FlattenBaseItem;
|
|
9
|
+
searchItem?: import("../../Items").FlattenBaseItem;
|
|
11
10
|
pinTop?: import("../../Items").ItemId[];
|
|
12
11
|
items: import("../../Items").ItemId[];
|
|
13
12
|
pinBottom?: import("../../Items").ItemId[];
|
|
@@ -55,18 +55,18 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
55
55
|
errorDataState,
|
|
56
56
|
dataError,
|
|
57
57
|
dataFiltered,
|
|
58
|
-
scrollToSelectedItem
|
|
58
|
+
scrollToSelectedItem = false
|
|
59
59
|
} = _a,
|
|
60
60
|
props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "searchItem", "scrollRef", "scrollContainerRef", "onScroll", "footer", "loading", "limitedScrollHeight", "untouchableScrollbars", "className", "noDataState", "noResultsState", "errorDataState", "dataError", "dataFiltered", "scrollToSelectedItem"]);
|
|
61
61
|
const {
|
|
62
62
|
size = 's',
|
|
63
|
-
flattenItems
|
|
63
|
+
flattenItems,
|
|
64
|
+
focusFlattenItems
|
|
64
65
|
} = (0, contexts_1.useNewListContext)();
|
|
65
66
|
const {
|
|
66
67
|
value,
|
|
67
68
|
isSelectionSingle
|
|
68
69
|
} = (0, contexts_1.useSelectionContext)();
|
|
69
|
-
const selectedItem = isSelectionSingle && value ? flattenItems[value] : undefined;
|
|
70
70
|
const itemsJSX = (0, Items_1.useRenderItems)(items);
|
|
71
71
|
const itemsPinTopJSX = (0, Items_1.useRenderItems)(pinTop);
|
|
72
72
|
const itemsPinBottomJSX = (0, Items_1.useRenderItems)(pinBottom);
|
|
@@ -100,7 +100,17 @@ exports.ListPrivate = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
100
100
|
const onScrollInitialized = () => {
|
|
101
101
|
var _a, _b;
|
|
102
102
|
if (scrollToSelectedItem) {
|
|
103
|
-
|
|
103
|
+
if (!value) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
107
|
+
if (!(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const itemToScrollTo = Object.values(focusFlattenItems).find(item => item.originalId === selectedItem.id);
|
|
111
|
+
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({
|
|
112
|
+
block: 'center'
|
|
113
|
+
});
|
|
104
114
|
}
|
|
105
115
|
};
|
|
106
116
|
const listJSX = (0, jsx_runtime_1.jsxs)("ul", Object.assign({
|
|
@@ -60,7 +60,7 @@ export function kindFlattenItems({ items, prefix, parentId }) {
|
|
|
60
60
|
const closeChildIds = [];
|
|
61
61
|
const autoChildIds = [];
|
|
62
62
|
const { items } = item, rest = __rest(item, ["items"]);
|
|
63
|
-
const childActiveParent = isGroupItem(item) ? parentId !== null && parentId !== void 0 ? parentId : ITEM_PREFIXES.default : autoId;
|
|
63
|
+
const childActiveParent = isGroupItem(item) ? (parentId !== null && parentId !== void 0 ? parentId : ITEM_PREFIXES.default) : autoId;
|
|
64
64
|
const filteredItems = items.filter(item => !item.hidden);
|
|
65
65
|
for (let idx = 0; idx < filteredItems.length; idx++) {
|
|
66
66
|
const { id, children, autoId, focusChildren } = flatten({
|
|
@@ -86,7 +86,7 @@ export function kindFlattenItems({ items, prefix, parentId }) {
|
|
|
86
86
|
allChildIds: focusChildren,
|
|
87
87
|
disabled: (item.type === 'collapse' || item.type === 'next-list') && item.disabled,
|
|
88
88
|
type: item.type,
|
|
89
|
-
itemRef:
|
|
89
|
+
itemRef: !isGroupItem(item) ? ((_b = item.itemRef) !== null && _b !== void 0 ? _b : createRef()) : undefined,
|
|
90
90
|
};
|
|
91
91
|
return { id: itemId, children, autoId, focusChildren };
|
|
92
92
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FlattenBaseItem } from '../../Items';
|
|
2
1
|
export declare const ListPrivate: import("react").ForwardRefExoticComponent<Omit<import("../types").ListProps, "items" | "hasListInFocusChain" | "pinTop" | "pinBottom"> & {
|
|
3
2
|
nested?: boolean;
|
|
4
3
|
active?: boolean;
|
|
@@ -7,7 +6,7 @@ export declare const ListPrivate: import("react").ForwardRefExoticComponent<Omit
|
|
|
7
6
|
onBlur?(e: import("react").FocusEvent<HTMLElement>): void;
|
|
8
7
|
onKeyDown?(e: import("react").KeyboardEvent<HTMLElement>): void;
|
|
9
8
|
limitedScrollHeight?: boolean;
|
|
10
|
-
searchItem?: FlattenBaseItem;
|
|
9
|
+
searchItem?: import("../../Items").FlattenBaseItem;
|
|
11
10
|
pinTop?: import("../../Items").ItemId[];
|
|
12
11
|
items: import("../../Items").ItemId[];
|
|
13
12
|
pinBottom?: import("../../Items").ItemId[];
|
|
@@ -21,10 +21,9 @@ import { useNewListContext, useSelectionContext } from '../contexts';
|
|
|
21
21
|
import commonStyles from '../styles.module.css';
|
|
22
22
|
import styles from './styles.module.css';
|
|
23
23
|
export const ListPrivate = forwardRef((_a, ref) => {
|
|
24
|
-
var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, searchItem, scrollRef, scrollContainerRef, onScroll, footer, loading, limitedScrollHeight, untouchableScrollbars, className, noDataState, noResultsState, errorDataState, dataError, dataFiltered, scrollToSelectedItem } = _a, props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "searchItem", "scrollRef", "scrollContainerRef", "onScroll", "footer", "loading", "limitedScrollHeight", "untouchableScrollbars", "className", "noDataState", "noResultsState", "errorDataState", "dataError", "dataFiltered", "scrollToSelectedItem"]);
|
|
25
|
-
const { size = 's', flattenItems } = useNewListContext();
|
|
24
|
+
var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, searchItem, scrollRef, scrollContainerRef, onScroll, footer, loading, limitedScrollHeight, untouchableScrollbars, className, noDataState, noResultsState, errorDataState, dataError, dataFiltered, scrollToSelectedItem = false } = _a, props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "searchItem", "scrollRef", "scrollContainerRef", "onScroll", "footer", "loading", "limitedScrollHeight", "untouchableScrollbars", "className", "noDataState", "noResultsState", "errorDataState", "dataError", "dataFiltered", "scrollToSelectedItem"]);
|
|
25
|
+
const { size = 's', flattenItems, focusFlattenItems } = useNewListContext();
|
|
26
26
|
const { value, isSelectionSingle } = useSelectionContext();
|
|
27
|
-
const selectedItem = isSelectionSingle && value ? flattenItems[value] : undefined;
|
|
28
27
|
const itemsJSX = useRenderItems(items);
|
|
29
28
|
const itemsPinTopJSX = useRenderItems(pinTop);
|
|
30
29
|
const itemsPinBottomJSX = useRenderItems(pinBottom);
|
|
@@ -35,7 +34,15 @@ export const ListPrivate = forwardRef((_a, ref) => {
|
|
|
35
34
|
const onScrollInitialized = () => {
|
|
36
35
|
var _a, _b;
|
|
37
36
|
if (scrollToSelectedItem) {
|
|
38
|
-
|
|
37
|
+
if (!value) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
41
|
+
if (!(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const itemToScrollTo = Object.values(focusFlattenItems).find(item => item.originalId === selectedItem.id);
|
|
45
|
+
(_b = (_a = itemToScrollTo === null || itemToScrollTo === void 0 ? void 0 : itemToScrollTo.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.scrollIntoView({ block: 'center' });
|
|
39
46
|
}
|
|
40
47
|
};
|
|
41
48
|
const listJSX = (_jsxs("ul", Object.assign({ className: cn(commonStyles.listContainer, className), ref: ref, onKeyDown: onKeyDown, tabIndex: tabIndex, onFocus: onFocus, onBlur: onBlur, "data-active": active || undefined, role: 'menu' }, extractSupportProps(props), { children: [(Number(pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) > 0 || search) && (_jsxs(PinTopGroupItem, { children: [search && _jsx(SearchItem, Object.assign({ search: search }, searchItem)), Number(pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) > 0 && itemsPinTopJSX] })), scroll ? (_jsxs(Scroll, { className: cn({
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "List",
|
|
7
|
-
"version": "0.21.
|
|
7
|
+
"version": "0.21.6",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@snack-uikit/locale": "*"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "b126dc1e89fc5fc99b0e1c5f16d8dbefc370161c"
|
|
57
57
|
}
|
|
@@ -94,7 +94,7 @@ export function kindFlattenItems({ items, prefix, parentId }: KindFlattenItemsPr
|
|
|
94
94
|
const autoChildIds: ItemId[] = [];
|
|
95
95
|
|
|
96
96
|
const { items, ...rest } = item;
|
|
97
|
-
const childActiveParent = isGroupItem(item) ? parentId ?? ITEM_PREFIXES.default : autoId;
|
|
97
|
+
const childActiveParent = isGroupItem(item) ? (parentId ?? ITEM_PREFIXES.default) : autoId;
|
|
98
98
|
|
|
99
99
|
const filteredItems = items.filter(item => !item.hidden);
|
|
100
100
|
|
|
@@ -131,7 +131,7 @@ export function kindFlattenItems({ items, prefix, parentId }: KindFlattenItemsPr
|
|
|
131
131
|
allChildIds: focusChildren,
|
|
132
132
|
disabled: (item.type === 'collapse' || item.type === 'next-list') && item.disabled,
|
|
133
133
|
type: item.type,
|
|
134
|
-
itemRef:
|
|
134
|
+
itemRef: !isGroupItem(item) ? (item.itemRef ?? createRef<HTMLElement>()) : undefined,
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
return { id: itemId, children, autoId, focusChildren };
|
|
@@ -6,7 +6,7 @@ import { Scroll } from '@snack-uikit/scroll';
|
|
|
6
6
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
7
7
|
|
|
8
8
|
import { ListEmptyState, useEmptyState } from '../../../helperComponents';
|
|
9
|
-
import {
|
|
9
|
+
import { PinBottomGroupItem, PinTopGroupItem, SearchItem, useRenderItems } from '../../Items';
|
|
10
10
|
import { useNewListContext, useSelectionContext } from '../contexts';
|
|
11
11
|
import commonStyles from '../styles.module.scss';
|
|
12
12
|
import { ListPrivateProps } from '../types';
|
|
@@ -40,14 +40,13 @@ export const ListPrivate = forwardRef(
|
|
|
40
40
|
errorDataState,
|
|
41
41
|
dataError,
|
|
42
42
|
dataFiltered,
|
|
43
|
-
scrollToSelectedItem,
|
|
43
|
+
scrollToSelectedItem = false,
|
|
44
44
|
...props
|
|
45
45
|
}: ListPrivateProps,
|
|
46
46
|
ref: ForwardedRef<HTMLElement>,
|
|
47
47
|
) => {
|
|
48
|
-
const { size = 's', flattenItems } = useNewListContext();
|
|
48
|
+
const { size = 's', flattenItems, focusFlattenItems } = useNewListContext();
|
|
49
49
|
const { value, isSelectionSingle } = useSelectionContext();
|
|
50
|
-
const selectedItem = isSelectionSingle && value ? flattenItems[value] : undefined;
|
|
51
50
|
|
|
52
51
|
const itemsJSX = useRenderItems(items);
|
|
53
52
|
const itemsPinTopJSX = useRenderItems(pinTop);
|
|
@@ -93,7 +92,18 @@ export const ListPrivate = forwardRef(
|
|
|
93
92
|
|
|
94
93
|
const onScrollInitialized = () => {
|
|
95
94
|
if (scrollToSelectedItem) {
|
|
96
|
-
|
|
95
|
+
if (!value) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const selectedItem = isSelectionSingle ? flattenItems[value] : flattenItems[value[0]];
|
|
100
|
+
|
|
101
|
+
if (!selectedItem?.id) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const itemToScrollTo = Object.values(focusFlattenItems).find(item => item.originalId === selectedItem.id);
|
|
106
|
+
itemToScrollTo?.itemRef?.current?.scrollIntoView({ block: 'center' });
|
|
97
107
|
}
|
|
98
108
|
};
|
|
99
109
|
|