@cloud-ru/ds-tree 1.0.24 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-tree",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Иерархический список с раскрывающимися узлами, выбором (single/multiple), кастомными иконками, контекстными действиями и асинхронной подгрузкой потомков.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,12 +36,12 @@
36
36
  "classnames": "^2.5.1",
37
37
  "react-transition-state": "^2.4.0",
38
38
  "@cloud-ru/ds-button": "^1.0.4",
39
- "@cloud-ru/ds-list": "^2.2.7",
40
39
  "@cloud-ru/ds-icons": "^1.4.0",
40
+ "@cloud-ru/ds-list": "^2.2.8",
41
41
  "@cloud-ru/ds-loader": "^1.0.3",
42
- "@cloud-ru/ds-materials": "^2.0.1",
42
+ "@cloud-ru/ds-truncate-string": "^1.0.11",
43
43
  "@cloud-ru/ds-toggles": "^1.1.8",
44
- "@cloud-ru/ds-truncate-string": "^1.0.10",
44
+ "@cloud-ru/ds-materials": "^2.0.1",
45
45
  "@cloud-ru/ds-typography": "^1.0.1",
46
46
  "@cloud-ru/ds-utils": "^1.2.0"
47
47
  },
@@ -178,7 +178,14 @@ export const TreeNode = forwardRef<HTMLDivElement, TreeNodeComponentProps>(
178
178
  }
179
179
  };
180
180
 
181
- const handleBlurActions = () => {
181
+ const handleBlurActions = (event: FocusEvent<HTMLElement>) => {
182
+ const nextTarget = event.relatedTarget;
183
+
184
+ // Фокус уходит на саму строку (возврат после закрытия дроплиста) — строку не блюрим.
185
+ if (nextTarget instanceof Node && contentRef.current?.contains(nextTarget)) {
186
+ return;
187
+ }
188
+
182
189
  if (isDroplistTriggerFocused && !isDroplistOpen) {
183
190
  setFocusDroplistTrigger(false);
184
191
 
@@ -1,7 +1,7 @@
1
1
  import { Button } from '@cloud-ru/ds-button';
2
2
  import { KebabSVG } from '@cloud-ru/ds-icons/interface/system';
3
3
  import { Droplist, ItemProps } from '@cloud-ru/ds-list';
4
- import { Dispatch, KeyboardEventHandler, SetStateAction, useEffect, useRef } from 'react';
4
+ import { Dispatch, FocusEvent, KeyboardEventHandler, SetStateAction, useEffect, useRef } from 'react';
5
5
 
6
6
  import { TEST_IDS } from '../../../constants';
7
7
  import { Size, TreeNodeProps } from '../../../types';
@@ -15,7 +15,7 @@ type TreeNodeActionsProps = {
15
15
  node: Omit<TreeNodeProps, 'href'>;
16
16
  isDroplistTriggerFocused: boolean;
17
17
  focusNode(): void;
18
- onBlurActions(): void;
18
+ onBlurActions(event: FocusEvent<HTMLElement>): void;
19
19
  size: Size;
20
20
  };
21
21
 
@@ -32,6 +32,7 @@ export function TreeNodeActions({
32
32
  const droplistActions = getNodeActions(node);
33
33
 
34
34
  const localRef = useRef<HTMLButtonElement>(null);
35
+ const returnFocusTimerRef = useRef<ReturnType<typeof setTimeout>>();
35
36
 
36
37
  useEffect(() => {
37
38
  if (localRef.current && isDroplistTriggerFocused) {
@@ -39,6 +40,13 @@ export function TreeNodeActions({
39
40
  }
40
41
  }, [isDroplistTriggerFocused, localRef]);
41
42
 
43
+ useEffect(
44
+ () => () => {
45
+ clearTimeout(returnFocusTimerRef.current);
46
+ },
47
+ [],
48
+ );
49
+
42
50
  const handleKeyDown: KeyboardEventHandler<HTMLElement> = e => {
43
51
  switch (e.key) {
44
52
  case 'Tab': {
@@ -71,6 +79,8 @@ export function TreeNodeActions({
71
79
  return;
72
80
  }
73
81
  case 'ArrowUp': {
82
+ // onOpenChange уже поставил возврат фокуса на строку — здесь фокус остаётся на kebab.
83
+ clearTimeout(returnFocusTimerRef.current);
74
84
  setDroplistOpen(false);
75
85
  localRef.current?.focus();
76
86
 
@@ -99,14 +109,17 @@ export function TreeNodeActions({
99
109
  open={isDroplistOpen}
100
110
  onOpenChange={open => {
101
111
  setDroplistOpen(open);
102
- // Закрытие дроплиста (по клику в пункт, ESC, outside-click) должно
103
- // вернуть фокус на строку и снять `isDroplistTriggerFocused` —
104
- // иначе kebab остаётся в visible-hover-состоянии. Tab и ArrowLeft
105
- // уже делают это сами; для пути через `closeDroplistOnItemClick`
106
- // ресет навешиваем здесь.
107
- if (!open) {
108
- focusNode();
112
+
113
+ if (open) {
114
+ return;
109
115
  }
116
+
117
+ // Droplist возвращает фокус на триггер после onOpenChange: синхронно
118
+ // при выборе пункта и через setTimeout(0) при Escape. Возврат на строку
119
+ // ставим следующим тиком, чтобы он шёл после обоих. Tab и ArrowLeft
120
+ // фокусируют строку сами и до onOpenChange не доходят.
121
+ clearTimeout(returnFocusTimerRef.current);
122
+ returnFocusTimerRef.current = setTimeout(focusNode);
110
123
  }}
111
124
  items={droplistActions}
112
125
  closeDroplistOnItemClick