Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape " (quote) in the command item text #222

Closed
yjl9903 opened this issue Mar 2, 2024 · 0 comments · Fixed by #223
Closed

Escape " (quote) in the command item text #222

yjl9903 opened this issue Mar 2, 2024 · 0 comments · Fixed by #223

Comments

@yjl9903
Copy link
Contributor

yjl9903 commented Mar 2, 2024

The following querySelectorAll will throw error when data-value="..." string contains " (quote)

cmdk/cmdk/src/index.tsx

Lines 399 to 404 in eb4fd0f

groups
.sort((a, b) => b[1] - a[1])
.forEach((group) => {
const element = listInnerRef.current.querySelector(`${GROUP_SELECTOR}[${VALUE_ATTR}="${group[0]}"]`)
element?.parentElement.appendChild(element)
})

Maybe can encodeURI like this?

cmdk/cmdk/src/index.tsx

Lines 772 to 777 in eb4fd0f

const selectedItemId = React.useMemo(() => {
const item = context.listInnerRef.current?.querySelector(
`${ITEM_SELECTOR}[${VALUE_ATTR}="${encodeURIComponent(value)}"]`,
)
return item?.getAttribute('id')
}, [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant