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

Allow intermediary breadcrumbs to not be links. #401

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/pages/kbreadcrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@
/>
</DocsShow>
</div>

<div>
Links to intermediary items can be disabled by omitting the <code>link</code> attribute, or making it falsey.

<DocsShow block>
<KBreadcrumbs
:items="[
{ text: 'Global Digital Library', link: { path: '#' } },
{ text: 'English' },
{ text: 'Reading ', link: { path: '#' } },
{ text: 'Level 2 ', link: { path: '#' } },
]"
/>
</DocsShow>
</div>
</DocsPageSection>

<DocsPageSection title="Placement" anchor="#placement">
Expand Down
15 changes: 11 additions & 4 deletions lib/KBreadcrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
class="breadcrumbs-dropdown-item"
>
<KRouterLink
v-if="crumb.link"
class="krouter-item"
:text="crumb.text"
:to="crumb.link"
Expand All @@ -35,6 +36,7 @@
<span class="breadcrumbs-crumb-text" dir="auto">{{ text }}</span>
</template>
</KRouterLink>
<span v-else dir="auto">{{ crumb.text }}</span>
</li>
</ol>
</div>
Expand All @@ -49,6 +51,7 @@
class="breadcrumbs-visible-item breadcrumbs-visible-item-notlast"
>
<KRouterLink
v-if="crumb.link"
:text="crumb.text"
:to="crumb.link"
dir="auto"
Expand All @@ -57,6 +60,7 @@
<span class="breadcrumbs-crumb-text">{{ text }}</span>
</template>
</KRouterLink>
<span v-else>{{ crumb.text }}</span>
</li>

<li
Expand Down Expand Up @@ -87,11 +91,12 @@
:key="index"
class="breadcrumbs-visible-item breadcrumbs-visible-item-notlast"
>
<KRouterLink :text="crumb.text" :to="crumb.link" tabindex="-1">
<KRouterLink v-if="crumb.link" :text="crumb.text" :to="crumb.link" tabindex="-1">
<template #text="{ text }">
<span class="breadcrumbs-crumb-text">{{ text }}</span>
</template>
</KRouterLink>
<span v-else>{{ crumb.text }}</span>
</li>

<li
Expand Down Expand Up @@ -143,7 +148,9 @@
/**
* An array of objects, each with a `text` attribute (String) and a
* `link` attribute (vue router link object). The `link` attribute
* of the last item in the array is optional and ignored.
* of the last item in the array is optional and ignored. The `link`
* attribute can be set to `null` which will render the breadcrumb only
* as text, regardless of its position in the breadcrumb.
*/
items: {
type: Array,
Expand All @@ -153,8 +160,8 @@
if (!crumbItems.every(crumb => Boolean(crumb.text))) {
return false;
}
// All, but the last, must have a valid router link
return crumbItems.slice(0, -1).every(crumb => validateLinkObject(crumb.link));
// If link is truthy make sure it is a valid router link
return crumbItems.every(crumb => !crumb.link || validateLinkObject(crumb.link));
},
},
/**
Expand Down