-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature request: add href
prop to Command.Item
#10
Comments
I don't think it's necessary. You should be able to do something like: onSelect={() => {
goto('/wherever')
}) I need to look further into the implications before determining if it's okay to just convert it into an |
Awesome. Thanks. Quick question: This way, is it "okay", in that, shouldn't something that behaves like a link be a link? Or is it still accessible just fine, regardless? Also, I know this isn't the place, but do you have an idea on how I can navigate to an external URL, with the usual blank target, 'noopener noreferrer' e.t.c using the above workaround? Doing this: Update: function navigate_to_external_page(url: string) {
command.toggle();
let link = document.createElement('a');
link.href = url;
link.target = '_blank';
link.rel = 'noopener noreferrer';
link.click();
} Is this something you would consider to be safe? Regardless, Firefox still complains, and you first need to confirm, which is a good thing, I guess, ergo my question if this is safe.
Good luck. But imo, at least on bit's side, it's nice having the option. |
I need to confirm later once I'm home, but I think the inverse may be true accessibility wise. Since 'link's should be able to be focused via tab, etc. Maybe a different aria attribute could be added to say it's a navigation item. As for external links, use window.location = 'link_here'. (https://kit.svelte.dev/docs/modules#$app-navigation-goto) |
Sure. Thanks.
That was the first place I looked. But sadly, it opens the link from the current tab. Basically replaces. But what I want is a separate tab opened. |
Does this work in place of the
|
Hey, @huntabyte
Nope. It's the same as #10 (comment). Right now, I'm settling for that hack above. If you're still considering the request, I'll leave this open. Otherwise, feel free to close it. Thanks again. |
For a workaround I would just add Slightly repetitive but allows you to use a real anchor tag w/ |
Hi, @lukeed Thanks for the suggestion. And yes, doing "cmd + click" didn't open in a new tab. I think you're super busy, but do you mind providing a snippet of how you got it to work? I tried doing that, but quickly ran into some issues, an example being that if I scroll with my keyboard, and hit "enter", it does nothing, perhaps to not having an This is how far I got. <Command.Item asChild={true}>
<a
href={route.path}
class={cn(
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50'
)}
>
<svelte:component this={route.icon} class={cn('mr-2 !h-[1.1rem] !w-[1.1rem]', route.color)} />
<span>{route.name}</span>
</a>
</Command.Item> Was very curious how you managed to do it, or if it's me who didn't understand your suggestion. Thanks for the consideration. |
I'm also interested in this. |
This is definitely a must since it would allow plenty a accessibility features, mobile features (like long press link for preview or copy in clipboard), navigation features like |
Found myself wanting this again today, and realized something I missed from Luke's comment. (Back then, I didn't know what Basically, you need to access the Something like: <Command.Item value={event.title} asChild let:action let:attrs>
<a
use:action
{...attrs}
href={`/${event.id}/${current_path}`}
on:click={() => {
selected_event = event;
close_and_refocus_trigger(ids.trigger);
}}
class={cn(
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50'
)}
>
<Icons.Archive class="mr-2 size-4 text-muted-foreground" />
{event.title}
<Icons.Check
class={cn(
'ml-auto size-4',
selected_event?.id !== event.id && 'text-transparent'
)}
/>
</a>
</Command.Item> Though, I'll point out, doing this has some weird edge cases, and I can't confirm search fully works, because I only did this inside a combo box with ≤3 items. |
Hi;
You know how over at
bits
'sDropdown Menu
you have an optional prop that when passed converts the dropdown item into an anchor tag, well, that would be awesome ifCommand.Item
had it.Currently, trying to implement a group of nav-links by wrapping
a
tags has some weird edge cases:1. The link comes first:
With this implementation:
The outcome of this is weird, UI-wise. The filtering is messed up, in that the unfiltered links are also rendered, but this time, they are put above the searched item. Take a look at this photo. All those dashes/borders are actual clickable links rendered. But at least, here when I hit
enter
, it navigates me to my desired page. At least that works.2. The Command.Item comes first:
With this implementation:
The outcome is also not as expected:
enter
, it doesn't navigate me to the link I wanted. It just fires mytoggle
function, which basically closes the dialog, but I'm stuck on the page I was on.Item
. I know I can fix this but removing it, but I wanted to emphasize that having just thehref
prop could save everyone the trouble.What do you think @huntabyte ? Does this sound like a good idea?
The text was updated successfully, but these errors were encountered: