Skip to content

Commit 3da6189

Browse files
Make macro expansion feature buttons accessible
1 parent dbac347 commit 3da6189

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,11 @@ fn get_expansion<'a, W: Write>(
325325
Cow::Owned(format!(
326326
"{closing}\
327327
<span class=expansion>\
328-
<input id={id} type=checkbox>\
329-
<label for={id}>↕</label>{reopening}",
328+
<input id={id} \
329+
tabindex=0 \
330+
type=checkbox \
331+
aria-label=\"Collapse/expand macro\" \
332+
title=\"\"Collapse/expand macro\">{reopening}",
330333
)),
331334
Some(Class::Expansion),
332335
));

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -928,10 +928,10 @@ ul.block, .block li, .block ul {
928928
display: inline;
929929
}
930930
.example-wrap .expansion > input {
931-
display: none;
932-
}
933-
.example-wrap .expansion > label {
931+
display: block;
934932
position: absolute;
933+
appearance: none;
934+
content: '↕';
935935
left: -20px;
936936
top: 0;
937937
border: 1px solid var(--border-color);
@@ -940,11 +940,9 @@ ul.block, .block li, .block ul {
940940
color: var(--main-color);
941941
padding: 0 2px;
942942
line-height: 20px;
943-
-moz-user-select: none;
944-
-webkit-user-select: none;
945-
-ms-user-select: none;
946-
user-select: none;
947-
943+
}
944+
.example-wrap .expansion > input::after {
945+
content: "↕";
948946
}
949947
.example-wrap .expansion .expanded {
950948
display: none;

tests/rustdoc-gui/macro-expansion.goml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ define-function: (
1212
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "none"})
1313

1414
// We "expand" the macro.
15-
click: "a[id='" + |line| + "'] + .expansion label"
15+
click: "a[id='" + |line| + "'] + .expansion input[type=checkbox]"
1616
// The "original" content is hidden.
1717
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "none"})
1818
// The expanded macro is visible.
1919
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "inline"})
2020

2121
// We collapse the macro.
22-
click: "a[id='" + |line| + "'] + .expansion label"
22+
click: "a[id='" + |line| + "'] + .expansion input[type=checkbox]"
2323
// The "original" content is expanded.
2424
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "inline"})
2525
// The expanded macro is hidden.
@@ -31,7 +31,7 @@ define-function: (
3131
call-function: ("check-expansion", {"line": 33, "original_content": "Debug"})
3232
// Then we check the `bar` macro expansion at line 41.
3333
call-function: ("check-expansion", {"line": 41, "original_content": "bar!(y)"})
34-
// Then we check the `println` macro expansion at line 23-25.
34+
// Then we check the `println` macro expansion at line 42-44.
3535
call-function: ("check-expansion", {"line": 42, "original_content": 'println!("
3636
43 {y}
3737
44 ")'})
@@ -56,7 +56,7 @@ assert-css: ('//*[@id="expand-50"]' + |repeat_e| + |repeat_e|, {"display": "none
5656

5757
// We "expand" the macro (because the line starts with a string, the label is not at the "top
5858
// level" of the `<code>`, so we need to use a different selector).
59-
click: ".expansion label[for='expand-50']"
59+
click: "#expand-50"
6060
// The "original" content is hidden.
6161
assert-css: ('//*[@id="expand-50"]' + |repeat_o|, {"display": "none"})
6262
assert-css: ('//*[@id="expand-50"]' + |repeat_o| + |repeat_o|, {"display": "none"})
@@ -65,10 +65,49 @@ assert-css: ('//*[@id="expand-50"]' + |repeat_e|, {"display": "inline"})
6565
assert-css: ('//*[@id="expand-50"]' + |repeat_e| + |repeat_e|, {"display": "inline"})
6666

6767
// We collapse the macro.
68-
click: ".expansion label[for='expand-50']"
68+
click: "#expand-50"
6969
// The "original" content is expanded.
7070
assert-css: ('//*[@id="expand-50"]' + |repeat_o|, {"display": "inline"})
7171
assert-css: ('//*[@id="expand-50"]' + |repeat_o| + |repeat_o|, {"display": "inline"})
7272
// The expanded macro is hidden.
7373
assert-css: ('//*[@id="expand-50"]' + |repeat_e|, {"display": "none"})
7474
assert-css: ('//*[@id="expand-50"]' + |repeat_e| + |repeat_e|, {"display": "none"})
75+
76+
// Checking the line 46 `println` which needs to be handled differently because the line number is
77+
// inside a "comment" span.
78+
assert-text: ("#expand-46 ~ .original", 'println!("
79+
47 {y}
80+
48 ")')
81+
// The "original" content should be expanded.
82+
assert-css: ("#expand-46 ~ .original", {"display": "inline"})
83+
// The expanded macro should be hidden.
84+
assert-css: ("#expand-46 ~ .expanded", {"display": "none"})
85+
86+
// We "expand" the macro.
87+
click: "#expand-46"
88+
// The "original" content is hidden.
89+
assert-css: ("#expand-46 ~ .original", {"display": "none"})
90+
// The expanded macro is visible.
91+
assert-css: ("#expand-46 ~ .expanded", {"display": "inline"})
92+
93+
// We collapse the macro.
94+
click: "#expand-46"
95+
// The "original" content is expanded.
96+
assert-css: ("#expand-46 ~ .original", {"display": "inline"})
97+
// The expanded macro is hidden.
98+
assert-css: ("#expand-46 ~ .expanded", {"display": "none"})
99+
100+
// Ensure that the toggles are focusable and can be interacted with keyboard.
101+
focus: "//a[@id='27']"
102+
press-key: "Tab"
103+
assert: "#expand-27:focus"
104+
assert-css: ("#expand-27 ~ .expanded", {"display": "none"})
105+
assert-css: ("#expand-27 ~ .original", {"display": "inline"})
106+
// We now expand the macro.
107+
press-key: "Space"
108+
assert-css: ("#expand-27 ~ .expanded", {"display": "inline"})
109+
assert-css: ("#expand-27 ~ .original", {"display": "none"})
110+
// We collapse the macro.
111+
press-key: "Space"
112+
assert-css: ("#expand-27 ~ .expanded", {"display": "none"})
113+
assert-css: ("#expand-27 ~ .original", {"display": "inline"})

0 commit comments

Comments
 (0)