Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
fix: add aria-disabled, aris-busy to listbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest committed Jun 6, 2021
1 parent 63f7631 commit 25d51b4
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cypress/integration/behavior/a11y/role/listbox/disabled.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue

const app = createApp({
name: 'app',
setup() {
const selectedOptions = null
const options = ref(['i', 'love', 'vue'])

return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
disabled
></vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions cypress/integration/behavior/a11y/role/listbox/disabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />
import path from 'path'

context('listbox', () => {
// https://www.w3.org/TR/wai-aria-1.1/#listbox

it('should set aria-busy to true when disabled options', () => {
cy.visit(path.join(__dirname, 'disabled.html'))

cy.get('[id="vs1-listbox"]').should('have.attr', 'aria-disabled', 'true')
})
})
44 changes: 44 additions & 0 deletions cypress/integration/behavior/a11y/role/listbox/loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue

const app = createApp({
name: 'app',
setup() {
const selectedOptions = null
const options = ref(['i', 'love', 'vue'])

return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
loading
></vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions cypress/integration/behavior/a11y/role/listbox/loading.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />
import path from 'path'

context('listbox', () => {
// https://www.w3.org/TR/wai-aria-1.1/#listbox

it('should set aria-busy to true when loading options', () => {
cy.visit(path.join(__dirname, 'loading.html'))

cy.get('[id="vs1-listbox"]').should('have.attr', 'aria-busy', 'true')
})
})
44 changes: 44 additions & 0 deletions cypress/integration/behavior/a11y/role/listbox/multiple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue

const app = createApp({
name: 'app',
setup() {
const selectedOptions = ref([])
const options = ref(['i', 'love', 'vue'])

return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
multiple
></vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions cypress/integration/behavior/a11y/role/listbox/mutiple.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />
import path from 'path'

context('listbox', () => {
// https://www.w3.org/TR/wai-aria-1.1/#listbox

it('should set aria-multiselectable to true when multiple options can be selected', () => {
cy.visit(path.join(__dirname, 'multiple.html'))

cy.get('[id="vs1-listbox"]').should('have.attr', 'aria-multiselectable', 'true')
})
})
2 changes: 2 additions & 0 deletions src/components/dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
role="listbox"
:id="`vs${comboboxUid}-listbox`"
:aria-multiselectable="dataAttrs['data-multiple']"
:aria-busy="dataAttrs['data-loading']"
:aria-disabled="dataAttrs['data-disabled']"
>
<template v-for="(option, index) of modelValue" :key="option.key">
<li
Expand Down
2 changes: 2 additions & 0 deletions src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ const VueSelect = {
'data-removable': optionsWithInfo.value.filter(option => option.selected).length > normalized.min,
'data-total-length': normalized.options.length,
'data-multiple': props.multiple,
'data-loading': props.loading,
'data-disabled': props.disabled,
}))
provide('dataAttrs', dataAttrs)
Expand Down

0 comments on commit 25d51b4

Please sign in to comment.