Skip to content

Commit 6e9fe7c

Browse files
committed
Accessibility improvements, added font styling options.
1 parent 42ab859 commit 6e9fe7c

File tree

6 files changed

+70
-46
lines changed

6 files changed

+70
-46
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export default {
4646
| title | `String` ||| The title that is displayed next to the toggle. |
4747
| activeColor | `String` | `#9FD6AE` || The color that is displayed when the toggler is active. |
4848
| darkTheme | `Boolean` | `false` || Set's dark mode to active. (note that this will not change the background like in the preview GIF) |
49-
| disabled | `Boolean` | `false` || Disables the toggler. |
49+
| disabled | `Number` | `false` || Disables the toggler. |
50+
| fontSize | `String` | `16` || Sets the font size of the text next to the toggle |
51+
| fontWeight | `Boolean` | `bold` || Sets the font weight of the text next to the toggle. |
5052
| toggled | `Boolean` | `true` || Sets the default value for the toggler. |
5153

5254
### Vue version support

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-toggle-component",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"main": "dist/vue-toggle-component.common.js",
55
"files": [
66
"dist/*"

src/components/VueToggle.vue

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
<template>
22
<section
3-
:class="{'dark': darkTheme, 'disabled': disabled}"
4-
:title="title"
5-
class="wrapper"
3+
:class="{'dark': darkTheme, 'disabled': disabled}"
4+
:title="title"
5+
class="wrapper"
66
>
77
<input
88
:id="`_${name}`"
99
v-model="toggleState"
10+
:aria-checked="toggleState"
11+
:aria-readonly="!toggleState"
1012
:disabled="disabled"
1113
:name="name"
1214
class="toggle"
15+
role="checkbox"
1316
type="checkbox"
1417
/>
1518
<label
16-
:for="name"
17-
:style="[toggleState && {'background': activeColor}]"
18-
class="toggler"
19-
@click="toggle"
19+
:for="name"
20+
:style="[toggleState && {background: activeColor}]"
21+
class="toggler"
22+
@click="toggle"
2023
/>
21-
<span class="title" @click="toggle">{{title}}</span>
24+
<span
25+
class="title"
26+
@click="toggle"
27+
:style="[{fontSize, fontWeight}]"
28+
>
29+
{{title}}
30+
</span>
2231
</section>
2332
</template>
2433

@@ -28,11 +37,13 @@ export default {
2837
2938
props: {
3039
activeColor: {type: String, default: '#9FD6AE'},
31-
darkTheme: {type: Boolean, default: false},
32-
disabled: {type: Boolean, default: false },
33-
name: {type: String, required: true},
34-
title: {type: String, required: true},
35-
toggled: {type: Boolean, default: false},
40+
darkTheme: {type: Boolean, default: false},
41+
disabled: {type: Boolean, default: false },
42+
fontSize: {type: Number, default: 16},
43+
fontWeight: {type: String, default: 'bold'},
44+
name: {type: String, required: true},
45+
title: {type: String, required: true},
46+
toggled: {type: Boolean, default: false},
3647
},
3748
3849
data() {
@@ -65,7 +76,6 @@ export default {
6576
6677
.title {
6778
display: inline-block;
68-
font-weight: 700;
6979
line-height: 2em;
7080
vertical-align: middle;
7181

vue-toggle-component/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ npm install vue-toggle-component --save
2424
#### Example
2525
```html
2626
<template>
27-
<VueToggle title="Toggle me" name="VueToggle"/>
27+
<VueToggle title="Toggle me" name="VueToggle"/>
2828
</template>
2929

3030
<script>
31-
import VueToggle from "vue-toggle-component";
31+
import VueToggle from "vue-toggle-component";
3232
33-
export default {
34-
name: 'App',
35-
components: {
36-
VueToggle
37-
}
38-
}
33+
export default {
34+
name: 'App',
35+
components: {
36+
VueToggle
37+
}
38+
}
3939
</script>
4040
```
4141

@@ -46,7 +46,9 @@ npm install vue-toggle-component --save
4646
| title | `String` ||| The title that is displayed next to the toggle. |
4747
| activeColor | `String` | `#9FD6AE` || The color that is displayed when the toggler is active. |
4848
| darkTheme | `Boolean` | `false` || Set's dark mode to active. (note that this will not change the background like in the preview GIF) |
49-
| disabled | `Boolean` | `false` || Disables the toggler. |
49+
| disabled | `Number` | `false` || Disables the toggler. |
50+
| fontSize | `String` | `16` || Sets the font size of the text next to the toggle |
51+
| fontWeight | `Boolean` | `bold` || Sets the font weight of the text next to the toggle. |
5052
| toggled | `Boolean` | `true` || Sets the default value for the toggler. |
5153

5254
### Vue version support

vue-toggle-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-toggle-component",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44

55
"main": "dist/vue-toggle-component.ssr.js",
66
"browser": "dist/vue-toggle-component.esm.js",

vue-toggle-component/src/vue-toggle-component.vue

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
<template>
22
<section
3-
:class="{'dark': darkTheme, 'disabled': disabled}"
4-
:title="title"
5-
class="wrapper"
3+
:class="{'dark': darkTheme, 'disabled': disabled}"
4+
:title="title"
5+
class="wrapper"
66
>
77
<input
8-
:id="`_${name}`"
9-
v-model="toggleState"
10-
:disabled="disabled"
11-
:name="name"
12-
class="toggle"
13-
type="checkbox"
8+
:id="`_${name}`"
9+
v-model="toggleState"
10+
:aria-checked="toggleState"
11+
:aria-readonly="!toggleState"
12+
:disabled="disabled"
13+
:name="name"
14+
class="toggle"
15+
role="checkbox"
16+
type="checkbox"
1417
/>
1518
<label
16-
:for="name"
17-
:style="[toggleState && {'background': activeColor}]"
18-
class="toggler"
19-
@click="toggle"
19+
:for="name"
20+
:style="[toggleState && {background: activeColor}]"
21+
class="toggler"
22+
@click="toggle"
2023
/>
21-
<span class="title" @click="toggle">{{title}}</span>
24+
<span
25+
class="title"
26+
@click="toggle"
27+
:style="[{fontSize, fontWeight}]"
28+
>
29+
{{title}}
30+
</span>
2231
</section>
2332
</template>
2433

@@ -28,11 +37,13 @@ export default {
2837
2938
props: {
3039
activeColor: {type: String, default: '#9FD6AE'},
31-
darkTheme: {type: Boolean, default: false},
32-
disabled: {type: Boolean, default: false },
33-
name: {type: String, required: true},
34-
title: {type: String, required: true},
35-
toggled: {type: Boolean, default: false},
40+
darkTheme: {type: Boolean, default: false},
41+
disabled: {type: Boolean, default: false },
42+
fontSize: {type: Number, default: 16},
43+
fontWeight: {type: String, default: 'bold'},
44+
name: {type: String, required: true},
45+
title: {type: String, required: true},
46+
toggled: {type: Boolean, default: false},
3647
},
3748
3849
data() {
@@ -62,7 +73,6 @@ export default {
6273
}
6374
.title {
6475
display: inline-block;
65-
font-weight: 700;
6676
line-height: 2em;
6777
vertical-align: middle;
6878
}

0 commit comments

Comments
 (0)