Skip to content
New issue

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

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

Already on GitHub? # to your account

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

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

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

yjl9903 opened this issue Mar 2, 2024 · 2 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')
}, [])

@Rinava
Copy link

Rinava commented Nov 14, 2024

This error still happens

@yjl9903
Copy link
Contributor Author

yjl9903 commented Nov 15, 2024

@Rinava Any minimal reproduction?

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

Successfully merging a pull request may close this issue.

2 participants