Skip to content

Remove aria labels from radio buttons. #1224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PG-2.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/Value/AnswerChecker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ sub ans_matrix {
foreach my $j (0 .. $cols - 1) {
my $label;
if ($options{aria_label}) {
$label = $options{aria_label} . 'row ' . ($i + 1) . ' col ' . ($j + 1);
$label = $options{aria_label} . main::maketext('row [_1] col [_2] ', $i + 1, $j + 1);
} else {
$label = pgCall('generate_aria_label', ANS_NAME($ename, $i, $j));
}
Expand Down
34 changes: 17 additions & 17 deletions macros/core/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,10 @@ sub NAMED_ANS_RADIO {
'label',
tag(
'input',
type => 'radio',
name => $name,
id => $name,
aria_label => $options{aria_label} // generate_aria_label($name) . 'option 1 ',
value => $value,
type => 'radio',
name => $name,
id => $name,
value => $value,
$checked ? (checked => undef) : (),
%{ $options{attributes} }
)
Expand Down Expand Up @@ -499,11 +498,10 @@ sub NAMED_ANS_RADIO_EXTENSION {
'label',
tag(
'input',
type => 'radio',
name => $name,
id => $options{id} // "${name}_$value",
aria_label => $options{aria_label} // generate_aria_label($name),
value => $value,
type => 'radio',
name => $name,
id => $options{id} // "${name}_$value",
value => $value,
$checked ? (checked => undef) : (),
%{ $options{attributes} }
)
Expand Down Expand Up @@ -541,30 +539,30 @@ sub generate_aria_label {

# if we dont have an AnSwEr type name then we do the best we can
if ($name !~ /AnSwEr\d+/) {
return maketext('answer') . ' ' . $name;
return maketext('answer [_1] ', $name);
}

# check for quiz prefix
if ($name =~ /^Q\d+/ || $name =~ /^MaTrIx_Q\d+/) {
$name =~ s/Q0*(\d+)_//;
$label .= maketext('problem') . ' ' . $1 . ' ';
$label .= maketext('problem [_1] ', $1);
}

# get answer number
$name =~ /AnSwEr0*(\d+)/;
$label .= maketext('answer') . ' ' . $1 . ' ';
$label .= maketext('answer [_1] ', $1);

# check for Multianswer
if ($name =~ /MuLtIaNsWeR_/) {
$name =~ s/MuLtIaNsWeR_//;
$name =~ /AnSwEr(\d+)_(\d+)/;
$label .= maketext('part') . ' ' . ($2 + 1) . ' ';
$label .= maketext('part [_1] ', $2 + 1);
}

# check for Matrix
if ($name =~ /^MaTrIx_/) {
$name =~ /_(\d+)_(\d+)$/;
$label .= maketext('row') . ' ' . ($1 + 1) . ' ' . maketext('column') . ' ' . ($2 + 1) . ' ';
$label .= maketext('row [_1] column [_2] ', $1 + 1, $2 + 1);
}

return $label;
Expand Down Expand Up @@ -624,7 +622,7 @@ sub NAMED_ANS_CHECKBOX {
type => 'checkbox',
name => $name,
id => $name,
aria_label => generate_aria_label($name) . 'option 1 ',
aria_label => $options{aria_label} // (generate_aria_label($name) . maketext('option [_1] ', 1)),
value => $value,
$checked ? (checked => undef) : (),
%{ $options{attributes} }
Expand Down Expand Up @@ -677,7 +675,9 @@ sub NAMED_ANS_CHECKBOX_BUTTONS {
while (@buttons) {
$value = shift @buttons;
$tag = shift @buttons;
push(@out, NAMED_ANS_CHECKBOX_OPTION($name, $value, $tag, aria_label => $label . "option $count "));
push(@out,
NAMED_ANS_CHECKBOX_OPTION($name, $value, $tag, aria_label => $label . maketext('option [_1] ', $count))
);
$count++;
}

Expand Down
12 changes: 9 additions & 3 deletions macros/parsers/parserCheckboxList.pl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ sub CHECKS {

my @checks;
main::RECORD_IMPLICIT_ANS_NAME($name = main::NEW_ANS_NAME()) unless $name;
my $label = main::generate_aria_label($name);
my $label = (delete $options{aria_label}) // main::generate_aria_label($name);

for my $i (0 .. $#{ $self->{orderedChoices} }) {
my $value = $self->{values}[$i];
Expand All @@ -567,12 +567,18 @@ sub CHECKS {
main::NAMED_ANS_CHECKBOX_OPTION(
$name, $value, " $tag",
id => "${name}_$i",
aria_label => $label . 'option ' . ($i + 1) . ' ',
aria_label => $label . main::maketext('option [_1] ', $i + 1),
%options
)
);
} else {
push(@checks, main::NAMED_ANS_CHECKBOX($name, $value, " $tag", $extend, %options));
push(
@checks,
main::NAMED_ANS_CHECKBOX(
$name, $value, " $tag", $extend, %options,
aria_label => $label . main::maketext('option [_1] ', 1)
)
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion macros/parsers/parserPopUp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ sub MENU {
my $menu = "";
main::RECORD_IMPLICIT_ANS_NAME($name = main::NEW_ANS_NAME()) unless $name;
my $answer_value = (defined($main::inputs_ref->{$name}) ? $main::inputs_ref->{$name} : '');
my $aria_label = main::generate_aria_label($name);
my $aria_label = $options{aria_label} // main::generate_aria_label($name);

if ($main::displayMode =~ m/^HTML/) {
if ($self->{useHTMLSelect}) {
Expand Down
4 changes: 1 addition & 3 deletions macros/parsers/parserRadioButtons.pl
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ sub BUTTONS {
my @choices = @{ $self->{orderedChoices} };
my @radio = ();
main::RECORD_IMPLICIT_ANS_NAME($name = main::NEW_ANS_NAME()) unless $name;
my $label = main::generate_aria_label($name);

foreach my $i (0 .. $#choices) {
my $value = $self->{values}[$i];
Expand All @@ -639,8 +638,7 @@ sub BUTTONS {
@radio,
main::NAMED_ANS_RADIO_EXTENSION(
$name, $value, $tag,
aria_label => $label . "option " . ($i + 1) . " ",
id => "${name}_$i",
id => "${name}_$i",
$self->{uncheckable}
? (
attributes => {
Expand Down
39 changes: 34 additions & 5 deletions macros/parsers/parserRadioMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,34 @@ sub label {
return $self->{labels}[$i];
}

sub generate_aria_label {
my ($name, $radioIndex, $partIndex) = @_;
my $label = '';

$name =~ s/$answerPrefix//;

# Check for the quiz prefix.
if ($name =~ /^Q\d+/ || $name =~ /^MaTrIx_Q\d+/) {
$name =~ s/Q0*(\d+)_//;
$label .= main::maketext('problem [_1] ', $1);
}

# Get the answer number.
$name =~ /AnSwEr0*(\d+)/;
$label .= main::maketext('answer [_1] ', $1);

$label .= main::maketext('part [_1] ', $radioIndex);
$label .= main::maketext('subpart [_1] ', $partIndex);

# Check for a Matrix answer.
if ($name =~ /^MaTrIx_/) {
$name =~ /_(\d+)_(\d+)$/;
$label .= main::maketext('row [_1] column [_2] ', $1 + 1, $2 + 1);
}

return $label;
}

# Produce the answer rule.
sub ans_rule {
my ($self, $size, @options) = @_;
Expand Down Expand Up @@ -648,6 +676,7 @@ sub ans_rule {
? (defined $size->[$i][ $_ - 1 ] ? $size->[$i][ $_ - 1 ] : 20)
: $size,
answer_group_name => $radio_name,
aria_label => generate_aria_label($name, $i + 1, $_),
@options
)
)
Expand All @@ -663,6 +692,7 @@ sub ans_rule {
? (defined $size->[$i][ $_ - 1 ] ? $size->[$i][ $_ - 1 ] : 20)
: $size,
answer_group_name => $radio_name,
aria_label => generate_aria_label($name, $i + 1, $_),
@options
)
)
Expand Down Expand Up @@ -724,11 +754,10 @@ sub begin_radio {
HTML => qq{<div class="radio-container">}
. main::tag(
'input',
type => 'radio',
name => $name,
id => "$name$idSuffix",
aria_label => main::generate_aria_label("$answerPrefix${name}_0") . ' option ' . ($i + 1),
value => $value,
type => 'radio',
name => $name,
id => "$name$idSuffix",
value => $value,
$self->{uncheckable}
? (
data_uncheckable_radio => 1,
Expand Down