Visitar URL original
USWDS - Megamenu: Recalculate width of outer-megamenu elements by amyleadem · Pull Request #4757 · uswds/uswds · GitHub
Skip to content
Merged
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
37 changes: 32 additions & 5 deletions packages/usa-header/src/styles/_usa-megamenu.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
@use "sass:math";

@use "sass:meta";
@use "uswds-core" as *;

@mixin outer-megamenu {
@mixin outer-megamenu($header-max-width: $theme-header-max-width, $type) {
@include u-pin("y");
background-color: color("primary-darker");
content: "";
display: block;
position: absolute;
width: 100%;

// retrieve the unit value of $theme-header-max-width, depending on type of value added
$mw: smart-quote($header-max-width);
@if meta.type-of($header-max-width) == "string" {
$mw: units($header-max-width);
}
Comment on lines +13 to +16

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for type in case user adds a unit value instead of a USWDS value. This maintains current capabilities.


// subtract half the value of the viewport width from half the value of the submenu width
// standard needs the additional $theme-site-margins-width to accommodate different paddings/structure on #basic-mega-nav-section-two
@if $type == "standard" {
width: calc(50vw - $mw / 2 + units($theme-site-margins-width));
} @else if $type == "extended" {
width: calc(50vw - $mw / 2);
}
}

.usa-megamenu {
Expand Down Expand Up @@ -36,15 +49,29 @@

&::before {
@include at-media($theme-header-min-width) {
@include outer-megamenu;
@include outer-megamenu($type: "standard");
right: 100%;
}
}

&::after {
@include at-media($theme-header-min-width) {
@include outer-megamenu;
@include outer-megamenu($type: "standard");
left: 100%;
}
}
}

.usa-header--extended .usa-megamenu.usa-nav__submenu {
&::before {
@include at-media($theme-header-min-width) {
@include outer-megamenu($type: "extended");
}
}

&::after {
@include at-media($theme-header-min-width) {
@include outer-megamenu($type: "extended");
}
}
}