Skip to content

Commit 11617b4

Browse files
authored
fix(b-table): header cell overflow for .sr-only sort label (bootstrap-vue#6371)
1 parent 7d72605 commit 11617b4

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/components/table/helpers/mixin-sorting.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ const SORT_DIRECTIONS = [SORT_DIRECTION_ASC, SORT_DIRECTION_DESC, SORT_DIRECTION
3434
// --- Props ---
3535

3636
export const props = {
37-
labelSortAsc: makeProp(PROP_TYPE_STRING, 'Click to sort Ascending'),
37+
labelSortAsc: makeProp(PROP_TYPE_STRING, 'Click to sort ascending'),
3838
labelSortClear: makeProp(PROP_TYPE_STRING, 'Click to clear sorting'),
39-
labelSortDesc: makeProp(PROP_TYPE_STRING, 'Click to sort Descending'),
39+
labelSortDesc: makeProp(PROP_TYPE_STRING, 'Click to sort descending'),
4040
noFooterSorting: makeProp(PROP_TYPE_BOOLEAN, false),
4141
noLocalSorting: makeProp(PROP_TYPE_BOOLEAN, false),
4242
// Another prop that should have had a better name
@@ -254,37 +254,38 @@ export const sortingMixin = Vue.extend({
254254
'aria-sort': ariaSort
255255
}
256256
},
257+
// A label to be placed in an `.sr-only` element in the header cell
257258
sortTheadThLabel(key, field, isFoot) {
258-
// A label to be placed in an `.sr-only` element in the header cell
259+
// No label if not a sortable table
259260
if (!this.isSortable || (isFoot && this.noFooterSorting)) {
260-
// No label if not a sortable table
261261
return null
262262
}
263-
const sortable = field.sortable
264-
// The correctness of these labels is very important for screen-reader users.
263+
const { localSortBy, localSortDesc, labelSortAsc, labelSortDesc } = this
264+
const { sortable } = field
265+
// The correctness of these labels is very important for screen reader users
265266
let labelSorting = ''
266267
if (sortable) {
267-
if (this.localSortBy === key) {
268-
// currently sorted sortable column.
269-
labelSorting = this.localSortDesc ? this.labelSortAsc : this.labelSortDesc
268+
if (localSortBy === key) {
269+
// Currently sorted sortable column
270+
labelSorting = localSortDesc ? labelSortAsc : labelSortDesc
270271
} else {
271-
// Not currently sorted sortable column.
272+
// Not currently sorted sortable column
272273
// Not using nested ternary's here for clarity/readability
273-
// Default for ariaLabel
274-
labelSorting = this.localSortDesc ? this.labelSortDesc : this.labelSortAsc
275-
// Handle sortDirection setting
274+
// Default for `aria-label`
275+
labelSorting = localSortDesc ? labelSortDesc : labelSortAsc
276+
// Handle `sortDirection` setting
276277
const sortDirection = this.sortDirection || field.sortDirection
277278
if (sortDirection === SORT_DIRECTION_ASC) {
278-
labelSorting = this.labelSortAsc
279+
labelSorting = labelSortAsc
279280
} else if (sortDirection === SORT_DIRECTION_DESC) {
280-
labelSorting = this.labelSortDesc
281+
labelSorting = labelSortDesc
281282
}
282283
}
283284
} else if (!this.noSortReset) {
284285
// Non sortable column
285-
labelSorting = this.localSortBy ? this.labelSortClear : ''
286+
labelSorting = localSortBy ? this.labelSortClear : ''
286287
}
287-
// Return the sr-only sort label or null if no label
288+
// Return the `.sr-only` sort label or `null` if no label
288289
return trim(labelSorting) || null
289290
}
290291
}

src/components/table/helpers/mixin-thead.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,15 @@ export const theadMixin = Vue.extend({
113113
const sortLabel = isSortable ? this.sortTheadThLabel(key, field, isFoot) : null
114114

115115
const data = {
116-
class: [this.fieldClasses(field), sortClass],
116+
class: [
117+
{
118+
// We need to make the header cell relative when we have
119+
// a `.sr-only` sort label to work around overflow issues
120+
'position-relative': sortLabel
121+
},
122+
this.fieldClasses(field),
123+
sortClass
124+
],
117125
props: { variant, stickyColumn },
118126
style: field.thStyle || {},
119127
attrs: {

0 commit comments

Comments
 (0)