Skip to content

Commit 33d6a8c

Browse files
authored
Nav Block Updates (#194)
* [N/A] Fix duplicate class attributes * [N/A] Added classes/variants to check when menu open/closed
1 parent d478c43 commit 33d6a8c

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

wp-content/themes/wp-starter/blocks/navigation-container/render.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class="hidden"
4545
<?php if ( ! is_admin() ) : ?>
4646
x-show="!menuIsOpen"
4747
<?php endif; ?>
48-
class="m-2" xmlns="http://www.w3.org/2000/svg" width="27" height="18" viewBox="0 0 27 18" fill="currentColor" class="menu-open">
48+
class="m-2 menu-open" xmlns="http://www.w3.org/2000/svg" width="27" height="18" viewBox="0 0 27 18" fill="currentColor">
4949
<title><?php esc_html_e( 'Open Menu', 'wp-starter' ); ?></title>
5050
<path d="M26.8059 1H0.805908" stroke="currentColor" stroke-width="1.5"></path>
5151
<path d="M26.8059 17H0.805908" stroke="currentColor" stroke-width="1.5"></path>
@@ -55,7 +55,7 @@ class="m-2" xmlns="http://www.w3.org/2000/svg" width="27" height="18" viewBox="0
5555
<?php if ( ! is_admin() ) : ?>
5656
x-show="menuIsOpen"
5757
<?php endif; ?>
58-
class="m-2" xmlns="http://www.w3.org/2000/svg" width="21" height="20" fill="currentColor" class="menu-close">
58+
class="m-2 menu-close" xmlns="http://www.w3.org/2000/svg" width="21" height="20" fill="currentColor">
5959
<title><?php esc_html_e( 'Close Menu', 'wp-starter' ); ?></title>
6060
<path d="M19.192 19.192.808.808M1 19.192 19.385.808" stroke="currentColor" stroke-width="2"></path>
6161
</svg>
@@ -64,6 +64,7 @@ class="m-2" xmlns="http://www.w3.org/2000/svg" width="21" height="20" fill="curr
6464
<div
6565
<?php if ( ! is_admin() ) : ?>
6666
x-show="menuIsOpen"
67+
:class="{ 'menu-hidden': !menuIsOpen }"
6768
@click.away="menuIsOpen = false"
6869
<?php endif; ?>
6970
class="acf-block-inner__container"

wp-content/themes/wp-starter/blocks/navigation-container/render.twig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
{% if function('is_admin') == false %}
4242
x-show="!menuIsOpen"
4343
{% endif %}
44-
class="m-2" xmlns="http://www.w3.org/2000/svg" role="img" width="27" height="18" viewBox="0 0 27 18" fill="currentColor" class="menu-open">
44+
class="m-2 menu-open" xmlns="http://www.w3.org/2000/svg" role="img" width="27" height="18" viewBox="0 0 27 18" fill="currentColor">
4545
<title>Open Menu</title>
4646
<path d="M26.8059 1H0.805908" stroke="currentColor" stroke-width="1.5"></path>
4747
<path d="M26.8059 17H0.805908" stroke="currentColor" stroke-width="1.5"></path>
@@ -51,7 +51,7 @@
5151
{% if function('is_admin') == false %}
5252
x-show="menuIsOpen"
5353
{% endif %}
54-
class="m-2" xmlns="http://www.w3.org/2000/svg" role="img" width="21" height="20" fill="currentColor" class="menu-close">
54+
class="m-2 menu-close" xmlns="http://www.w3.org/2000/svg" role="img" width="21" height="20" fill="currentColor">
5555
<title>Close Menu</title>
5656
<path d="M19.192 19.192.808.808M1 19.192 19.385.808" stroke="currentColor" stroke-width="2"></path>
5757
</svg>
@@ -60,6 +60,7 @@
6060
<div
6161
{% if function('is_admin') == false %}
6262
x-show="menuIsOpen"
63+
:class="{ 'menu-hidden': !menuIsOpen }"
6364
@click.away="menuIsOpen = false"
6465
{% endif %}
6566
class="acf-block-inner__container"

wp-content/themes/wp-starter/blocks/navigation-container/view.css

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
@apply mobile-menu:w-auto flex w-full flex-col items-end gap-5;
33

44
& > .acf-block-inner__container {
5-
@apply mobile-menu:!flex;
5+
@apply fixed z-40 top-0 right-0 w-full h-full bg-white;
6+
@apply admin-bar-sticky:top-[var(--wp-admin--admin-bar--height,0)];
7+
@apply mobile-menu:w-auto mobile-menu:relative mobile-menu:top-auto mobile-menu:right-auto mobile-menu:flex!;
68
}
79
&[x-data*='true'] > .acf-block-inner__container {
8-
@apply max-mobile-menu:!flex;
10+
@apply max-mobile-menu:flex!;
911
}
1012

1113
button.navigation-toggle[aria-rel='mobile-toggle'] {
12-
@apply mobile-menu:hidden absolute inset-y-0 right-0 flex h-32 w-32 items-center justify-center text-black dark:text-white;
14+
@apply absolute z-50 inset-y-0 right-0 flex h-32 w-32 items-center justify-center text-black dark:text-white;
15+
@apply mobile-menu:hidden;
16+
@apply mobile-menu-open:fixed;
1317
}
1418
.acf-block-inner__container {
1519
@apply mobile-menu:pt-0 mobile-menu:w-auto w-full pt-24;
@@ -19,3 +23,13 @@
1923
@apply flex flex-row gap-24;
2024
}
2125
}
26+
27+
html, body {
28+
&:has(.menu-open[style]) {
29+
@apply overflow-hidden
30+
}
31+
}
32+
33+
#wpadminbar {
34+
@apply max-admin-bar-sticky:z-[30]!;
35+
}

wp-content/themes/wp-starter/src/styles/tailwind.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
/* Dark theme to be driven by a CSS selector instead of the prefers-color-scheme media query */
88
@custom-variant dark (&:where(.dark, .dark *));
9+
@custom-variant mobile-menu-closed (body:has(.menu-closed[style]) &);
10+
@custom-variant mobile-menu-open (body:has(.menu-open[style]) &);
911

1012
/*
1113
Check the css files in the tailwind folder for more variables
@@ -15,7 +17,9 @@
1517
/* Screens (breakpoints) */
1618
--breakpoint-container: 1200px;
1719
--breakpoint-content-wide: 900px;
20+
--breakpoint-admin-bar-desktop: 782px;
1821
--breakpoint-wp-cols: 781px;
22+
--breakpoint-admin-bar-sticky: 601px;
1923
--breakpoint-mobile-menu: 600px;
2024
--breakpoint-xs: 480px;
2125

0 commit comments

Comments
 (0)