Skip to content

Commit 702a1ef

Browse files
authored
feat(b-table, b-table-lite): add prop details-td-class for applying classes to the details row <td> (#4276)
1 parent b1ba127 commit 702a1ef

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

src/components/table/helpers/mixin-tbody-row.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const detailsSlotName = 'row-details'
1010
export default {
1111
props: {
1212
tbodyTrClass: {
13-
type: [String, Array, Function],
13+
type: [String, Array, Object, Function],
14+
default: null
15+
},
16+
detailsTdClass: {
17+
type: [String, Array, Object],
1418
default: null
1519
}
1620
},
@@ -251,14 +255,15 @@ export default {
251255
}
252256

253257
// Render the details slot in a TD
254-
const $details = h(BTd, { props: { colspan: fields.length } }, [
258+
const $details = h(BTd, { props: { colspan: fields.length }, class: this.detailsTdClass }, [
255259
this.normalizeSlot(detailsSlotName, detailsScope)
256260
])
257261

258262
// Add a hidden row to keep table row striping consistent when details showing
263+
// Only added if the table is striped
259264
if (tableStriped) {
260265
$rows.push(
261-
// We don't use `BTr` here as we dont need the extra functionality
266+
// We don't use `BTr` here as we don't need the extra functionality
262267
h('tr', {
263268
key: `__b-table-details-stripe__${rowKey}`,
264269
staticClass: 'd-none',

src/components/table/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@
135135
"prop": "tbodyTrClass",
136136
"description": "CSS class (or classes) to apply to the tr element in the tbody. Can be a function that returns a class (see docs for details)"
137137
},
138+
{
139+
"prop": "detailsTdClass",
140+
"version": "2.1.0",
141+
"description": "CSS class (or classes) to apply to the td element in the details row"
142+
},
138143
{
139144
"prop": "value",
140145
"description": "Currently displayed row data. Read-only. Do not set a value on this prop"
@@ -1059,6 +1064,11 @@
10591064
"prop": "tbodyTrClass",
10601065
"description": "CSS class (or classes) to apply to the tr element in the tbody. Can be a function that returns a class (see docs for details)"
10611066
},
1067+
{
1068+
"prop": "detailsTdClass",
1069+
"version": "2.1.0",
1070+
"description": "CSS class (or classes) to apply to the td element in the details row"
1071+
},
10621072
{
10631073
"prop": "value",
10641074
"description": "Currently displayed row data. Read-only. Do not set a value on this prop"

src/components/table/table-row-details.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,45 @@ describe('table > row details', () => {
5959
wrapper.destroy()
6060
})
6161

62+
it('prop `details-td-class` works', async () => {
63+
const testItems = [
64+
{ a: 1, b: 2, c: 3, _showDetails: true },
65+
{ a: 5, b: 5, c: 6 },
66+
{ a: 7, b: 8, c: 9, _showDetails: false }
67+
]
68+
const testFields = ['a', 'b', 'c']
69+
const wrapper = mount(BTable, {
70+
propsData: {
71+
fields: testFields,
72+
items: testItems,
73+
detailsTdClass: 'foobar-class'
74+
},
75+
slots: {
76+
// Named slots get turned into scopedSlots in Vue 2.6.x
77+
'row-details': '<div>foobar</div>'
78+
}
79+
})
80+
81+
expect(wrapper).toBeDefined()
82+
expect(wrapper.find('tbody').exists()).toBe(true)
83+
const $trs = wrapper.findAll('tbody > tr')
84+
expect($trs.length).toBe(4)
85+
expect($trs.at(0).is('tr.b-table-details')).toBe(false)
86+
expect($trs.at(0).findAll('td').length).toBe(3)
87+
expect($trs.at(1).is('tr.b-table-details')).toBe(true)
88+
expect($trs.at(1).findAll('td').length).toBe(1)
89+
expect($trs.at(1).text()).toBe('foobar')
90+
const $detailsTd = $trs.at(1).find('td')
91+
expect($detailsTd.classes().length).toBe(1)
92+
expect($detailsTd.classes()).toContain('foobar-class')
93+
expect($trs.at(2).is('tr.b-table-details')).toBe(false)
94+
expect($trs.at(2).findAll('td').length).toBe(3)
95+
expect($trs.at(3).is('tr.b-table-details')).toBe(false)
96+
expect($trs.at(3).findAll('td').length).toBe(3)
97+
98+
wrapper.destroy()
99+
})
100+
62101
it('should show details slot when _showDetails changed', async () => {
63102
const testItems = [
64103
{ a: 1, b: 2, c: 3, _showDetails: true },

0 commit comments

Comments
 (0)