Skip to content

Commit 58e3ed9

Browse files
committed
feat: fix item finding story error when focusing (#403)
1 parent ee68324 commit 58e3ed9

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

packages/core/src/stories/FindingItems.stories.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
} as Meta;
1212

1313
export const CustomFinder = () => {
14-
const [search, setSearch] = useState('');
14+
const [search, setSearch] = useState('pizza');
1515
const tree = useRef<TreeRef>(null);
1616

1717
const dataProvider = useMemo(
@@ -47,12 +47,11 @@ export const CustomFinder = () => {
4747
if (search) {
4848
findItemPath(search).then(path => {
4949
if (path) {
50-
tree.current
51-
?.expandSubsequently(path.slice(0, path.length - 1))
52-
.then(() => {
53-
tree.current?.selectItems([path[path.length - 1]]);
54-
tree.current?.focusItem(path[path.length - 1]);
55-
});
50+
// wait for full path including leaf, to make sure it loaded in
51+
tree.current?.expandSubsequently(path).then(() => {
52+
tree.current?.selectItems([path[path.length - 1]]);
53+
tree.current?.focusItem(path[path.length - 1]);
54+
});
5655
}
5756
});
5857
}

packages/docs/docs/guides/search.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ function App() {
157157
if (search) {
158158
findItemPath(search).then(path => {
159159
if (path) {
160-
tree.current
161-
.expandSubsequently(path.slice(0, path.length - 1))
162-
.then(() => {
160+
// wait for full path including leaf, to make sure it loaded in
161+
tree.current?.expandSubsequently(path).then(() => {
163162
tree.current.selectItems([path[path.length - 1]]);
164163
tree.current.focusItem(path[path.length - 1]);
165164
});

0 commit comments

Comments
 (0)