Simple click-triggered navigation submenus. Accessible and progressively enhanced.

Overview

Clicky Menus!

A project by Mark Root-Wiley, MRW Web Design

Clicky Menus lets you create a progressively-enhanced, accessible one-level dropdown menu that opens when activated by click, touch, or ENTER/SPACE. The menu is progressively enhanced, supporting hover and keyboard navigation (in modern browsers) if JS is not enabled.

Basic Features

  • Supports mouse, touch, and keyboard interactions
  • Turns parent items from links into buttons
  • aria-expanded, aria-controls and aria-hidden support
  • Close open submenu with ESC key
  • Close open submenu with click outside of open menu
  • Basic offscreen-menu prevention

Browser Support

All Modern Browsers such as Firefox, Chrome, Edge, and Safari.

Internet Explorer 11 support is possible if you include polyfills for closest and NodeList.forEach and transpile your code with something like Babel.

Expected Markup

<nav id="primary-nav"> <!-- element must have an ID -->
	<ul class="clicky-menu no-js">
		<li>
			<a href="#">Menu Item 1</a>
			<ul>
				<li><a href="page-1a.html">Menu Item 1a</a></li>
				<li><a href="page-1b.html">Menu Item 1b</a></li>
				<li><a href="page-1c.html">Menu Item 1c</a></li>
			</ul>
		</li>
		<--! etc… -->
	</ul>
</nav>

Setup

Include click-menus.js anywhere in the DOM and clicky-menus.css in the <head>.

Changelog

1.0.0

  • It's alive!
Comments
  • Would you consider dual-licensing your code under MIT/BSD?

    Would you consider dual-licensing your code under MIT/BSD?

    Thank you for this nice click-menu. Your reasoning on CSS-Tricks resonates with me and I would like to use this in one of my projects.

    While I am not anti-GPL, I would like to ask whether you could consider to license it (also) under a permissive license such as MIT or BSD? I absolutely don't mind anyone to copy and adapt our HTML/CSS/JS. But GPL forces us to always check that we we do not combine it with code under a conflicting license.

    opened by utrenkner 4
  • Generate id based on attribute, not anchor text

    Generate id based on attribute, not anchor text

    It is necessary to change the way in which the ids of the submenus are generated .. it is better to be based on the id of the parent or the container div ... currently it is based on the text of the link that has the submenu but it causes problems when you have the same menu in two different parts of the website.

    aria

    opened by juanjosezg 2
  • Submenu does not close when clicking a top-level anchor link

    Submenu does not close when clicking a top-level anchor link

    The demo features a main menu entry "home" without a submenu. If any submenu is expanded, a click on the main menu entry without submenu leaves it open.

    Example: I click on "Services" and the relative sub-menu is expanded. When I then click on "Home" the Services-sub-menu remains expanded. This is an issue only if you are already on the "Home" page, however. In any other case, a click would lead you to another page.

    I did not find in the JavaScript, which code prevents a click on Home to contract the other sub-menu. Should not be difficult to fix, though.

    bug 
    opened by utrenkner 2
  • Feature request: close on scrolling away

    Feature request: close on scrolling away

    Feature Request

    It would be really useful if the menu would close itself when the user starts scrolling down. For example, this scenario:

    1. User opens a dropdown
    2. User starts to scroll down the page without closing the menu
    3. The menu closes itself because the user started scrolling away without clicking on anything.
    opened by ajplopez 1
  • Fix CSS-only fallback

    Fix CSS-only fallback

    ul's need to be set visibility: visible on hover, focus-within - to override visibility: hidden in line 8.

    Alternatively, we could change line 8 to display: none

    opened by utrenkner 1
  • Change license from GPL to MIT

    Change license from GPL to MIT

    The MIT License is used by the vast majority of front-end code and frame-works (Bootstrap, Tailwindcss, React, Vue, Alpine,...) because it frees the user from thinking twice about the legal implications.

    opened by utrenkner 0
  • Don't require ID on menu parent

    Don't require ID on menu parent

    Currently the script will fail if the menu's parent element doesn't have an ID set. This is small issue, but this seems like an unnecessary requirement. The script could automatically set an ID if one doesn't exist.

    opened by mrwweb 0
  • Generate ID / aria-controls in a way that doesn't result in potentially invalid attribute characters

    Generate ID / aria-controls in a way that doesn't result in potentially invalid attribute characters

    Right now, the way the ID for each submenu is generated can pull in special characters, probably including those that might be invalid. For example, here's one from a site I'm working on right now: exhibitions-|-collections-submenu. The solution is to either drop any characters other than numbers and letters or switch to something that is guaranteed to be unique. I just updated the script to ensure submenu IDs are unique per-menu (see #11), so I should probably switch to something that is also unique per-menu-item.

    bug good first issue 
    opened by mrwweb 0
  • Include animations in demo

    Include animations in demo

    I feels stupid myself. You've noted that "using visibility instead of display allows for easier transitions and animation of submenus". So I've playing with your demo and trying to add animation/transition to icon and submenu, but I couldn't make it work. Could you please add some animation as example?

    documentation enhancement demo 
    opened by 7Narwen 2
  • Consider support for multiple levels of submenu

    Consider support for multiple levels of submenu

    While I don't like it, it would make the script more useful to more people if this supported multiple levels of submenus. That said, doing then must not come at the expense of being able to make "mega menus" that show nested lists within the top-level submenu. Therefore, the secondary submenu feature would need to be configurable in a way that makes it opt-in.

    opened by mrwweb 1
  • Gap above submenu breaks menu in CSS-only use

    Gap above submenu breaks menu in CSS-only use

    The demo code features a gap between the main menu and the sub-menu. With CSS-only this makes it difficult to click on an entry in the sub-menu because the sub-menu disappears when moving the cursor over the gap.

    opened by utrenkner 1
  • Feature: Make submenu selector configurable

    Feature: Make submenu selector configurable

    Right now, the script will select any nested <ul> and treat it as a submenu. It would be good to allow passing a custom selector for cases where that might not be the desired behavior.

    opened by mrwweb 1
Owner
Mark Root-Wiley
WordPress websites for nonprofits in Seattle, WA. Created NonprofitWP.org for low-budget nonprofits needing free WordPress guidance.
Mark Root-Wiley
A progressively enhanced server-rendered form-aware web component counter using WebC

Eleventy WebC Number Counter Demo A progressively enhanced server-rendered form-aware web component counter using WebC. This enhances from an <input t

Eleventy 6 Nov 11, 2022
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021
High performance and SEO friendly lazy loader for images (responsive and normal), iframes and more, that detects any visibility changes triggered through user interaction, CSS or JavaScript without configuration.

lazysizes lazysizes is a fast (jank-free), SEO-friendly and self-initializing lazyloader for images (including responsive images picture/srcset), ifra

Alexander Farkas 16.6k Jan 1, 2023
CSS-based animations triggered by JS, defined in your stylesheet

Anim-x CSS-based animations triggered by JS, defined in your stylesheet. $ npm i https://github.com/LTBL-Studio/anim-x.git Quick start An animation is

LTBL 2 Sep 29, 2021
An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone.

An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone

Andy 44 Dec 30, 2022
jSide Menu is a well designed, simple and clean side navigation menu with dropdowns.

jQuery jSide Menu jSide Menu is a well designed, simple and clean side navigation menu with dropdowns. Browse: Live Demo & Using Guide Main Features F

CodeHim 24 Feb 14, 2022
A Drag-and-Drop library for all JavaScript frameworks implementing an enhanced transformation mechanism to manipulate DOM elements

JavaScript Project to Manipulate DOM Elements DFlex A Drag-and-Drop library for all JavaScript frameworks implementing an enhanced transformation mech

DFlex 1.5k Jan 8, 2023
Enhanced interval features for Node.js, such as promisified interval and human readable time parsing.

Interval-next Interval-next is a package that extends Javascript's built-in setInterval() capabilities. You have a plain and promisified interval meth

Snowy 5 Jul 28, 2022
An enhanced HTML 5 file input for Bootstrap 5.x/4.x./3.x with file preview, multiple selection, and more features.

bootstrap-fileinput An enhanced HTML 5 file input for Bootstrap 5.x, 4.x, and 3.x with file preview for various files, offers multiple selection, resu

Kartik Visweswaran 5.2k Jan 3, 2023
Enhanced Sanity.io plugin development experience.

@sanity/plugin-kit NOTE This is a developer preview package meant for Sanity Studio v3 plugin development. For a v2 alternative, consider using Sanipa

Sanity 40 Dec 27, 2022
An enhanced VSCode extension for the Move programming language.

Move Analyzer Plus Provides language support for the Move programming language. Install on the VSCode Extension Marketplace: Move Analyzer Plus on the

The Moving Company 10 Aug 12, 2022
This is a toy, it is an enhanced version of console.log

uu-console Hi, this is a toy. When you use console.log to print some logs, this can help you do some useless things. What is uu-console Support built-

KK Liu 2 Sep 25, 2022
The classical game of Liar's Dice enhanced with the usage of Zero-Knowledge Proof

Liar's Dice An online multiplayer game showcasing the potential of Aleo's Zero Knowledge Proof platform. Local deployment Prerequisites Setup dnsmasq

Kryha 4 Dec 15, 2022
The classical game of Liar's Dice enhanced with the usage of Zero-Knowledge Proof

Liar's Dice An online multiplayer game showcasing the potential of Aleo's Zero Knowledge Proof platform. Local deployment Prerequisites Setup dnsmasq

Kryha 3 Oct 20, 2022
Simple, fast, accessible accordion library with no dependency

React Fast Accordion ⚡️ Dynamic, fast, accessible & zero dependency accordion for React How it's fast? Instead of adding event listener on all the ite

Shivam 59 Oct 8, 2022
🍭 search-buddy ultra lightweight javascript plugin that can help you create instant search and/or facilitate navigation between pages.

?? search-buddy search-buddy is an open‑source ultra lightweight javascript plugin (* <1kb). It can help you create instant search and/or facilitate n

Michael 4 Jun 16, 2022
Responsive navigation plugin without library dependencies and with fast touch screen support.

Responsive Nav Responsive navigation plugin without library dependencies and with fast touch screen support. Responsive Nav is a tiny JavaScript plugi

Viljami Salminen 4.1k Dec 29, 2022
It's a tiny freeware library on TypeScript to sinhronize page scrolling and navigation meny-bar.

Scroll progress (dual-side-scroll) v1.2.3 Assignment This tiny plugin is designed to show the progress of the page scrolling interactively. There are

Evgeny 4 May 17, 2022
jQuery plugin to show a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML pages.

jquery.simpletabs v1.2.3 The jquery.simpletabs plugin shows a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML p

Peter Thoeny 1 Feb 23, 2022