Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created February 1, 2023 15:49
Show Gist options
  • Save ccapndave/71a8f5243a467a17eada3ccf345fd722 to your computer and use it in GitHub Desktop.
Save ccapndave/71a8f5243a467a17eada3ccf345fd722 to your computer and use it in GitHub Desktop.
const initialiseMenuWidths = (menuItem) => {
const menuContents = menuItem.querySelector('.menu-contents');
// Find the longest menu item
const maxWidth = Math.max(
...Array.from(menuContents.querySelectorAll('.nav-content li')).map(
(el) => el.offsetWidth
)
);
menuContents.querySelector(
'.nav-content > ul'
).style.gridAutoColumns = `${maxWidth}px`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment