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

querySelector issue introduced in 0.2.1 #212

Closed
etcd opened this issue Jan 30, 2024 · 6 comments
Closed

querySelector issue introduced in 0.2.1 #212

etcd opened this issue Jan 30, 2024 · 6 comments

Comments

@etcd
Copy link

etcd commented Jan 30, 2024

The latest update v0.2.1 introduces a bug that was not present in v0.2.0. The following error is thrown when the child of a CommandItem includes a string with the quote character ("):

SyntaxError: Failed to execute 'querySelector' on 'Element': '[cmdk-item=""][data-value="""]' is not a valid selector.
@pacocoursey
Copy link
Owner

Fixed in 8aecf2d, will release soon.

@theboxer
Copy link

theboxer commented Feb 1, 2024

@pacocoursey any ETA on when the new release will be out?

@etcd
Copy link
Author

etcd commented Feb 7, 2024

@pacocoursey Sorry to bother again, but this is a major regression that was introduced in a minor version bump, so this will introduce silent runtime failures for more people (anyone who pinned the minor version) the longer a hotfix isn't deployed

@gokulkrishh
Copy link

Thanks @pacocoursey. Looking forward for the fix.

@pacocoursey
Copy link
Owner

@TylerJNewman
Copy link

Workaround for CommandItem value with quotes

By default, CommandItem uses its children as the value for search matching. If the children contain quotes, this can cause issues. You can avoid this by explicitly setting the value prop instead.

Example Implementation:

// Instead of letting it use the children (which may contain quotes):
<CommandItem>
 User "John Doe"  {/* problematic - quotes in the text */}
</CommandItem>

// Explicitly set the value prop to something without quotes:
const getOptionValue = (x: any) => x.id;

<CommandItem
 key={getOptionValue(o)}
 onSelect={() => handleSelect(o)}
 value={getOptionValue(o)} // use ID or other quote-free value for matching
>
 User "John Doe"  {/* quotes in children won't affect matching now */}
</CommandItem>

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

No branches or pull requests

5 participants