@headless-tree/core 0.0.0-20250717001619 → 0.0.0-20250723222210

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 CHANGED
@@ -1,11 +1,12 @@
1
1
  # @headless-tree/core
2
2
 
3
- ## 0.0.0-20250717001619
3
+ ## 0.0.0-20250723222210
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - b41e1d2: fixed a bug where ending drag without successful drop doesn't properly reset drag line (#132)
8
8
  - b413f74: Fix `aria-posinset` and `aria-level` to be 1-based indexing
9
+ - a250b3b: Fix a bug where expand from the initial keyboard focus fails when rootItemId is an empty string
9
10
 
10
11
  ## 1.2.1
11
12
 
@@ -56,8 +56,9 @@ exports.treeFeature = {
56
56
  return flatItems;
57
57
  },
58
58
  getFocusedItem: ({ tree }) => {
59
- var _a, _b;
60
- return ((_b = tree.getItemInstance((_a = tree.getState().focusedItem) !== null && _a !== void 0 ? _a : "")) !== null && _b !== void 0 ? _b : tree.getItems()[0]);
59
+ var _a;
60
+ const focusedItemId = tree.getState().focusedItem;
61
+ return ((_a = (focusedItemId !== null ? tree.getItemInstance(focusedItemId) : null)) !== null && _a !== void 0 ? _a : tree.getItems()[0]);
61
62
  },
62
63
  getRootItem: ({ tree }) => {
63
64
  const { rootItemId } = tree.getConfig();
@@ -53,8 +53,9 @@ export const treeFeature = {
53
53
  return flatItems;
54
54
  },
55
55
  getFocusedItem: ({ tree }) => {
56
- var _a, _b;
57
- return ((_b = tree.getItemInstance((_a = tree.getState().focusedItem) !== null && _a !== void 0 ? _a : "")) !== null && _b !== void 0 ? _b : tree.getItems()[0]);
56
+ var _a;
57
+ const focusedItemId = tree.getState().focusedItem;
58
+ return ((_a = (focusedItemId !== null ? tree.getItemInstance(focusedItemId) : null)) !== null && _a !== void 0 ? _a : tree.getItems()[0]);
58
59
  },
59
60
  getRootItem: ({ tree }) => {
60
61
  const { rootItemId } = tree.getConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-tree/core",
3
- "version": "0.0.0-20250717001619",
3
+ "version": "0.0.0-20250723222210",
4
4
  "main": "lib/cjs/index.js",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/esm/index.d.ts",
@@ -76,8 +76,9 @@ export const treeFeature: FeatureImplementation<any> = {
76
76
  },
77
77
 
78
78
  getFocusedItem: ({ tree }) => {
79
+ const focusedItemId = tree.getState().focusedItem;
79
80
  return (
80
- tree.getItemInstance(tree.getState().focusedItem ?? "") ??
81
+ (focusedItemId !== null ? tree.getItemInstance(focusedItemId) : null) ??
81
82
  tree.getItems()[0]
82
83
  );
83
84
  },
@@ -472,4 +472,14 @@ describe("core-feature/selections", () => {
472
472
  });
473
473
  });
474
474
  });
475
+
476
+ describe("empty rootItemId", () => {
477
+ factory.with({ rootItemId: "" }).forSuits((tree) => {
478
+ describe("focused item", () => {
479
+ it("returns correct initial focused item", () => {
480
+ expect(tree.instance.getFocusedItem().getId()).toBe("1");
481
+ });
482
+ });
483
+ });
484
+ });
475
485
  });