Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Ch1972 add accessibility check for checkbox and radio #1996

Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8d48c0b
(GH1972) fixes all eslint errors in checkbox-test in preparation for …
Jun 15, 2017
86f31db
(GH1972) fixes html lint error
Jun 15, 2017
6cd5fee
(GH1972) adds checkbox html to qunit fixture and begins structuring t…
Jun 15, 2017
859c37a
(GH1972) more cleanup of checkbox tests
Jun 16, 2017
30de167
(GH1972) cleans up checkbox qunit tests to utilize fixture, helpers, …
Jun 17, 2017
82a8723
(GH1972) cleans up remaining checkbox tests. Corrects tested checkbox…
Jun 19, 2017
6517999
(GH1972) renames return functions properly
Jun 19, 2017
8b23823
(GH1972) stubs out keyboard tests
Jun 19, 2017
42f2f14
(GH1972) removes attempt to innapropriately test browser functionality
Jun 20, 2017
2c3ae6d
(GH1972) moves keypress factory method into more shareable location
Jun 20, 2017
14e7913
(GH1972) puts back non-checkbox unit tests
Jun 20, 2017
11bbee5
(GH1972) adds check for visibility hidden|collapse and errors out if …
Jun 20, 2017
2cdcd78
Merge remote-tracking branch 'origin/master' into GH1972---checkbox-a…
Jun 20, 2017
c8a6aa9
(GH1972) makes UMD wrapper consistent across Fuel UX
Jun 20, 2017
384d28f
(GH1972) fixes eslint errors in checkbox
Jun 20, 2017
dfe29b0
(GH1972) adds line breaks to error messages in case there are more th…
Jun 20, 2017
0b97844
(GH1972) makes a11y checkbox error non-breaking
Jun 21, 2017
13769f2
(CH1972) references correct PR number from error message
Jun 21, 2017
f81f9b9
(CH1972) adds error to radio also
Jun 21, 2017
a13c5f8
(CH1972) cleans up eslint error. Moves setDisabledState closer to a f…
Jun 21, 2017
4ced2a4
(CH1972) allow options override to ignore visibility check
Jun 21, 2017
67dcc06
(CH1972) checks actual input element visibility instead of label
Jun 21, 2017
f58b649
(CH1972) adds dev tests for visibility checks
Jun 21, 2017
28a0256
(CH1972) adds unit tests for visibility error check
Jun 21, 2017
e97f9c4
(CH1972) adds unit test for ignoreVisibilityCheck option
Jun 21, 2017
deaa53e
(CH1972) fixes all eslint errors in radio unittests
Jun 21, 2017
1fced53
(CH1972) makes checkbox test both checked and unchecked change event …
Jun 21, 2017
906def4
(CH1972) cleans up radio tests. They were badly copy-pastad versions …
Jun 21, 2017
4779116
Merge branch 'master' into CH1972---add-accessibility-check-for-checkbox
Jun 27, 2017
60598f4
(CH1972) removes commented out feature
Jun 27, 2017
82424b5
Merge branch 'master' of github.com:ExactTarget/fuelux into CH1972---…
Jun 27, 2017
fe0c272
Merge branch 'CH1972---add-accessibility-check-for-checkbox' of githu…
Jun 27, 2017
3a6c720
(CH1972) places single require error checking code outside of code th…
Jun 27, 2017
eb88b1d
(CH1972) attempts to clarify skipped tests
Jun 27, 2017
871c0e8
Merge remote-tracking branch 'upstream/master' into CH1972---add-acce…
Jun 28, 2017
af3961c
(CH1972) removes incorrect markup variants
Jun 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ <h2>Checkboxes</h2>
<div class="thin-box">
<section id="checkboxes-toggling">
<div class="checkbox">
<label class="checkbox-custom" data-initialize="checkbox" id="myCustomTogglingCheckbox1">
<input type="checkbox" class="sr-only" data-toggle=".checkboxToggle" />
<label class="checkbox-custom" data-initialize="checkbox" data-ignore-visibility-check=true id="myCustomTogglingCheckbox1">
<input type="checkbox" class="sr-only" data-toggle=".checkboxToggle" style="visibility: hidden;" />
<span class="checkbox-label">Custom checkbox toggles by class</span>
</label>
</div>
<div class="checkbox">
<label class="checkbox-custom" data-initialize="checkbox" id="myCustomTogglingCheckbox2">
<input type="checkbox" class="sr-only" data-toggle="#checkboxToggle" />
<input type="checkbox" class="sr-only" data-toggle="#checkboxToggle" style="visibility: hidden;" />
<span class="checkbox-label">Custom checkbox toggles by id</span>
</label>
</div>
Expand Down Expand Up @@ -654,14 +654,14 @@ <h2>Radio Buttons</h2>
<div class="thin-box">
<!--Block-level Radios-->
<div class="radio">
<label class="radio-custom" data-initialize="radio" id="myCustomRadio1">
<input class="sr-only" name="radio1" type="radio" value="" id="radio1" />
<label class="radio-custom" data-initialize="radio" data-ignore-visibility-check=true id="myCustomRadio1">
<input class="sr-only" name="radio1" type="radio" value="" id="radio1" style="visibility: hidden;"/>
<span class="radio-label">Custom radio unchecked on page load</span>
</label>
</div>
<div class="radio">
<label class="radio-custom" data-initialize="radio" id="myCustomRadio2">
<input checked="checked" class="checked sr-only" name="radio1" type="radio" value="" id="radio2" />
<input checked="checked" class="checked sr-only" name="radio1" type="radio" value="" id="radio2" style="visibility: hidden;"/>
<span class="radio-label">Custom radio checked on page load</span>
</label>
</div>
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ define(function (require) {
window.console.log.apply(console, args);
}
};
if (window.console && window.console.clear) {
window.console.clear();
}
// if (window.console && window.console.clear) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it, if you don't want it.

// window.console.clear();
// }

// programmatically injecting this is so much easier than writing the html by hand 376 times...
$('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id], dt[id], section[id]').each(function (i) {
Expand Down
99 changes: 51 additions & 48 deletions js/checkbox.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global jQuery:true */

/*
* Fuel UX Checkbox
* https://github.com/ExactTarget/fuelux
Expand All @@ -11,7 +13,7 @@
// For more information on UMD visit:
// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js

(function (factory) {
(function umdFactory (factory) {
if (typeof define === 'function' && define.amd) {
// if AMD loader is available, register as an anonymous module.
define(['jquery'], factory);
Expand All @@ -22,7 +24,7 @@
// OR use browser globals if AMD is not present
factory(jQuery);
}
}(function ($) {
}(function CheckboxWrapper ($) {
// -- END UMD WRAPPER PREFACE --

// -- BEGIN MODULE CODE HERE --
Expand All @@ -31,18 +33,29 @@

// CHECKBOX CONSTRUCTOR AND PROTOTYPE

var Checkbox = function (element, options) {
var logError = function logError (error) {
if (window && window.console && window.console.error) {
window.console.error(error);
}
};

var Checkbox = function Checkbox (element, options) {
this.options = $.extend({}, $.fn.checkbox.defaults, options);
var $element = $(element);

if(element.tagName.toLowerCase() !== 'label') {
//console.log('initialize checkbox on the label that wraps the checkbox');
if (element.tagName.toLowerCase() !== 'label') {
logError('Checkbox must be initialized on the `label` that wraps the `input` element. See https://github.com/ExactTarget/fuelux/blob/master/reference/markup/checkbox.html for example of proper markup. Call `.checkbox()` on the `<label>` not the `<input>`');
return;
}

// cache elements
this.$label = $(element);
this.$label = $element;
this.$chk = this.$label.find('input[type="checkbox"]');
this.$container = $(element).parent('.checkbox'); // the container div
this.$container = $element.parent('.checkbox'); // the container div

if (!this.options.ignoreVisibilityCheck && this.$chk.css('visibility').match(/hidden|collapse/)) {
logError('For accessibility reasons, in order for tab and space to function on checkbox, checkbox `<input />`\'s `visibility` must not be set to `hidden` or `collapse`. See https://github.com/ExactTarget/fuelux/pull/1996 for more details.');
}

// determine if a toggle container is specified
var containerSelector = this.$chk.attr('data-toggle');
Expand All @@ -59,9 +72,8 @@

constructor: Checkbox,

setInitialState: function() {
setInitialState: function setInitialState () {
var $chk = this.$chk;
var $lbl = this.$label;

// get current state of input
var checked = $chk.prop('checked');
Expand All @@ -72,94 +84,83 @@
this.setDisabledState($chk, disabled);
},

setCheckedState: function(element, checked) {
setCheckedState: function setCheckedState (element, checked) {
var $chk = element;
var $lbl = this.$label;
var $container = this.$container;
var $containerToggle = this.$toggleContainer;

// set class on outer container too...to support highlighting
// TODO: verify inline checkboxes, also test with MCTheme

if(checked) {
if (checked) {
$chk.prop('checked', true);
$lbl.addClass('checked');
//$container.addClass('checked');
$containerToggle.removeClass('hide hidden');
$lbl.trigger('checked.fu.checkbox');
}
else {
} else {
$chk.prop('checked', false);
$lbl.removeClass('checked');
//$container.removeClass('checked');
$containerToggle.addClass('hidden');
$lbl.trigger('unchecked.fu.checkbox');
}

$lbl.trigger('changed.fu.checkbox', checked);
},

setDisabledState: function(element, disabled) {
var $chk = element;
setDisabledState: function setDisabledState (element, disabled) {
var $chk = $(element);
var $lbl = this.$label;

if(disabled) {
this.$chk.prop('disabled', true);
if (disabled) {
$chk.prop('disabled', true);
$lbl.addClass('disabled');
$lbl.trigger('disabled.fu.checkbox');
}
else {
this.$chk.prop('disabled', false);
} else {
$chk.prop('disabled', false);
$lbl.removeClass('disabled');
$lbl.trigger('enabled.fu.checkbox');
}

return $chk;
},

itemchecked: function (evt) {
itemchecked: function itemchecked (evt) {
var $chk = $(evt.target);
var checked = $chk.prop('checked');

this.setCheckedState($chk, checked);
},

toggle: function () {
toggle: function toggle () {
var checked = this.isChecked();

if(checked) {
if (checked) {
this.uncheck();
}
else {
} else {
this.check();
}
},

check: function () {
check: function check () {
this.setCheckedState(this.$chk, true);
},

uncheck: function () {
uncheck: function uncheck () {
this.setCheckedState(this.$chk, false);
},

isChecked: function () {
isChecked: function isChecked () {
var checked = this.$chk.prop('checked');
return checked;
},

enable: function () {
enable: function enable () {
this.setDisabledState(this.$chk, false);
},

disable: function () {
disable: function disable () {
this.setDisabledState(this.$chk, true);
},

destroy: function () {
destroy: function destroy () {
this.$label.remove();
// remove any external bindings
// [none]
// empty elements to return to original markup
// [none]
return this.$label[0].outerHTML;
}
};
Expand All @@ -168,11 +169,11 @@

// CHECKBOX PLUGIN DEFINITION

$.fn.checkbox = function (option) {
$.fn.checkbox = function checkbox (option) {
var args = Array.prototype.slice.call(arguments, 1);
var methodReturn;

var $set = this.each(function () {
var $set = this.each(function applyData () {
var $this = $(this);
var data = $this.data('fu.checkbox');
var options = typeof option === 'object' && option;
Expand All @@ -189,27 +190,29 @@
return (methodReturn === undefined) ? $set : methodReturn;
};

$.fn.checkbox.defaults = {};
$.fn.checkbox.defaults = {
ignoreVisibilityCheck: false
};

$.fn.checkbox.Constructor = Checkbox;

$.fn.checkbox.noConflict = function () {
$.fn.checkbox.noConflict = function noConflict () {
$.fn.checkbox = old;
return this;
};

// DATA-API

$(document).on('mouseover.fu.checkbox.data-api', '[data-initialize=checkbox]', function (e) {
$(document).on('mouseover.fu.checkbox.data-api', '[data-initialize=checkbox]', function initializeCheckboxes (e) {
var $control = $(e.target);
if (!$control.data('fu.checkbox')) {
$control.checkbox($control.data());
}
});

// Must be domReady for AMD compatibility
$(function () {
$('[data-initialize=checkbox]').each(function () {
$(function onReadyInitializeCheckboxes () {
$('[data-initialize=checkbox]').each(function initializeCheckbox () {
var $this = $(this);
if (!$this.data('fu.checkbox')) {
$this.checkbox($this.data());
Expand Down
12 changes: 7 additions & 5 deletions js/combobox.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global jQuery:true */

/*
* Fuel UX Combobox
* https://github.com/ExactTarget/fuelux
Expand All @@ -11,7 +13,7 @@
// For more information on UMD visit:
// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js

(function (factory) {
(function umdFactory (factory) {
if (typeof define === 'function' && define.amd) {
// if AMD loader is available, register as an anonymous module.
define(['jquery'], factory);
Expand All @@ -22,7 +24,7 @@
// OR use browser globals if AMD is not present
factory(jQuery);
}
}(function ($) {
}(function ComboboxWrapper ($) {
// -- END UMD WRAPPER PREFACE --

// -- BEGIN MODULE CODE HERE --
Expand Down Expand Up @@ -83,9 +85,9 @@
},

doSelect: function ($item) {

if (typeof $item[0] !== 'undefined') {
// remove selection from old item, may result in remove and
// remove selection from old item, may result in remove and
// re-addition of class if item is the same
this.$element.find('li.selected:first').removeClass('selected');

Expand Down Expand Up @@ -285,7 +287,7 @@
if (extra && extra.synthetic) {
this.selectByText(val);
return;
}
}
this.selectByText(val);

// find match based on input
Expand Down
6 changes: 4 additions & 2 deletions js/datepicker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global jQuery:true */

/*
* Fuel UX Datepicker
* https://github.com/ExactTarget/fuelux
Expand All @@ -11,7 +13,7 @@
// For more information on UMD visit:
// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js

(function (factory) {
(function umdFactory (factory) {
if (typeof define === 'function' && define.amd) {
// if AMD loader is available, register as an anonymous module.
define(['jquery'], factory);
Expand All @@ -22,7 +24,7 @@
// OR use browser globals if AMD is not present
factory(jQuery);
}
}(function ($) {
}(function DatepickerWrapper ($) {
// -- END UMD WRAPPER PREFACE --

// -- BEGIN MODULE CODE HERE --
Expand Down
6 changes: 4 additions & 2 deletions js/dropdown-autoflip.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global jQuery:true */

/*
* Fuel UX Dropdown Auto Flip
* https://github.com/ExactTarget/fuelux
Expand All @@ -11,7 +13,7 @@
// For more information on UMD visit:
// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js

(function (factory) {
(function umdFactory (factory) {
if (typeof define === 'function' && define.amd) {
// if AMD loader is available, register as an anonymous module.
define(['jquery'], factory);
Expand All @@ -22,7 +24,7 @@
// OR use browser globals if AMD is not present
factory(jQuery);
}
}(function ($) {
}(function dropdownautoflipWrapper ($) {
// -- END UMD WRAPPER PREFACE --

// -- BEGIN MODULE CODE HERE --
Expand Down
Loading