Skip to content

Commit 2e76c24

Browse files
mash19tangbc
authored andcommitted
Update setsize source in test
Add demo using aria Working demo for aria
1 parent b30bfc0 commit 2e76c24

File tree

5 files changed

+124
-6
lines changed

5 files changed

+124
-6
lines changed

demos/vfor-mode-with-aria/App.vue

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<template>
2+
<div class="app">
3+
<GithubCorner path="/vfor-mode" />
4+
<div class="container">
5+
<Header
6+
title="vfor-mode with wai-aria"
7+
:desciption="'Build ' + items.length.toLocaleString() + ' items.'"
8+
:startIndex="start"
9+
:onDataChange="onHeaderDataChange"
10+
></Header>
11+
<div class="main">
12+
<virtual-list class="list"
13+
role="list"
14+
:size="size"
15+
:remain="remain"
16+
:start="start"
17+
>
18+
<item
19+
v-for="(item, index) in items"
20+
v-bind:key="item.index"
21+
:index="item.index"
22+
:height="size"
23+
:info="item.info"
24+
role="list-item"
25+
:aria-posinset="item.index"
26+
:aria-setsize="setSize"
27+
/>
28+
</virtual-list>
29+
<p>
30+
Added accessibility support. Virtual list given a
31+
<a href="https://www.w3.org/TR/wai-aria-1.1/#list">role of 'list'</a>
32+
Each list item is given a role of 'list-item' and its position in the list set with
33+
the aria-posinset state. The size of the list is set with aria-setsize.
34+
Assitive techonologies should be able to report the size of the list and
35+
were in the list is currently displayed.
36+
37+
</p>
38+
</div>
39+
</div>
40+
</div>
41+
</template>
42+
43+
<script>
44+
import Item from '../common/Item.vue'
45+
import VirtualList from 'vue-virtual-scroll-list'
46+
import { countStorage, getRandomUser } from '../common/util'
47+
48+
const remain = 6
49+
const itemSize = 80
50+
const itemCount = countStorage.get()
51+
52+
let itemList = []
53+
for (let idx = 0; idx < itemCount; idx++) {
54+
itemList.push({
55+
index: idx,
56+
height: itemSize,
57+
info: getRandomUser()
58+
})
59+
}
60+
console.log('array size', itemCount);
61+
export default {
62+
name: 'app',
63+
64+
components: {
65+
'item': Item,
66+
'virtual-list': VirtualList
67+
},
68+
69+
data () {
70+
return {
71+
remain,
72+
start: 0,
73+
size: itemSize,
74+
items: itemList,
75+
setSize: itemCount
76+
}
77+
},
78+
methods: {
79+
onHeaderDataChange (type, value) {
80+
if (type === 'start') {
81+
this.start = value
82+
}
83+
},
84+
}
85+
}
86+
</script>
87+
88+
<style lang="less">
89+
@import '../common/app.less';
90+
</style>

demos/vfor-mode-with-aria/build.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demos/vfor-mode-with-aria/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>vfor-mode demo of vue-virtual-scroll-list</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0"/>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script src="build.js"></script>
11+
</body>
12+
</html>

demos/vfor-mode-with-aria/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import App from './App.vue'
2+
import createApp from '../common/createApp'
3+
4+
createApp(App)

test/aria.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getIndexList } from './util'
66
const theme = 'aria-test'
77

88
describe(theme, () => {
9-
const listCount = 1000
9+
const listCount = 100
1010
const wrapper = mount({
1111
template: `
1212
<div id="app" style="width: 300px;">
@@ -21,7 +21,7 @@ describe(theme, () => {
2121
:key="index"
2222
style="height: 40px; line-height: 40px;"
2323
role="list-item"
24-
:aria-setsize="listCount"
24+
:aria-setsize="items.length"
2525
:aria-posinset="index"
2626
>
2727
<span class="for-item-text">{{ item }}</span>
@@ -38,8 +38,7 @@ describe(theme, () => {
3838

3939
data () {
4040
return {
41-
items: getIndexList(listCount),
42-
listCount
41+
items: getIndexList(listCount)
4342
}
4443
}
4544
})
@@ -56,8 +55,8 @@ describe(theme, () => {
5655
const itemFrags = wrapper.findAll('.for-item')
5756
const allListItemsTest = itemFrags.wrappers.every((x, i) => {
5857
return x.attributes('role') === 'list-item'
59-
&& x.attributes('aria-setsize') === listCount.toString()
60-
&& x.attributes('aria-posinset') === i.toString()
58+
&& x.attributes('aria-setsize') === `${listCount}`
59+
&& x.attributes('aria-posinset') === `${i}`
6160
})
6261
expect(allListItemsTest).toBe(true)
6362
});

0 commit comments

Comments
 (0)