Skip to content

Commit

Permalink
Fixed a JavaScript error when clicking anywhere but on a toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
KittyGiraudel committed Mar 14, 2016
1 parent 63884d6 commit 1be89d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions a11y-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
var toggle = event.target.hasAttribute(namespace)
? event.target
: closest(event.target, '[' + namespace + ']');
var target = targetsMap[toggle.getAttribute(namespace)];
var isExpanded = toggle.getAttribute('aria-expanded') === 'true';
var target = toggle && targetsMap[toggle.getAttribute(namespace)];

if (target) {
var isExpanded = toggle.getAttribute('aria-expanded') === 'true';

toggle.setAttribute('aria-expanded', !isExpanded);
target.setAttribute('aria-hidden', isExpanded);
}
Expand Down
2 changes: 1 addition & 1 deletion a11y-toggle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
var toggle = event.target.hasAttribute(namespace)
? event.target
: closest(event.target, '[' + namespace + ']');
var target = targetsMap[toggle.getAttribute(namespace)];
var isExpanded = toggle.getAttribute('aria-expanded') === 'true';
var target = toggle && targetsMap[toggle.getAttribute(namespace)];

if (target) {
var isExpanded = toggle.getAttribute('aria-expanded') === 'true';

toggle.setAttribute('aria-expanded', !isExpanded);
target.setAttribute('aria-hidden', isExpanded);
}
Expand Down

0 comments on commit 1be89d0

Please sign in to comment.