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

feat: mobile navigation sidebar menu #142

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions src/_includes/layouts/project.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
<div class="content">
<nav aria-labelledby="project-menu" class="flow">
<h2 id="project-menu">{% __ 'project-menu' %}</h2>
<ul role="list" class="flow">
</ul>
<inclusive-disclosure>
<button aria-controls="{{ title | slugify }}-menu">
<h2 id="project-menu-mobile">{% __ 'project-menu' %}</h2>
</button>
<div content id="{{ title | slugify }}-menu">
<ul role="list" class="flow">
</ul>
</div>
</inclusive-disclosure>
</nav>
<article class="flow">
{{ content | safe }}
Expand Down
2 changes: 1 addition & 1 deletion src/_transforms/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default (value, outputPath) => {
}
}

const pageNavHeadings = document.querySelectorAll("main:has(nav) h2");
const pageNavHeadings = document.querySelectorAll("main:has(nav) article h2");
if (pageNavHeadings.length > 0) {
const navContainer = document.querySelector("main nav ul");
for (const heading of pageNavHeadings) {
Expand Down
7 changes: 1 addition & 6 deletions src/assets/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,22 @@ customElements.define(
super();

this.toggle = this.querySelector("[aria-controls]");
this.content = this.querySelector("[content]");

if (!this.toggle || !this.content) {
if (!this.toggle) {
return;
}

this.toggle.removeAttribute("hidden");
this.toggle.setAttribute("aria-expanded", false);
this.content.setAttribute("hidden", "");

this.toggle.addEventListener("click", this);
}

handleEvent(event) {
event.preventDefault();
if (this.toggle.getAttribute("aria-expanded") === "true") {
this.toggle.setAttribute("aria-expanded", false);
this.content.setAttribute("hidden", "");
} else {
this.toggle.setAttribute("aria-expanded", true);
this.content.removeAttribute("hidden");
}
}
}
Expand Down
41 changes: 39 additions & 2 deletions src/assets/styles/collections/_projects.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,54 @@

.project nav,
.project article {
padding-inline: var(--common-inline-padding);
box-shadow: inset 0 -0.1875rem 0 0 var(--fl-fgColor, transparent);
}

.project nav {
background-color: var(--fl-bgColor, var(--color-indigo-100));
padding-block: 1.25rem 3.125rem;
}

.project nav > h2 {
display: none;
}

.project nav inclusive-disclosure {
padding-inline: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2025-01-24 at 4 39 42 PM

We should remove top margin for this one;

margin-block-start: unset;

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried it and I don't agree; the focus state looks really weird with the double border at the top:

Focus state without top margin

Copy link
Member

Choose a reason for hiding this comment

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

@greatislander and @chosww, I think I can see both points here. There ends up being a lot of horizontal bars across the page, especially towards the top, such as the included screenshot. Is it possible to remove some of these horizontal bars/borders or change how the "sections" are visually indicated. I don't think it's always clear right now where things break up and in the case of the project menu is making things look less aligned than they do without the contrast theme.

Screenshot showing several horizontal bars.

Would something looking like the following be okay?

Screenshot with bars removed Screenshot with focus styling

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually think that's probably a bigger conversation and I would prefer to open a separate issue to explore the approach we are taking to delineating sections when contrast themes are applied. Is that okay? @jobara if you want to file an issue that's good with me.

Copy link
Member

Choose a reason for hiding this comment

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

Filed as #148

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Let me know if this is good to merge now.

}

.project nav inclusive-disclosure > * {
padding-inline: var(--common-inline-padding);
}

.project nav inclusive-disclosure [aria-expanded] {
box-shadow: none;
}

.project nav inclusive-disclosure [aria-expanded]:after {
right: var(--common-inline-padding);
}

@media (width >= 70.875rem) {
.project nav > h2 {
display: block;
}

.project nav inclusive-disclosure > * {
padding-inline: 0;
}

.project nav inclusive-disclosure [aria-expanded] {
display: none;
}

.project nav inclusive-disclosure [aria-expanded] + * {
display: block;
}
}

.project article {
padding-block: 2.125rem 5rem;
padding-inline: var(--common-inline-padding);
}

.project article > * {
Expand Down
8 changes: 8 additions & 0 deletions src/assets/styles/components/_disclosure.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ inclusive-disclosure [aria-expanded] {
}
}

inclusive-disclosure [aria-expanded] + * {
display: none;
}

inclusive-disclosure [aria-expanded="true"] + * {
display: block;
}

inclusive-disclosure [aria-expanded="true"]::after {
transform: rotate(180deg);
}
Expand Down
Loading