Skip to content

Commit 476cd91

Browse files
Charlotte Spencergr2m
Charlotte Spencer
authored andcommitted
fix(slack): make the slack form accessible
A visible label has been added to the input to indicate what data the input actually takes. This is useful for both the eye, and particularly the screenreader. The ‘autofocus’ attribute has been removed from the email input, jumping to a box with no context (i.e the screenreader didn’t get a chance to read the contextual information about IRC/Slack) is not useful. A better message for when the individual is already a member of the team has been added. Styling has been added to the messaging on success/fail, with green/red success/fail states. The button `input` has been changed to `button` as HTML5 is awesome. The JavaScript was also tidied a little to make it more readable.
1 parent 9ebaf61 commit 476cd91

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

chat/index.html

+33-14
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ <h2>Send and receive the same messages on IRC and Slack.</h2>
4343

4444
<p>
4545
<form id="slack-integration">
46-
<input id="mail-for-slack" type="email" placeholder="[email protected]" autofocus="true" required />
47-
<input type="submit" id="submit-slack" value="Get your Invite" />
48-
<div class="message"></div>
46+
<label for="mail-for-slack">Enter your email address</label>
47+
<input id="mail-for-slack" type="email" placeholder="[email protected]" required>
48+
<button type="submit" id="submit-slack">Get your invite</button>
49+
<div id="slack-form-message" class="message"></div>
4950
</form>
5051
</p>
5152

@@ -64,11 +65,16 @@ <h2>These are the guidelines:</h2>
6465
<script>
6566
$(document).ready(function () {
6667
$('#slack-integration').submit(function (e) {
67-
e.preventDefault()
68-
var btn = $('#submit-slack', this)
69-
var email = $('#mail-for-slack', this)
70-
if (!email.val()) return
71-
btn.prop('disabled', true)
68+
e.preventDefault();
69+
var btn = $('#submit-slack', this),
70+
email = $('#mail-for-slack', this),
71+
formMessage = $('#slack-form-message', this);
72+
73+
if (!email.val()) {
74+
return;
75+
}
76+
77+
btn.prop('disabled', true);
7278
$.ajax({
7379
type: 'POST',
7480
url: 'https://hoodie-slack.herokuapp.com/invite',
@@ -78,17 +84,30 @@ <h2>These are the guidelines:</h2>
7884
data: JSON.stringify({ email: email.val() })
7985
})
8086
.fail(function (res) {
81-
$('#slack-integration .message').text((res.responseJSON && res.responseJSON.msg) || 'Sorry, there was a server error.');
87+
if (!res.responseJSON) {
88+
return formMessage.removeClass('message').addClass('message-fail')
89+
.text('Sorry, there was a server error.');
90+
}
91+
if (res.responseJSON.msg === 'already_in_team') {
92+
return formMessage.removeClass('message').addClass('message-fail')
93+
.text('It looks like you\'ve already joined!');
94+
}
95+
96+
formMessage.removeClass('message').addClass('message-fail')
97+
.text(res.responseJSON.msg);
8298
})
8399
.done(function (data) {
84-
email.val('')
85-
$('#slack-integration .message').text('Woot! Check your email!');
100+
email.val('');
101+
formMessage.removeClass('message')
102+
.addClass('message-done')
103+
.text('Woot! Check your email!');
86104
})
87105
.always(function () {
88-
btn.prop('disabled', false)
89-
})
90-
})
106+
btn.prop('disabled', false);
107+
});
108+
});
91109
});
110+
92111
(function(window,undefined){
93112
var d = new Date();
94113

dist1/sass/_modules.scss

+24-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ aside img { border: 0; }
185185
text-align: center;
186186
padding-bottom: rem-calc(25);
187187

188-
input {
188+
label {
189+
display: block;
190+
}
191+
192+
input, button {
189193
border: 1px solid;
190194
font-size: 1em;
191195
height: 2.2rem;
@@ -214,11 +218,30 @@ aside img { border: 0; }
214218
outline: none;
215219
background-color: #C1A7BC;
216220
border-color: #C1A7BC;
221+
color: #404040;
217222
}
218223
}
219224

220225
.message {
226+
visibility: hidden;
227+
}
228+
229+
.message-done, .message-fail {
230+
visibility: visible;
231+
width: 60%;
232+
margin: rem-calc(7) auto 0;
221233
font-weight: 400;
222234
line-height: 2;
223235
}
236+
237+
.message-fail {
238+
border: 1px solid #E8260C;
239+
background-color: #ffefef;
240+
}
241+
242+
.message-done {
243+
border: 1px solid $green;
244+
background-color: 1px solid $green-l;
245+
}
246+
224247
}

0 commit comments

Comments
 (0)