Skip to content

Commit 756a7ac

Browse files
committedDec 30, 2019
- Add aria-labels to calculator buttons.
- Add status message on update of calculator display.
1 parent 11acc71 commit 756a7ac

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed
 

‎src/javascripts/calculator.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Calculator
6969
@updateCurrentExpressionWithCommand @math.commands.build_negate_last()
7070

7171
additionClick: ->
72-
console.log "okay"
7372
if @typeLastPressed == "exponent" || @typeLastPressed == "lparen"
7473
return
7574
@typeLastPressed = "addition"
@@ -196,6 +195,7 @@ class CalculatorView
196195
disp = @element.find("figure.jc--display")
197196
disp.html(content)
198197
disp.scrollLeft(9999999)
198+
$('#statusMessageContent').html(content)
199199

200200
render: ->
201201
@element.append "<div class='#{calculator_wrapper_class}'></div>"

‎src/javascripts/math_buttons.coffee

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,73 +11,84 @@ class ButtonBuilder
1111
@button({
1212
value: "#{num}"
1313
class: "jc--button jc--button-number"
14+
ariaLabel: "#{num}"
1415
}, opts)
1516

1617
decimal: (opts)->
1718
@button({
1819
value: "."
19-
class: "jc--button jc--button-decimal decimalButton"
20+
class: "jc--button jc--button-decimal"
21+
ariaLabel: "Decimal Separator"
2022
}, opts)
2123

2224
negative: (opts)->
2325
@button({
2426
value: "negative"
2527
label: "(&#x2013;)"
2628
class: "jc--button jc--button-negative"
29+
ariaLabel: "Negative"
2730
}, opts)
2831

2932
# Operations
3033
addition: (opts)->
3134
@button({
3235
value: "+"
33-
class: "jc--button jc--button-operation jc--button-add addButton"
36+
class: "jc--button jc--button-operation jc--button-add"
37+
ariaLabel: "Plus"
3438
}, opts)
3539

3640
subtraction: (opts)->
3741
@button({
3842
value: "-"
3943
label: "&#x2212;"
4044
class: "jc--button jc--button-operation jc--button-subtract"
45+
ariaLabel: "Minus"
4146
}, opts)
4247

4348
multiplication: (opts)->
4449
@button({
4550
value: "*"
4651
label: "&#xd7;"
4752
class: "jc--button jc--button-operation jc--button-multiply"
53+
ariaLabel: "Multiply by"
4854
}, opts)
4955

5056
division: (opts)->
5157
@button({
5258
value: "/"
5359
label: "&#xf7;"
5460
class: "jc--button jc--button-operation jc--button-divide"
61+
ariaLabel: "Divide by"
5562
}, opts)
5663

5764
equals: (opts)->
5865
@button({
5966
value: "="
60-
class: "jc--button jc--button-operation jc--button-equal equalButton"
67+
class: "jc--button jc--button-operation jc--button-equal"
68+
ariaLabel: "Equals"
6169
}, opts)
6270

6371
# Other functions
6472
lparen: (opts)->
6573
@button({
6674
value: "("
6775
class: "jc--button jc--button-other jc--button-rParen"
76+
ariaLabel: "Left parenthesis"
6877
}, opts)
6978

7079
rparen: (opts)->
7180
@button({
7281
value: ")"
7382
class: "jc--button jc--button-other jc--button-lParen"
83+
ariaLabel: "Right parenthesis"
7484
}, opts)
7585

7686
pi: (opts)->
7787
@button({
7888
value: "pi"
7989
label: "&#x3c0;"
8090
class: "jc--button jc--button-other jc--button-pi"
91+
ariaLabel: "Pi"
8192
}, opts)
8293

8394
fraction: (opts)->
@@ -91,6 +102,7 @@ class ButtonBuilder
91102
@button({
92103
value: "^"
93104
class: "jc--button jc--button-other jc--button-caret"
105+
ariaLabel: "Caret"
94106
}, opts)
95107

96108
exponent: (opts)->
@@ -100,6 +112,7 @@ class ButtonBuilder
100112
value: "exponent"
101113
label: "#{base}<sup>#{power}</sup>"
102114
class: "jc--button jc--button-other jc--button-exponent jc--button-exponent-#{base}to#{power}"
115+
ariaLabel: "Square"
103116
}, opts)
104117

105118
root: (opts)->
@@ -109,6 +122,7 @@ class ButtonBuilder
109122
value: "root"
110123
label: if degree then "<sup>#{degree}</sup>&#x221a;#{radicand}" else "&#x221a;#{radicand}"
111124
class: "jc--button jc--button-other jc--button-root jc--button-root-#{degree}of#{radicand}"
125+
ariaLabel: "Square root"
112126
}, opts)
113127

114128
# EQ builder vars
@@ -136,6 +150,7 @@ class ButtonBuilder
136150
value: "clear"
137151
label: "Clear"
138152
class: "jc--button jc--button-clear"
153+
ariaLabel: "Clear"
139154
}, opts)
140155

141156
button: (type_opts, opts)->

‎src/javascripts/ui_elements.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Button
55
render: (opts={})->
66
opts = _.extend({}, @opts, opts)
77
button = $("""
8-
<button type='button' class='#{opts.class}' value='#{opts.value}'>
8+
<button type='button' class='#{opts.class}' value='#{opts.value}' aria-label='#{opts.ariaLabel}'>
99
<span class="jc--buttonLabel">
1010
#{opts.label || opts.value}
1111
</span>

0 commit comments

Comments
 (0)
Failed to load comments.