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

attach click event to links in nav bar so that it closes the nav bar … #123

Merged
merged 6 commits into from
Jul 17, 2023
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
19 changes: 17 additions & 2 deletions gov_uk_dashboards/assets/mobile-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var mobileNav = null;
* @type {boolean}
*/
var isOpen = false;

if (typeof attachEventToDash !== 'undefined') {
attachEventToDash('mobile-menu-btn', 'click', function () {
if (mobileNav === null) {
Expand All @@ -18,6 +18,21 @@ if (typeof attachEventToDash !== 'undefined') {
mobileNav.style.display = isOpen ? 'none' : 'inline-block';
isOpen = !isOpen;
}, false)

// attach click events that close the menu to links in the nav menu
var numberOfLinks = 8; // ideally get dynamically but document.querySelectorAll and trying to match id before attaching event to Dash didn't work..
Ellie-Brakoniecki marked this conversation as resolved.
Show resolved Hide resolved
for (var i = 0; i < numberOfLinks; i++) {
var linkId = 'nav-bar-link-' + i + '-mobile';
attachEventToDash(linkId, 'click', function () {
if (mobileNav === null) {
mobileNav = document.getElementById('nav-section')
if (!mobileNav) {
return;
}
Ellie-Brakoniecki marked this conversation as resolved.
Show resolved Hide resolved
}
mobileNav.style.display = 'none';
isOpen = false;
}, false);
}

/**
Expand Down Expand Up @@ -46,4 +61,4 @@ window.addEventListener(
}
}
}, 150)
);
);}
6 changes: 4 additions & 2 deletions gov_uk_dashboards/components/plotly/side_navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ def side_navbar(
)


def side_navbar_link(text, href):
def side_navbar_link(text, href, link_id):
"""A link to another dashboard"""
return html.Li(
dcc.Link(text, href=href, className="govuk-link govuk-link--no-visited-state"),
className="moj-side-navigation__item govuk-!-margin-bottom-1",
id=link_id,
)


def side_navbar_link_active(text, href):
def side_navbar_link_active(text, href, link_id):
"""
A link to another dashboard that appears highlighted, suggesting to the user that they are
already viewing the linked dashboard.
Expand All @@ -39,4 +40,5 @@ def side_navbar_link_active(text, href):
"moj-side-navigation__item moj-side-navigation__item--active "
"govuk-!-margin-bottom-1"
),
id=link_id,
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
author="Department for Levelling Up, Housing and Communities",
description="Provides access to functionality common to creating a data dashboard.",
name="gov_uk_dashboards",
version="9.13.4",
version="9.14.0",
long_description=long_description,
long_description_content_type="text/markdown",
packages=find_packages(),
Expand Down
Loading