fix(ui): keep mega menu open across hover gap
This commit is contained in:
@@ -44,6 +44,7 @@ component MegaMenu {
|
||||
}
|
||||
|
||||
state visible = defaultOpen
|
||||
state closeTimer = null
|
||||
|
||||
functions {
|
||||
shared function columnList() {
|
||||
@@ -59,15 +60,32 @@ component MegaMenu {
|
||||
}
|
||||
|
||||
client function showPanel(sourceEvent) {
|
||||
cancelScheduledHide()
|
||||
visible = true
|
||||
output.open({ sourceEvent: sourceEvent })
|
||||
}
|
||||
|
||||
client function hidePanel(reason) {
|
||||
cancelScheduledHide()
|
||||
visible = false
|
||||
output.close({ reason: reason })
|
||||
}
|
||||
|
||||
client function cancelScheduledHide() {
|
||||
if (closeTimer) {
|
||||
window.clearTimeout(closeTimer)
|
||||
closeTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
client function scheduleHide() {
|
||||
cancelScheduledHide()
|
||||
closeTimer = window.setTimeout(function () {
|
||||
closeTimer = null
|
||||
hidePanel("pointer-leave")
|
||||
}, 220)
|
||||
}
|
||||
|
||||
client function togglePanel(sourceEvent) {
|
||||
if (visible) {
|
||||
hidePanel("toggle")
|
||||
@@ -121,7 +139,8 @@ component MegaMenu {
|
||||
data-full-width='{fullWidth ? "true" : "false"}'
|
||||
data-column-count='{columnCount}'
|
||||
@keydown='handleKeydown(event)'
|
||||
@mouseleave='hidePanel("pointer-leave")'
|
||||
@mouseenter='cancelScheduledHide()'
|
||||
@mouseleave='scheduleHide()'
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
@@ -141,6 +160,7 @@ component MegaMenu {
|
||||
data-wrn-anchored="true"
|
||||
data-show="visible"
|
||||
data-wrn-roving="both"
|
||||
@mouseenter='cancelScheduledHide()'
|
||||
>
|
||||
<div class="wrn-mega__layout">
|
||||
{#if railList().length > 0}
|
||||
@@ -278,7 +298,7 @@ component MegaMenu {
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 100%;
|
||||
height: 0.6rem;
|
||||
height: 0.85rem;
|
||||
}
|
||||
|
||||
.wrn-mega__panel {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/ui",
|
||||
"version": "0.8.31",
|
||||
"version": "0.8.32",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
|
||||
@@ -3133,6 +3133,15 @@ test("mega menu keeps hover activation and click activation from cancelling each
|
||||
expect(source).toContain("max-height: calc(100dvh - 5.5rem)");
|
||||
});
|
||||
|
||||
test("mega menu gives the pointer time to cross from its trigger into a floating panel", () => {
|
||||
const source = readFileSync(uiComponentPath("MegaMenu"), "utf8");
|
||||
expect(source).toContain("state closeTimer = null");
|
||||
expect(source).toContain("@mouseleave='scheduleHide()'");
|
||||
expect(source).toContain("@mouseenter='cancelScheduledHide()'");
|
||||
expect(source).toContain("}, 220)");
|
||||
expect(source).not.toContain('@mouseleave=\'hidePanel("pointer-leave")\'');
|
||||
});
|
||||
|
||||
test("navbar pins full-width mega panels to desktop viewport gutters", () => {
|
||||
const source = readFileSync(uiComponentPath("Navbar"), "utf8");
|
||||
expect(source).toMatch(/\.wrn-navbar__mega\[data-full-width="true"\] \.wrn-mega__panel \{[^}]*position: fixed/s);
|
||||
|
||||
Reference in New Issue
Block a user