mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 23:44:48 +08:00
DEV: Listen for escape key on hamburger & user menu (#18629)
This commit is contained in:
@ -400,4 +400,12 @@ export default createWidget("hamburger-menu", {
|
|||||||
this.sendWidgetAction("toggleHamburger");
|
this.sendWidgetAction("toggleHamburger");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
keyDown(e) {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
this.sendWidgetAction("toggleHamburger");
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -313,6 +313,14 @@ export default createWidget("user-menu", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
keyDown(e) {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
this.sendWidgetAction("toggleUserMenu");
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
quickAccess(type) {
|
quickAccess(type) {
|
||||||
if (this.state.currentQuickAccess !== type) {
|
if (this.state.currentQuickAccess !== type) {
|
||||||
this.state.currentQuickAccess = type;
|
this.state.currentQuickAccess = type;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
acceptance,
|
acceptance,
|
||||||
|
exists,
|
||||||
query,
|
query,
|
||||||
updateCurrentUser,
|
updateCurrentUser,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { click, visit } from "@ember/test-helpers";
|
import { click, triggerKeyEvent, visit } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
acceptance(
|
acceptance(
|
||||||
@ -26,3 +27,12 @@ acceptance(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
acceptance("Hamburger Menu accessibility", function () {
|
||||||
|
test("Escape key closes hamburger menu", async function (assert) {
|
||||||
|
await visit("/");
|
||||||
|
await click("#toggle-hamburger-menu");
|
||||||
|
await triggerKeyEvent(".hamburger-panel", "keydown", "Escape");
|
||||||
|
assert.ok(!exists(".hamburger-panel"), "Esc closes the hamburger panel");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user