Skip to content

Commit

Permalink
enh(breadcrumb): conditionally renders button when no redirection lin…
Browse files Browse the repository at this point in the history
…k given

Signed-off-by: Eduardo Morales <emoral435@gmail.com>
  • Loading branch information
emoral435 committed Jan 16, 2024
1 parent 91c44a3 commit 22149cd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/NcBreadcrumb/NcBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ This component is meant to be used inside a Breadcrumbs component.
@dragover.prevent="() => {}"
@dragenter="dragEnter"
@dragleave="dragLeave">
<component :is="tag"
v-if="(name || icon) && !$slots.default"
<component v-if="(name || icon) && !$slots.default"
:is="tag"

Check warning on line 43 in src/components/NcBreadcrumb/NcBreadcrumb.vue

View workflow job for this annotation

GitHub Actions / eslint

Attribute ":is" should go before "v-if"
:title="title"
:aria-label="icon ? name : undefined"
v-bind="linkAttributes"
Expand Down Expand Up @@ -75,6 +75,7 @@ This component is meant to be used inside a Breadcrumbs component.
<script>
import NcActions from '../NcActions/index.js'
import GenRandomId from '../../utils/GenRandomId.js'
import NcButton from '../NcButton/NcButton.vue'
import ChevronRight from 'vue-material-design-icons/ChevronRight.vue'
Expand All @@ -83,6 +84,7 @@ export default {
components: {
NcActions,
ChevronRight,
NcButton,
},
inheritAttrs: false,
props: {
Expand Down Expand Up @@ -180,20 +182,24 @@ export default {
},
computed: {
/**
* Determines which element tag to use
* Determines which element tag to use, between <NcButton/>, <a/>, and <router-link/>

Check failure on line 185 in src/components/NcBreadcrumb/NcBreadcrumb.vue

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
*
* @return {string} the tag
*/
tag() {
// if neither <router-link/. or <a/>m we render a button
if (!this.to && !this.href) {
return 'NcButton'
}
return this.to ? 'router-link' : 'a'
},
/**
* The attributes to pass to `router-link` or `a`
*/
linkAttributes() {
// If it's a router-link, we pass `to` and `exact`, otherwise only `href`
return this.to ? { to: this.to, exact: this.exact, ...this.$attrs } : { href: this.href, ...this.$attrs }
// If it's a router-link, we pass `to` and `exact`, if its an a element, we pass `href`, otherwise we have a button
return this.to ? { to: this.to, exact: this.exact, ...this.$attrs } : (this.href ? { href: this.href, ...this.$attrs } : {type: 'tertiary', ...this.$attrs})

Check failure on line 202 in src/components/NcBreadcrumb/NcBreadcrumb.vue

View workflow job for this annotation

GitHub Actions / eslint

A space is required after '{'

Check failure on line 202 in src/components/NcBreadcrumb/NcBreadcrumb.vue

View workflow job for this annotation

GitHub Actions / eslint

A space is required before '}'
},
},
methods: {
Expand Down

0 comments on commit 22149cd

Please sign in to comment.