Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropdown layout in mobile menu #738

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions assets/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,7 @@ function addRssReadMore() {

// make parent item of dropdowm menu clickable which is not intended by Bootstrap
jQuery( '.dropdown .dropdown-toggle' ).on( 'click', function () {
const dropdownOpen = jQuery( this ).hasClass( 'show' ); // dropdown shown
const mobileOpen = jQuery( '#mainmenu-container' ).hasClass( 'show' ); // mobile nav open
if (
( dropdownOpen === false && mobileOpen === true ) ||
( dropdownOpen === true && mobileOpen === false )
) {
if ( jQuery( '.dropdown:hover' ).length !== 0 ) {
window.location = jQuery( this ).attr( 'href' );
}

Expand Down
18 changes: 10 additions & 8 deletions inc/class-wp-bootstrap-navwalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,12 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0
$item_has_children = false;
// If item has_children add atts to <a>.
if ( isset( $args->has_children ) && $args->has_children && 0 === $depth && $args->depth > 1 ) {
$item_has_children = true;
$atts['href'] = empty( $item->url ) ? '#' : $item->url;
$atts['data-bs-toggle'] = 'dropdown';
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
$atts['class'] = 'dropdown-toggle nav-link';
$atts['id'] = 'menu-item-dropdown-' . $item->ID;
$item_has_children = true;
$atts['href'] = empty( $item->url ) ? '#' : $item->url;
$atts['aria-haspopup'] = 'true';
$atts['aria-expanded'] = 'false';
$atts['class'] = 'dropdown-toggle nav-link';
$atts['id'] = 'menu-item-dropdown-' . $item->ID;
} else {
$atts['href'] = empty( $item->url ) ? '#' : $item->url;
// Items in dropdowns use .dropdown-item instead of .nav-link.
Expand Down Expand Up @@ -310,7 +309,10 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0
$item_output .= $args->after ?? '';

if ( $item_has_children ) {
$item_output .= '<div class="submenu-opener" data-bs-toggle="dropdown"><i class="fas fa-angle-down" ></i></div>';
$item_output .= '
<button class="toggle submenu-expand submenu-opener" data-toggle-target="dropdown" data-bs-toggle="dropdown" aria-expanded="false">
<span class="screen-reader-text">' . esc_attr__( 'Show sub menu', 'sunflower' ) . '</span>
</button>';
}

/**
Expand Down
209 changes: 134 additions & 75 deletions sass/_navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
div.dropdown-menu {
display: block;

margin-top: 54px;

&.show {
margin-top: 4px;
}

ul {
border-radius: 0;
}
}

}
}
}
Expand Down Expand Up @@ -113,6 +120,10 @@
}

.navbar {

$dropdown-button-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='#{$body-color}' stroke-linecap='round' stroke-linejoin='round'><path d='M2 5L8 11L14 5'/></svg>") !default;
$dropdown-button-icon-hover: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='#{$secondary}' stroke-linecap='round' stroke-linejoin='round'><path d='M2 5L8 11L14 5'/></svg>") !default;

padding: 0;

&-main {
Expand All @@ -124,30 +135,87 @@
&-light {

.navbar-nav {
align-items: center;
align-items: normal;

>.nav-item {

border-bottom: 4px solid transparent;
padding: 4px 0;
display: flex;


&.active {

>a {
color: $secondary;
}

&.current-menu-parent {

>a {
color: $body-color;
}
}

}

&:hover {

@include media-breakpoint-up(lg) {
border-bottom: 4px solid $secondary;
padding-bottom: 0;
}
}

&.menu-item-has-children {

.submenu-opener {
color: $black;
font-size: 18px;
flex-wrap: wrap;
justify-content: space-between;

button.submenu-opener {
border: none;
background: none;
background-image: #{escape-svg($dropdown-button-icon)};
background-repeat: no-repeat;
background-size: 30px;
background-position: center;
transition: transform 0.2s ease-in-out;
font-weight: 700;
right: var(--wp--preset--spacing--50);

&.show {
content: "";
transform: rotate(-180deg);
background-image: #{escape-svg($dropdown-button-icon-hover)};
}
}

&:hover {

button.submenu-opener {
background-image: #{escape-svg($dropdown-button-icon-hover)};
}
}
}

.dropdown-toggle {

text-align: end;

&::after {
display: none;
}

}

&.button-highlight {

a {
> a {

background-color: $secondary;
border-radius: 9999px;
text-align: left;
padding: 11px 14px 7px 14px;
margin-left: -7px;

&.nav-link {
color: $white;
Expand All @@ -156,7 +224,7 @@

&.menu-item-has-children {

.submenu-opener {
.dropdown-toggle {
color: $white;
}

Expand All @@ -165,25 +233,13 @@

}

.button-highlight {
background-color: $secondary;
cursor: pointer;
padding: 0 0.5rem;
margin: 0.2rem;
border-radius: 9999px;
order: 0;
white-space: nowrap;
max-height: 4em;

}


.nav-link {
color: $body-color;
font-size: 18px;
padding: 11px 0 7px 0;
margin-right: 0.5rem;
margin-left: 0.5rem;
text-align: left;

&:hover {
color: $secondary;
Expand Down Expand Up @@ -220,7 +276,6 @@
display: none;
}


.dropdown {

&-menu {
Expand Down Expand Up @@ -251,6 +306,13 @@
border: 0;
box-shadow: 0 25px 20px rgba(0, 0, 0, 0.1);
}

ul li {

&:not(:first-child) {
border-top: 1px solid $very-light-gray;
}
}
}

&-1 {
Expand All @@ -272,31 +334,39 @@
display: block;
border-radius: 4px;
margin-right: 0;
margin-top: -4px;
overflow: hidden;
border: 1px solid $white;
list-style-type: none;
background: $white;
background-color: $white;
padding: 0;
margin-bottom: -1px;

li {
padding: 0;
margin-right: 0;

&.active {

>a {
color: $secondary;
}

&.current-menu-parent {

>a {
color: $body-color;
}
}
}

a {
font-size: 18px;
text-transform: none;
font-weight: 700;
padding-top: 10px;
padding-bottom: 10px;

@include media-breakpoint-up(lg) {
border-bottom: 1px solid $very-light-gray;
}

&:hover {
color: $white;
background: $secondary;
color: $secondary;
}

&:focus-visible {
Expand All @@ -307,81 +377,70 @@
}
}

&-submenu {
list-style-type: none;
padding-left: 0;
margin-left: 0;

ul {

li {
text-transform: none;

a {
font-size: 18px;
font-weight: 400;
}
}
}
}

&-item {
display: flex;
align-items: center;
justify-content: space-between;

&.has-children {
margin-right: 2em;
}

&:hover {
background-color: $white;
}
}

}

.dropdown-toggle {

&::after {
display: none;
}
}

#mainmenu {

>li {
text-transform: uppercase;

&.menu-item-has-children {
display: flex;
align-items: baseline;
flex-wrap: wrap;

@include media-breakpoint-up(lg) {
flex-wrap: nowrap;
}

a {
flex-basis: auto;
}

ul li {
display: block;
}

.dropdown-menu {
flex: 100%;
top: 100%;

>ul {
margin-top: 20px;
}
}

}
}
}

.navbar-nav {
// specific settings to the collapse (mobile) menu
.navbar-collapse {
display: block;
width: 100%;
margin-left: 10px;

&.collapse.show {

li {
text-align: end;
border-top: 1px solid $very-light-gray;
padding-left: 14px;
}

.dropdown {

&-menu {

ul {
margin-top: 0;
}

.dropdown-menu {
position: static;
&.show {
width: 100%;
}
}

&-item {
justify-content: start;
}
}
}
}