From c6f863a94b7d56c7cd872395fba5f66534eced70 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sun, 1 Jun 2025 13:38:33 +0200 Subject: [PATCH] a11y: Set aria-label for comment action options dropdown Summary: Forms should have a label per https://dequeuniversity.com/rules/axe/4.10/link-select. This is not the case for the `` element above the comment field (which has "Add Action..." as its first option) with and without this patch. * Optionally, run an Accessibility check in Chromium Lighthouse. Reviewers: O1 Blessed Committers, chris Reviewed By: O1 Blessed Committers, chris Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T16072 Differential Revision: https://we.phorge.it/D26051 --- ...abricatorApplicationTransactionCommentView.php | 1 + src/view/form/control/AphrontFormControl.php | 15 +++++++++++++++ .../form/control/AphrontFormSelectControl.php | 7 ++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php index b0f71069a9..3f402e61e7 100644 --- a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php +++ b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php @@ -451,6 +451,7 @@ final class PhabricatorApplicationTransactionCommentView $action_select = id(new AphrontFormSelectControl()) ->addClass('phui-comment-fullwidth-control') ->addClass('phui-comment-action-control') + ->setAriaLabel(pht('Comment Action Options')) ->setID($action_id) ->setOptions($options); diff --git a/src/view/form/control/AphrontFormControl.php b/src/view/form/control/AphrontFormControl.php index af317d257c..7a8199cfc4 100644 --- a/src/view/form/control/AphrontFormControl.php +++ b/src/view/form/control/AphrontFormControl.php @@ -3,6 +3,7 @@ abstract class AphrontFormControl extends AphrontView { private $label; + private $ariaLabel; private $caption; private $error; private $name; @@ -52,6 +53,20 @@ abstract class AphrontFormControl extends AphrontView { return $this; } + /** + * Explicitly set an aria-label attribute for accessibility. Only to be used + * when no visible label is already set via setLabel(). + * @param string $aria_label aria-label text to add to the form control + */ + public function setAriaLabel($aria_label) { + $this->ariaLabel = $aria_label; + return $this; + } + + public function getAriaLabel() { + return $this->ariaLabel; + } + public function getLabel() { return $this->label; } diff --git a/src/view/form/control/AphrontFormSelectControl.php b/src/view/form/control/AphrontFormSelectControl.php index 8799fcfd91..4ceef484a3 100644 --- a/src/view/form/control/AphrontFormSelectControl.php +++ b/src/view/form/control/AphrontFormSelectControl.php @@ -28,9 +28,10 @@ final class AphrontFormSelectControl extends AphrontFormControl { $this->getValue(), $this->getOptions(), array( - 'name' => $this->getName(), - 'disabled' => $this->getDisabled() ? 'disabled' : null, - 'id' => $this->getID(), + 'name' => $this->getName(), + 'disabled' => $this->getDisabled() ? 'disabled' : null, + 'id' => $this->getID(), + 'aria-label' => $this->getAriaLabel(), ), $this->disabledOptions); } -- 2.51.2