Commit a6cf9c95 authored by Rajat Jain's avatar Rajat Jain

Accept tag-name as prop in IssueCardWeight

IssueCardWeight had a hardcoded anchor tag which is not needed
in the Epic's related issues list. This change adds a functionality
to let IssueCardWeight decide which tag to render. This functionality
is backward compatible and defaults to anchor tag.
parent e5847f73
...@@ -13,12 +13,18 @@ export default { ...@@ -13,12 +13,18 @@ export default {
type: Number, type: Number,
required: true, required: true,
}, },
tagName: {
type: String,
required: false,
default: 'a',
},
}, },
}; };
</script> </script>
<template> <template>
<a <component
:is="tagName"
ref="itemWeight" ref="itemWeight"
class="board-card-info card-number board-card-weight" class="board-card-info card-number board-card-weight"
tabindex="1" tabindex="1"
...@@ -33,5 +39,5 @@ export default { ...@@ -33,5 +39,5 @@ export default {
class="js-item-weight" class="js-item-weight"
>{{ __('Weight') }}<br /><span class="text-tertiary">{{ weight }}</span> >{{ __('Weight') }}<br /><span class="text-tertiary">{{ weight }}</span>
</gl-tooltip> </gl-tooltip>
</a> </component>
</template> </template>
...@@ -103,6 +103,7 @@ export default { ...@@ -103,6 +103,7 @@ export default {
v-if="weight" v-if="weight"
:weight="weight" :weight="weight"
class="item-weight d-flex align-items-center" class="item-weight d-flex align-items-center"
tag-name="span"
/> />
</div> </div>
<issue-assignees <issue-assignees
......
...@@ -81,10 +81,10 @@ $item-weight-max-width: 48px; ...@@ -81,10 +81,10 @@ $item-weight-max-width: 48px;
.item-milestone, .item-milestone,
.item-weight { .item-weight {
cursor: help; cursor: help;
text-decoration: none;
} }
.item-milestone { .item-milestone {
text-decoration: none;
max-width: $item-milestone-max-width; max-width: $item-milestone-max-width;
} }
......
import Vue from 'vue';
import IssueCardWeight from 'ee/boards/components/issue_card_weight.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('IssueCardWeight component', () => {
let vm;
let Component;
beforeAll(() => {
Component = Vue.extend(IssueCardWeight);
});
afterEach(() => {
vm.$destroy();
});
it('renders weight', () => {
vm = mountComponent(Component, {
weight: 5,
});
expect(vm.$el.querySelector('.board-card-info-text')).toContainText('5');
});
it('renders a link when no tag is specified', () => {
vm = mountComponent(Component, {
weight: 2,
});
expect(vm.$el.querySelector('a.board-card-info')).toBeDefined();
});
it('renders the tag when it is explicitly specified', () => {
vm = mountComponent(Component, {
weight: 2,
tagName: 'span',
});
expect(vm.$el.querySelector('span.board-card-info')).toBeDefined();
expect(vm.$el.querySelector('a.board-card-info')).toBeNull();
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment