Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit 5f31822

Browse files
committed
Restore use of button for menu-toggle in AMP
1 parent b4d24c2 commit 5f31822

File tree

7 files changed

+19
-47
lines changed

7 files changed

+19
-47
lines changed

functions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ function _s_widgets_init() {
126126
* Note that this must only be called after the parse_query action.
127127
*
128128
* @link https://github.com/Automattic/amp-wp
129+
* @return bool Is AMP endpoint (and AMP plugin is active).
129130
*/
130131
function _s_is_amp() {
131132
return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
132133
}
133134

134135
/**
135-
* Detemrine whether amp-live-list should be used for the comment list.
136+
* Determine whether amp-live-list should be used for the comment list.
136137
*
137138
* @return bool Whether to use amp-live-list.
138139
*/
@@ -155,7 +156,7 @@ function _s_styles() {
155156
/**
156157
* Enqueue scripts.
157158
*
158-
* This short-circuits in AMP because custom scripts are not allowed. There is are AMP equivalents provided elsewhere.
159+
* This short-circuits in AMP because custom scripts are not allowed. There are AMP equivalents provided elsewhere.
159160
*
160161
* navigation:
161162
* In AMP the :focus-within selector is used to keep submenus displayed while tabbing,

header.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
<?php endif; ?>
4545
</div><!-- .site-branding -->
4646

47-
<nav id="site-navigation" class="main-navigation"
47+
<nav
48+
id="site-navigation"
49+
class="main-navigation"
4850
<?php if ( _s_is_amp() ) : ?>
4951
[class]=" siteNavigationMenu.expanded ? 'main-navigation toggled' : 'main-navigation' "
5052
<?php endif; ?>
@@ -57,26 +59,19 @@
5759
}
5860
</script>
5961
</amp-state>
60-
<input
61-
id="site-navigation-expanded"
62-
type="checkbox"
63-
hidden
64-
on="change:AMP.setState( { siteNavigationMenu: { expanded: event.checked } } )"
65-
>
66-
<label
67-
class="menu-toggle"
68-
for="site-navigation-expanded"
69-
tabindex="0"
70-
role="button"
71-
aria-controls="primary-menu"
72-
aria-expanded="false"
62+
<?php endif; ?>
63+
64+
<button
65+
class="menu-toggle"
66+
aria-controls="primary-menu"
67+
aria-expanded="false"
68+
<?php if ( _s_is_amp() ) : ?>
69+
on="tap:AMP.setState( { siteNavigationMenu: { expanded: ! siteNavigationMenu.expanded } } )"
7370
[aria-expanded]="siteNavigationMenu.expanded ? 'true' : 'false'"
74-
>
71+
<?php endif; ?>
72+
>
7573
<?php esc_html_e( 'Primary Menu', '_s' ); ?>
76-
</label>
77-
<?php else : ?>
78-
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', '_s' ); ?></button>
79-
<?php endif; ?>
74+
</button>
8075
<?php
8176
wp_nav_menu( array(
8277
'theme_location' => 'menu-1',

sass/_normalize.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ img {
150150
*/
151151

152152
button,
153-
[role=button],
154153
input,
155154
optgroup,
156155
select,
@@ -167,7 +166,6 @@ textarea {
167166
*/
168167

169168
button,
170-
[role=button],
171169
input { /* 1 */
172170
overflow: visible;
173171
}
@@ -178,7 +176,6 @@ input { /* 1 */
178176
*/
179177

180178
button,
181-
[role=button],
182179
select { /* 1 */
183180
text-transform: none;
184181
}
@@ -188,7 +185,6 @@ select { /* 1 */
188185
*/
189186

190187
button,
191-
[role=button],
192188
[type="button"],
193189
[type="reset"],
194190
[type="submit"] {
@@ -200,7 +196,6 @@ button,
200196
*/
201197

202198
button::-moz-focus-inner,
203-
[role=button]::-moz-focus-inner,
204199
[type="button"]::-moz-focus-inner,
205200
[type="reset"]::-moz-focus-inner,
206201
[type="submit"]::-moz-focus-inner {
@@ -213,7 +208,6 @@ button::-moz-focus-inner,
213208
*/
214209

215210
button:-moz-focusring,
216-
[role=button]:-moz-focusring,
217211
[type="button"]:-moz-focusring,
218212
[type="reset"]:-moz-focusring,
219213
[type="submit"]:-moz-focusring {

sass/forms/_buttons.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
button,
2-
[role=button],
32
input[type="button"],
43
input[type="reset"],
54
input[type="submit"] {

sass/navigation/_menus.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@
8484
}
8585

8686
/* Small menu. */
87-
.menu-toggle {
88-
display: inline-block;
89-
user-select: none; /* when label[role=button] in AMP */
90-
}
87+
.menu-toggle,
9188
.main-navigation.toggled ul {
9289
display: block;
9390
}

sass/typography/_typography.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
body,
22
button,
3-
[role=button],
43
input,
54
select,
65
optgroup,

style.css

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ img {
196196
*/
197197

198198
button,
199-
[role=button],
200199
input,
201200
optgroup,
202201
select,
@@ -213,7 +212,6 @@ textarea {
213212
*/
214213

215214
button,
216-
[role=button],
217215
input { /* 1 */
218216
overflow: visible;
219217
}
@@ -224,7 +222,6 @@ input { /* 1 */
224222
*/
225223

226224
button,
227-
[role=button],
228225
select { /* 1 */
229226
text-transform: none;
230227
}
@@ -234,7 +231,6 @@ select { /* 1 */
234231
*/
235232

236233
button,
237-
[role=button],
238234
[type="button"],
239235
[type="reset"],
240236
[type="submit"] {
@@ -246,7 +242,6 @@ button,
246242
*/
247243

248244
button::-moz-focus-inner,
249-
[role=button]::-moz-focus-inner,
250245
[type="button"]::-moz-focus-inner,
251246
[type="reset"]::-moz-focus-inner,
252247
[type="submit"]::-moz-focus-inner {
@@ -259,7 +254,6 @@ button::-moz-focus-inner,
259254
*/
260255

261256
button:-moz-focusring,
262-
[role=button]:-moz-focusring,
263257
[type="button"]:-moz-focusring,
264258
[type="reset"]:-moz-focusring,
265259
[type="submit"]:-moz-focusring {
@@ -397,7 +391,6 @@ template {
397391
--------------------------------------------------------------*/
398392
body,
399393
button,
400-
[role=button],
401394
input,
402395
select,
403396
optgroup,
@@ -534,7 +527,6 @@ table {
534527
# Forms
535528
--------------------------------------------------------------*/
536529
button,
537-
[role=button],
538530
input[type="button"],
539531
input[type="reset"],
540532
input[type="submit"] {
@@ -550,15 +542,13 @@ input[type="submit"] {
550542
}
551543

552544
button:hover,
553-
[role=button]:hover,
554545
input[type="button"]:hover,
555546
input[type="reset"]:hover,
556547
input[type="submit"]:hover {
557548
border-color: #ccc #bbb #aaa;
558549
}
559550

560551
button:active, button:focus,
561-
[role=button]:active, [role=button]:focus,
562552
input[type="button"]:active,
563553
input[type="button"]:focus,
564554
input[type="reset"]:active,
@@ -712,10 +702,7 @@ a:hover, a:active {
712702
}
713703

714704
/* Small menu. */
715-
.menu-toggle {
716-
display: inline-block;
717-
user-select: none; /* when label[role=button] in AMP */
718-
}
705+
.menu-toggle,
719706
.main-navigation.toggled ul {
720707
display: block;
721708
}

0 commit comments

Comments
 (0)