Skip to content

Commit 9e66c9e

Browse files
authored
Merge pull request #104 from cs169/feature/datatable-sort-indicators
Sortable DataTable column headers had no visual indication of sort direction or clickability.
2 parents 08fed1d + e3e53df commit 9e66c9e

4 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
table.dataTable > thead > tr > th {
2+
position: relative;
3+
padding-right: 26px;
4+
5+
&.sorting,
6+
&.sorting_asc,
7+
&.sorting_desc {
8+
cursor: pointer;
9+
10+
&::after {
11+
position: absolute;
12+
right: 8px;
13+
top: 50%;
14+
transform: translateY(-50%);
15+
opacity: 0.5;
16+
font-size: 0.65em;
17+
}
18+
}
19+
20+
&.sorting::after {
21+
content: "\a";
22+
white-space: pre;
23+
line-height: 0.9;
24+
}
25+
26+
&.sorting_asc::after {
27+
content: "";
28+
opacity: 1;
29+
}
30+
31+
&.sorting_desc::after {
32+
content: "";
33+
opacity: 1;
34+
}
35+
36+
&.sorting_disabled {
37+
cursor: default;
38+
39+
&::after {
40+
content: none;
41+
}
42+
}
43+
}
44+
45+
.thead-dark th.sorting::after,
46+
.thead-dark th.sorting_asc::after,
47+
.thead-dark th.sorting_desc::after {
48+
color: #fff;
49+
}

app/javascript/styles/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $fa-font-path: '~@fortawesome/fontawesome-free/webfonts';
2727
@import 'merge_modal';
2828
@import './sidebar.scss';
2929
@import "./selectize.scss";
30+
@import "datatable_sorting";
3031

3132
html {
3233
min-height: 100%;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: DataTables sort indicators
2+
As an admin
3+
So that I can tell which column is sorted and in which direction
4+
Table headers show sort indicator arrows and a pointer cursor
5+
6+
Background:
7+
Given the following schools exist:
8+
| name | country | city | state | website | grade_level | school_type |
9+
| UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public |
10+
And the following teachers exist:
11+
| first_name | last_name | admin | primary_email | school | application_status |
12+
| Admin | User | true | testadminuser@berkeley.edu | UC Berkeley | Validated |
13+
Given I am on the BJC home page
14+
And I have an admin email
15+
And I follow "Log In"
16+
Then I can log in with Google
17+
18+
Scenario: Teachers table headers show sort indicators and pointer cursor
19+
When I go to the teachers page
20+
Then sortable table headers should have sort indicators
21+
And sortable table headers should have a pointer cursor
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
Then("sortable table headers should have sort indicators") do
4+
headers = page.all("th.sorting, th.sorting_asc, th.sorting_desc")
5+
expect(headers.length).to be > 0, "Expected DataTables sorting classes on <th> elements"
6+
headers.each do |th|
7+
pseudo_content = page.evaluate_script(
8+
"window.getComputedStyle(document.querySelector('th.#{th[:class].split.first}'), '::after').getPropertyValue('content')"
9+
)
10+
expect(pseudo_content).not_to eq("none"),
11+
"Expected ::after pseudo-element on th.#{th[:class]} but got content: #{pseudo_content}"
12+
end
13+
end
14+
15+
Then("sortable table headers should have a pointer cursor") do
16+
header = page.first("th.sorting, th.sorting_asc, th.sorting_desc")
17+
expect(header).not_to be_nil, "No sortable headers found"
18+
cursor = page.evaluate_script(
19+
"window.getComputedStyle(document.querySelector('th.sorting, th.sorting_asc, th.sorting_desc')).cursor"
20+
)
21+
expect(cursor).to eq("pointer"), "Expected cursor: pointer on sortable headers but got: #{cursor}"
22+
end

0 commit comments

Comments
 (0)