Bulma navbar dropdown with is-hoverable does not open on touch devices
0 reputation · 11 May 2025, 04:07 UTC
0 reputation · 11 May 2025, 04:07 UTC
A Bulma navbar dropdown marked with the is-hoverable modifier opens on desktop hover but does not open when tapped on touch devices. The goal is to restore tap-to-open behavior on mobile while keeping a usable interaction for desktop users, without introducing a JavaScript dependency or breaking keyboard accessibility.
Because Bulma is a CSS-only framework, the navbar dropdown relies on default hover and click states rather than scripted pointer detection. The is-hoverable modifier forces the dropdown to appear only on :hover, which removes the default click-to-open fallback that touch browsers otherwise use. Bulma exposes the is-active class on the parent navbar-item as a mechanism for programmatic control, but toggling that class requires custom JavaScript. Teams therefore face a choice between removing the modifier and accepting a less responsive desktop hover experience, or keeping it and losing touch support.
Should the is-hoverable modifier be removed to rely on Bulma's default click-to-open behavior, or is the is-active class with a minimal JavaScript toggle the supported path? How do current Bulma versions expect keyboard users to access these dropdowns when hover-only styles are in play?
35275 reputation · 11 May 2025, 11:21 UTC
is-active class. Removing the is-hoverable modifier will break the desktop hover experience.
Bulma is a CSS-only framework. When is-hoverable is applied, Bulma uses the CSS :hover pseudo-class to display the dropdown. On touch devices, 'hover' states are ambiguous; browsers often simulate them on the first tap, but they frequently fail to maintain that state for subsequent interactions, or they may trigger the link's href immediately instead of opening the menu.
The is-hoverable modifier overrides the default interaction logic. In a standard Bulma navbar, the dropdown is toggled by the is-active class being added to the parent navbar-item. Because Bulma does not include its own JavaScript to manage this class, the is-hoverable modifier is essentially a CSS-only shortcut that assumes only pointer-based devices.
The most robust approach is to keep is-hoverable for desktop users but use a small script to toggle the is-active class for touch-based interactions. This ensures mobile users get a functional menu while desktop users keep their hover.
is-hoverable class on your HTML.navbar-item.is-active class only if the device is identified as a touch device.// Simple implementation to toggle dropdowns on touch
document.querySelectorAll('.navbar-item.is-hoverable').forEach(item => {
item.addEventListener('click', (e) => {
// Only toggle if it's a touch device to prevent breaking desktop hover
if (window.matchMedia("(pointer: coarse)").matches) {
e.preventDefault();
item.classList.toggle('is-active');
}
});
});;
Regarding keyboard users: Bulma's is-hoverable menus are notoriously inaccessible via keyboard because :hover does not trigger on focus. To fix this without a heavy library, you should ensure your CSS includes a focus-within rule:
/* Add this to your stylesheet to ensure keyboard users can navigate */
.navbar-item.is-hoverable:focus-within .navbar-dropdown {
display: block;
}
Diagnostic Question: Are you using a framework like React or Vue to manage these classes, which would change how we handle the state of the is-active class?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.