Skip to content

Commit b30bfc0

Browse files
mash19tangbc
authored andcommitted
correct render function to add role attribute
role 'group' add to list wrap Add unit test to aria roles and states.
1 parent 52aa306 commit b30bfc0

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@
455455
'padding-bottom': delta.paddingBottom + 'px'
456456
},
457457
'class': this.wclass,
458-
'role': 'group'
458+
attrs: {
459+
'role': 'group'
460+
}
459461
}, list)
460462
])
461463
}

test/aria.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import VirtualList from '../index'
2+
import { mount } from '@vue/test-utils'
3+
import { getIndexList } from './util'
4+
5+
// for testing base build.
6+
const theme = 'aria-test'
7+
8+
describe(theme, () => {
9+
const listCount = 1000
10+
const wrapper = mount({
11+
template: `
12+
<div id="app" style="width: 300px;">
13+
<virtual-list class="list"
14+
role="list"
15+
:size="40"
16+
:remain="6"
17+
wclass="group"
18+
>
19+
<div class="for-item"
20+
v-for="(item, index) in items"
21+
:key="index"
22+
style="height: 40px; line-height: 40px;"
23+
role="list-item"
24+
:aria-setsize="listCount"
25+
:aria-posinset="index"
26+
>
27+
<span class="for-item-text">{{ item }}</span>
28+
</div>
29+
</virtual-list>
30+
</div>
31+
`,
32+
33+
name: 'test',
34+
35+
components: {
36+
'virtual-list': VirtualList
37+
},
38+
39+
data () {
40+
return {
41+
items: getIndexList(listCount),
42+
listCount
43+
}
44+
}
45+
})
46+
47+
it('check to see if aria role "list" is set on parent', () => {
48+
const role = wrapper.find('.list').attributes('role');
49+
expect(role).toBe('list')
50+
});
51+
it('check to see if aria role "group" is set on list container', () => {
52+
const groupRole = wrapper.find('.list > .group').attributes('role')
53+
expect(groupRole).toBe('group')
54+
});
55+
it('check to see if aria roles and states are set on list items', () => {
56+
const itemFrags = wrapper.findAll('.for-item')
57+
const allListItemsTest = itemFrags.wrappers.every((x, i) => {
58+
return x.attributes('role') === 'list-item'
59+
&& x.attributes('aria-setsize') === listCount.toString()
60+
&& x.attributes('aria-posinset') === i.toString()
61+
})
62+
expect(allListItemsTest).toBe(true)
63+
});
64+
})

0 commit comments

Comments
 (0)