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

Expandable/dropdown menus #3917

Merged
merged 78 commits into from
May 20, 2024
Merged

Expandable/dropdown menus #3917

merged 78 commits into from
May 20, 2024

Conversation

martyn-w
Copy link
Contributor

@martyn-w martyn-w commented Mar 27, 2024

Trello card

Expandable/dropdown menus

Context

Changes proposed in this pull request

New dropdown menu system for mobile and desktop

Guidance to review

Please test at multiple screen resolutions (mobile, tablet and desktop)

@github-actions github-actions bot added ruby Pull requests that update Ruby code Style labels Mar 27, 2024
Comment on lines 23 to 25
def sync_mode(mode)
mode == :mobile ? :desktop : :mobile
end
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems slightly counterintuitive at first glance

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe there's a way of expressing what sync means in this context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep I think I could phrase that better 👍

Comment on lines 1 to 2
<!-- The <ul> element is dynamically generated -->
<!-- //NOSONAR -->
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this?

// fires when the user clicks on a navigation menu item
const item = event.target.closest('li');

if (item) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest avoid nesting with if (!item) return;

const childMenuSync = this.getTargetItem(item.dataset.childMenuSyncId);
const toggleSecondaryNavigation = item.dataset.toggleSecondaryNavigation;

if (!directLink) {
Copy link
Contributor

Choose a reason for hiding this comment

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

again i think better to return rather than nest

}

getTarget(id) {
if (id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

}

toggleIconExpanded(item) {
if (item) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (!item) return false;

toggleIconExpanded(item) {
if (item) {
const icon = item.querySelector('span.nav-icon');
if (icon) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (!icon) return false;

}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

you could possibly factor out a shared method here, eg

toggleIcon(item, expand = true) {
  if (!item) return false;

  const icon = item.querySelector('span.nav-icon');
  const linkOrButton = item.querySelector('a, button');
  
  if (!icon || !linkOrButton) return false;

  const currentClass = expand ? 'nav-icon__contracted' : 'nav-icon__expanded';
  const newClass = expand ? 'nav-icon__expanded' : 'nav-icon__contracted';
  const ariaExpanded = expand ? true : false;

  if (icon.classList.contains(currentClass)) {
    icon.classList.replace(currentClass, newClass);
    item.classList.toggle('selected', expand);
    linkOrButton.ariaExpanded = ariaExpanded;
    return true;
  }

  return false;
}

which is used by

toggleIconExpanded(item) {
  return this.toggleIcon(item, true);
}

toggleIconContracted(item) {
  return this.toggleIcon(item, false);
}


context "when using a desktop browser" do
it "renders a dropdown menu for category links" do
expect(page).to have_css("#secondary-navigation > div.category-links > ol.category-links-list > li[id='page-five-category-1-desktop'] > button")
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a less brittle and more readable way to test these things? eg

within('#secondary-navigation') do
  within('div.category-links') do
    expect(page).to have_button('whatever the button text is')
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't seem to make this approach work? - the within blocks are skipped over

@carlosmartinez
Copy link
Contributor

LGTM! Just a few suggestions

Copy link

Copy link

sonarcloud bot commented May 16, 2024

Copy link
Contributor

@gemmadallmandfe gemmadallmandfe left a comment

Choose a reason for hiding this comment

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

Looks good to me from a front-end perspective (apart from the known issues which are ticketed separately)

Happy for this to be merged first thing on Monday!

@martyn-w martyn-w merged commit f056f2e into master May 20, 2024
26 checks passed
@martyn-w martyn-w deleted the expandable-menus branch May 20, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Config Review ruby Pull requests that update Ruby code Style test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants