Skip to content

Commit d716639

Browse files
Merge pull request #16 from tylerkrupicka/accessibility
Accessibility Fixes
2 parents d964ecf + 71b03a9 commit d716639

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This package has a few major improvements over predecessors: builds, styles, and
1717

1818
The styles in this package are all scoped, with key colors still being customizable. There are no extra margins or overflow rules and text properties are all inherited from the page. This makes the view much easier to integrate anywhere you need it.
1919

20-
The default color theme is based on solarized, and font weights are modified to increase readability.
20+
The default color theme is based on solarized, and font weights are modified to increase readability. The component uses semantic HTML elements and tries to be fully keyboard accessible.
2121

2222
## Usage
2323

harness/App.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<div :class="{ dark: dark }">
3+
<div :class="{ tree: true, dark: dark }">
44
<json-view
55
:data="data"
66
rootKey="view"
@@ -96,7 +96,11 @@ export default Vue.extend({
9696
cursor: pointer;
9797
}
9898
99-
.dark {
99+
.tree {
100+
padding: 5px;
101+
}
102+
103+
.tree.dark {
100104
background-color: #121212;
101105
border-radius: 4px;
102106
}

src/JSONView.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default Vue.extend({
143143
--vjc-null-color: #6c71c4;
144144
--vjc-arrow-size: 6px;
145145
--vjc-arrow-color: #444;
146-
--vjc-hover-color: rgba(0, 0, 0, 0.15);
146+
--vjc-hover-color: rgba(0, 0, 0, 0.2);
147147
148148
margin-left: 0;
149149
width: 100%;
@@ -152,7 +152,7 @@ export default Vue.extend({
152152
.root-item.dark {
153153
--vjc-key-color: #80d8ff;
154154
--vjc-valueKey-color: #fdf6e3;
155-
--vjc-hover-color: rgba(255, 255, 255, 0.15);
155+
--vjc-hover-color: rgba(255, 255, 255, 0.2);
156156
--vjc-arrow-color: #fdf6e3;
157157
}
158158
</style>

src/JSONViewItem.vue

+31-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
<div class="json-view-item">
33
<!-- Handle Objects and Arrays-->
44
<div v-if="data.type === 'object' || data.type === 'array'">
5-
<div @click.stop="toggleOpen" class="data-key">
5+
<button
6+
@click.stop="toggleOpen"
7+
class="data-key"
8+
:aria-expanded="open ? 'true' : 'false'"
9+
>
610
<div :class="classes"></div>
711
{{ data.key }}:
812
<span class="properties">{{ lengthString }}</span>
9-
</div>
13+
</button>
1014
<json-view-item
1115
v-on:selected="bubbleSelected"
1216
v-for="child in data.children"
@@ -21,6 +25,10 @@
2125
<div
2226
:class="valueClasses"
2327
v-on:click="clickEvent(data)"
28+
@keyup.enter="clickEvent(data)"
29+
@keyup.space="clickEvent(data)"
30+
:role="canSelect ? 'button' : undefined"
31+
:tabindex="canSelect ? '0' : undefined"
2432
v-if="data.type === 'value'"
2533
>
2634
<span class="value-key">{{ data.key }}:</span>
@@ -157,10 +165,23 @@ export default Vue.extend({
157165
&:hover {
158166
background-color: rgba(0, 0, 0, 0.08);
159167
}
168+
169+
&:focus {
170+
outline: 2px solid var(--vjc-hover-color);
171+
}
160172
}
161173
}
162174
163175
.data-key {
176+
// Button overrides
177+
font-size: 100%;
178+
font-family: inherit;
179+
border: 0;
180+
padding: 0;
181+
background-color: transparent;
182+
width: 100%;
183+
184+
// Normal styles
164185
color: var(--vjc-key-color);
165186
display: flex;
166187
align-items: center;
@@ -174,6 +195,14 @@ export default Vue.extend({
174195
background-color: var(--vjc-hover-color);
175196
}
176197
198+
&:focus {
199+
outline: 2px solid var(--vjc-hover-color);
200+
}
201+
202+
&::-moz-focus-inner {
203+
border: 0;
204+
}
205+
177206
.properties {
178207
font-weight: 300;
179208
opacity: 0.9;

0 commit comments

Comments
 (0)