Skip to content

Commit

Permalink
Check for radio conditionals before setting attrs
Browse files Browse the repository at this point in the history
Since sometimes users set aria-controls unrelated to
conditional reveals we need to be extra careful here.

See #1156 for more
context.
  • Loading branch information
NickColley committed Jul 16, 2019
1 parent 7e2494a commit 42ab630
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/govuk/components/radios/radios.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ Radios.prototype.init = function () {
}

Radios.prototype.setAttributes = function ($input) {
var inputIsChecked = $input.checked
$input.setAttribute('aria-expanded', inputIsChecked)

var $content = document.querySelector('#' + $input.getAttribute('aria-controls'))
if ($content) {

if ($content && $content.classList.contains('govuk-radios__conditional')) {
var inputIsChecked = $input.checked

$input.setAttribute('aria-expanded', inputIsChecked)

$content.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked)
}
}
Expand Down

0 comments on commit 42ab630

Please sign in to comment.