fix: escape CSS selector keys to handle special characters (#9030)

This commit is contained in:
Slone 2026-01-17 19:48:38 +08:00 committed by GitHub
parent d377246491
commit 07dc8d8ce4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -69,7 +69,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
if (!props.current) return if (!props.current) return
const key = props.key(props.current) const key = props.key(props.current)
requestAnimationFrame(() => { requestAnimationFrame(() => {
const element = scrollRef()?.querySelector(`[data-key="${key}"]`) const element = scrollRef()?.querySelector(`[data-key="${CSS.escape(key)}"]`)
element?.scrollIntoView({ block: "center" }) element?.scrollIntoView({ block: "center" })
}) })
}) })
@ -81,7 +81,7 @@ export function List<T>(props: ListProps<T> & { ref?: (ref: ListRef) => void })
scrollRef()?.scrollTo(0, 0) scrollRef()?.scrollTo(0, 0)
return return
} }
const element = scrollRef()?.querySelector(`[data-key="${active()}"]`) const element = scrollRef()?.querySelector(`[data-key="${CSS.escape(active()!)}"]`)
element?.scrollIntoView({ block: "center" }) element?.scrollIntoView({ block: "center" })
}) })