Skip to content

Commit

Permalink
feat: fix item finding story error when focusing (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Aug 5, 2024
1 parent ee68324 commit 58e3ed9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 6 additions & 7 deletions packages/core/src/stories/FindingItems.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
} as Meta;

export const CustomFinder = () => {
const [search, setSearch] = useState('');
const [search, setSearch] = useState('pizza');
const tree = useRef<TreeRef>(null);

const dataProvider = useMemo(
Expand Down Expand Up @@ -47,12 +47,11 @@ export const CustomFinder = () => {
if (search) {
findItemPath(search).then(path => {
if (path) {
tree.current
?.expandSubsequently(path.slice(0, path.length - 1))
.then(() => {
tree.current?.selectItems([path[path.length - 1]]);
tree.current?.focusItem(path[path.length - 1]);
});
// wait for full path including leaf, to make sure it loaded in
tree.current?.expandSubsequently(path).then(() => {
tree.current?.selectItems([path[path.length - 1]]);
tree.current?.focusItem(path[path.length - 1]);
});
}
});
}
Expand Down
5 changes: 2 additions & 3 deletions packages/docs/docs/guides/search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ function App() {
if (search) {
findItemPath(search).then(path => {
if (path) {
tree.current
.expandSubsequently(path.slice(0, path.length - 1))
.then(() => {
// wait for full path including leaf, to make sure it loaded in
tree.current?.expandSubsequently(path).then(() => {
tree.current.selectItems([path[path.length - 1]]);
tree.current.focusItem(path[path.length - 1]);
});
Expand Down

0 comments on commit 58e3ed9

Please sign in to comment.