Commit 49167644 authored by catch's avatar catch
Browse files

Issue #2782111 by theMusician, CarlyGerard, smustgrave, msankhala,...

Issue #2782111 by theMusician, CarlyGerard, smustgrave, msankhala, andrewmacpherson: Add aria-sort attribute to Views table output
parent 926297a4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@ public function testContentAdminSort() {
        ':label' => $string,
      ]));
    }
    // Verify aria-sort is present and its value matches the sort order.
    $this->assertSession()->elementAttributeContains('css', 'table thead tr th.views-field-title', 'aria-sort', 'ascending');
  }

  /**
+7 −0
Original line number Diff line number Diff line
@@ -524,6 +524,13 @@ function template_preprocess_views_view_table(&$variables) {
        // Improves accessibility of complex tables.
        $variables['header'][$field]['attributes']['id'] = Html::getUniqueId('view-' . $field . '-table-column');
      }
      // aria-sort is a WAI-ARIA property that indicates if items in a table
      // or grid are sorted in ascending or descending order. See
      // http://www.w3.org/TR/wai-aria/states_and_properties#aria-sort
      if ($active == $field) {
        $variables['header'][$field]['attributes']['aria-sort'] = ($order == 'asc') ? 'ascending' : 'descending';
      }

      // Check if header label is not empty.
      if (!empty($variables['header'][$field]['content'])) {
        $has_header_labels = TRUE;