Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d656e4

Browse filesBrowse files
committed
fix(app): querySelector errors, more defensive scroll-to-item
1 parent ae8cff2 commit 6d656e4
Copy full SHA for 6d656e4

File tree

Expand file treeCollapse file tree

1 file changed

+11
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-4
lines changed
Open diff view settings
Collapse file

‎packages/ui/src/components/list.tsx‎

Copy file name to clipboardExpand all lines: packages/ui/src/components/list.tsx
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { Icon, type IconProps } from "./icon"
66
import { IconButton } from "./icon-button"
77
import { TextField } from "./text-field"
88

9+
function findByKey(container: HTMLElement, key: string) {
10+
const nodes = container.querySelectorAll<HTMLElement>('[data-slot="list-item"][data-key]')
11+
for (const node of nodes) {
12+
if (node.getAttribute("data-key") === key) return node
13+
}
14+
}
15+
916
export interface ListSearchProps {
1017
placeholder?: string
1118
autofocus?: boolean
@@ -97,8 +104,8 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
97104
if (!props.current) return
98105
const key = props.key(props.current)
99106
requestAnimationFrame(() => {
100-
const element = scroll.querySelector(`[data-key="${CSS.escape(key)}"]`)
101-
if (!(element instanceof HTMLElement)) return
107+
const element = findByKey(scroll, key)
108+
if (!element) return
102109
scrollIntoView(scroll, element, "center")
103110
})
104111
})
@@ -114,8 +121,8 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
114121
}
115122
const key = active()
116123
if (!key) return
117-
const element = scroll.querySelector(`[data-key="${CSS.escape(key)}"]`)
118-
if (!(element instanceof HTMLElement)) return
124+
const element = findByKey(scroll, key)
125+
if (!element) return
119126
scrollIntoView(scroll, element, "center")
120127
})
121128

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.