Skip to content

Commit 7fa842f

Browse files
committed
feat(BTable): Fields keys now appear in the headers when the given field has no Label.
1 parent b385f87 commit 7fa842f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

packages/bootstrap-vue-3/src/components/BTable/BTable.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
:name="$slots['head(' + field.key + ')'] ? 'head(' + field.key + ')' : 'head()'"
3535
:label="field.label"
3636
/>
37-
<template v-else>{{ field.label }}</template>
37+
<template v-else>{{ getFieldHeadLabel(field) }}</template>
3838
</div>
3939
</div>
4040
</th>
@@ -125,7 +125,8 @@
125125
<script setup lang="ts">
126126
// import type {Breakpoint} from '../../types'
127127
import {computed, ref, toRef, useSlots} from 'vue'
128-
import {useBooleanish} from '../../composables'
128+
import {useBooleanish, useTitleCase} from '../../composables'
129+
129130
import type {
130131
Booleanish,
131132
ColorVariant,
@@ -241,6 +242,13 @@ const responsiveClasses = computed(() => ({
241242
[`table-responsive-${props.responsive}`]: typeof props.responsive === 'string',
242243
}))
243244
245+
const getFieldHeadLabel = (field: TableField) => {
246+
if (typeof field === 'string') return useTitleCase(field)
247+
if (field.label !== undefined) return field.label
248+
if (typeof field.key === 'string') return useTitleCase(field.key)
249+
return field.key
250+
}
251+
244252
const addSelectableCell = computed(
245253
() => selectableBoolean.value && (!!props.selectHead || slots.selectHead !== undefined)
246254
)

packages/bootstrap-vue-3/src/composables/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import useAlignment from './useAlignment'
2+
import useBooleanish from './useBooleanish'
23
import {createBreadcrumb, useBreadcrumb} from './useBreadcrumb'
34
import useEventListener from './useEventListener'
45
import {
@@ -13,8 +14,8 @@ import {
1314
} from './useFormCheck'
1415
import useFormInput, {COMMON_INPUT_PROPS} from './useFormInput'
1516
import {normalizeOptions} from './useFormSelect'
16-
import useBooleanish from './useBooleanish'
1717
import useId from './useId'
18+
import useTitleCase from './useTitleCase'
1819

1920
export {
2021
useAlignment,
@@ -23,6 +24,7 @@ export {
2324
useEventListener,
2425
bindGroupProps,
2526
useBooleanish,
27+
useTitleCase,
2628
getClasses,
2729
getGroupAttr,
2830
getGroupClasses,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {RX_LOWER_UPPER, RX_START_SPACE_WORD, RX_UNDERSCORE} from '../constants/regex'
2+
3+
export default (input: string): string => {
4+
return input
5+
.replace(RX_UNDERSCORE, ' ')
6+
.replace(RX_LOWER_UPPER, (str, $1, $2) => $1 + ' ' + $2)
7+
.replace(RX_START_SPACE_WORD, (str, $1, $2) => $1 + $2.toUpperCase())
8+
}

0 commit comments

Comments
 (0)