Skip to content

Commit 2438137

Browse files
authored
fix(b-table): set aria-sort when using sortKey and no-local-sorting (closes #6602) (#6603)
* Use field sortKey if utilized * Add test
1 parent 7d62956 commit 2438137

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,19 @@ export const sortingMixin = Vue.extend({
235235
}
236236
},
237237
sortTheadThAttrs(key, field, isFoot) {
238-
if (!this.isSortable || (isFoot && this.noFooterSorting)) {
238+
const { isSortable, noFooterSorting, localSortDesc, localSortBy, localSorting } = this
239+
if (!isSortable || (isFoot && noFooterSorting)) {
239240
// No attributes if not a sortable table
240241
return {}
241242
}
243+
242244
const sortable = field.sortable
245+
const sortKey = !localSorting ? field.sortKey ?? key : key
246+
243247
// Assemble the aria-sort attribute value
244248
const ariaSort =
245-
sortable && this.localSortBy === key
246-
? this.localSortDesc
249+
sortable && localSortBy === sortKey
250+
? localSortDesc
247251
? 'descending'
248252
: 'ascending'
249253
: sortable

src/components/table/table-sorting.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ describe('table > sorting', () => {
6363
expect(wrapper.emitted('sort-changed')[0][0].sortBy).toEqual('non-local')
6464
})
6565

66+
it('should set `aria-sort` when `field.sortKey` and `no-local-sorting` is used', async () => {
67+
const wrapper = mount(BTable, {
68+
propsData: {
69+
fields: [...testFields, { key: 'd', label: 'D', sortable: true, sortKey: 'non-local' }],
70+
items: testItems,
71+
noLocalSorting: true
72+
}
73+
})
74+
75+
expect(wrapper).toBeDefined()
76+
const $header = wrapper.findAll('thead > tr > th').at(3)
77+
78+
await $header.trigger('keydown.enter')
79+
expect(wrapper.emitted('sort-changed').length).toBe(1)
80+
expect(wrapper.emitted('sort-changed')[0][0].sortBy).toEqual('non-local')
81+
82+
expect($header.attributes('aria-sort')).toBe('ascending')
83+
})
84+
6685
it('should sort column descending when sortBy set and sortDesc changed, with proper attributes', async () => {
6786
const wrapper = mount(BTable, {
6887
propsData: {

0 commit comments

Comments
 (0)