🌐 AI搜索 & 代理 主页
Skip to content

Commit b39d31c

Browse files
Payton Burdettepburdettetmorehouse
authored
feat(b-drodpown-item-button, b-drodpown-item-button): add button-class and link-class prop (#5014)
* feat(b-drodpown-item-button): add button-class prop Add the button class prop to the b-dropdown-item-button and also add a test to ensure its working as expected. * Update dropdown-item-button.js * Update package.json * Update dropdown-item.js * Update package.json * Update dropdown-item.spec.js Add new test to ensure the linkClass prop value is applied correctly to the a element. Co-authored-by: pburdette <pburdette@gitlab.com> Co-authored-by: Troy Morehouse <troymore@nbnet.nb.ca>
1 parent 4476945 commit b39d31c

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

src/components/dropdown/dropdown-item-button.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export const props = {
1010
type: String,
1111
default: 'active'
1212
},
13+
buttonClass: {
14+
type: [String, Array, Object],
15+
default: null
16+
},
1317
disabled: {
1418
type: Boolean,
1519
default: false
@@ -48,10 +52,13 @@ export const BDropdownItemButton = /*#__PURE__*/ Vue.extend({
4852
'button',
4953
{
5054
staticClass: 'dropdown-item',
51-
class: {
52-
[this.activeClass]: this.active,
53-
[`text-${this.variant}`]: this.variant && !(this.active || this.disabled)
54-
},
55+
class: [
56+
this.buttonClass,
57+
{
58+
[this.activeClass]: this.active,
59+
[`text-${this.variant}`]: this.variant && !(this.active || this.disabled)
60+
}
61+
],
5562
attrs: {
5663
...this.$attrs,
5764
role: 'menuitem',

src/components/dropdown/dropdown-item-button.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,19 @@ describe('dropdown-item-button', () => {
102102

103103
wrapper.destroy()
104104
})
105+
106+
it('has buttonClass when prop is passed a value', () => {
107+
const wrapper = mount(BDropdownItemButton, {
108+
propsData: {
109+
buttonClass: 'button-class'
110+
}
111+
})
112+
expect(wrapper.is('li')).toBe(true)
113+
114+
const button = wrapper.find('button')
115+
expect(button.classes()).toContain('button-class')
116+
expect(button.classes()).toContain('dropdown-item')
117+
118+
wrapper.destroy()
119+
})
105120
})

src/components/dropdown/dropdown-item.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export const BDropdownItem = /*#__PURE__*/ Vue.extend({
1717
},
1818
props: {
1919
...props,
20+
linkClass: {
21+
type: [String, Array, Object],
22+
default: null
23+
},
2024
variant: {
2125
type: String,
2226
default: null
@@ -43,9 +47,12 @@ export const BDropdownItem = /*#__PURE__*/ Vue.extend({
4347
{
4448
props: this.$props,
4549
staticClass: 'dropdown-item',
46-
class: {
47-
[`text-${this.variant}`]: this.variant && !(this.active || this.disabled)
48-
},
50+
class: [
51+
this.linkClass,
52+
{
53+
[`text-${this.variant}`]: this.variant && !(this.active || this.disabled)
54+
}
55+
],
4956
attrs: { ...this.$attrs, role: 'menuitem' },
5057
on: { click: this.onClick },
5158
ref: 'item'

src/components/dropdown/dropdown-item.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ describe('dropdown-item', () => {
7979
wrapper.destroy()
8080
})
8181

82+
it('has linkClass when prop is passed a value', () => {
83+
const wrapper = mount(BDropdownItem, {
84+
propsData: {
85+
linkClass: 'link-class'
86+
}
87+
})
88+
expect(wrapper.is('li')).toBe(true)
89+
90+
const item = wrapper.find('a')
91+
expect(item.classes()).toContain('link-class')
92+
expect(item.classes()).toContain('dropdown-item')
93+
94+
wrapper.destroy()
95+
})
96+
8297
describe('router-link support', () => {
8398
it('works', async () => {
8499
const localVue = new CreateLocalVue()

src/components/dropdown/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@
198198
"aliases": [
199199
"BDdItem"
200200
],
201+
"props": [
202+
{
203+
"prop": "linkClass",
204+
"version": "2.9.0",
205+
"description": "Class or classes to apply to the inner link element"
206+
}
207+
],
201208
"events": [
202209
{
203210
"event": "click",
@@ -219,6 +226,13 @@
219226
"BDdItemButton",
220227
"BDdItemBtn"
221228
],
229+
"props": [
230+
{
231+
"prop": "buttonClass",
232+
"version": "2.9.0",
233+
"description": "Class or classes to apply to the inner button element"
234+
}
235+
],
222236
"events": [
223237
{
224238
"event": "click",

0 commit comments

Comments
 (0)