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

Breadcrumb: use custom action instead of link #1796

Open
KevinCocquyt39 opened this issue May 16, 2024 · 3 comments
Open

Breadcrumb: use custom action instead of link #1796

KevinCocquyt39 opened this issue May 16, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@KevinCocquyt39
Copy link

KevinCocquyt39 commented May 16, 2024

Description

Because of the way Nuxt routing works and how we set up our Product List Page (PLP) with searching, filtering and paging, it's not really possible to go back to the previous page after selecting a category or search term by clicking on a link within the breadcrumb.

For that, I re-created the breadcrumb keeping the styling but extending it with an "action" property.

Example: the breadcrumb looks like "HOME > CATALOG > BEER".

This is the interface where I added an optional "action" property.

export interface BreadcrumbLink {
  icon?: string | null;
  label?: string | null;
  to?: string | null;
  action?: Function | null;
}

The action is then used to clear the categoryId property and reset the pagination in our Catalog composable so our request could trigger again before showing the updated items in our PLP.

links.push({
  label: "Catalog",
  action: () => { categoryId.value = undefined; page.value = 1; },
});

This is the part in our custom breadcrumb where the action can be triggered when it was applied.

<span v-else-if="link.action" class="...">
  <span v-if="link.icon" class="... cursor-pointer" :class="link.icon" @click="link.action" />
  <span v-else class="... cursor-pointer" @click="link.action">{{ link.label }}</span>
  <span class="i-heroicons-chevron-right-20-solid ..." role="presentation" />
</span>

Could this be a valid enhancement to add to the official component?

Additional context

No response

@KevinCocquyt39 KevinCocquyt39 added the enhancement New feature or request label May 16, 2024
@KevinCocquyt39
Copy link
Author

If it is, then that's not entirely clear in the docs (https://ui.nuxt.com/components/breadcrumb#props).

@benjamincanac
Copy link
Member

Have you tried passing a click function? This component uses ULink underneath which renders a button when no to prop is passed.

@KevinCocquyt39
Copy link
Author

I might try that, although (maybe not related but a bug I should report) "custom: true" does not seem to work as it keeps on rendering a wrapper anchor tag.

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

No branches or pull requests

2 participants