Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix Escape handling in menus #8916

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/js/menu/menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
handleKeyDown(event) {

// Escape or Tab unpress the 'button'
if (event.key === 'Esc' || event.key === 'Tab') {
if (event.key === 'Escape' || event.key === 'Tab') {

Check warning on line 300 in src/js/menu/menu-button.js

View check run for this annotation

Codecov / codecov/patch

src/js/menu/menu-button.js#L300

Added line #L300 was not covered by tests
if (this.buttonPressed_) {
this.unpressButton();
}
Expand Down Expand Up @@ -328,7 +328,7 @@
*/
handleMenuKeyUp(event) {
// Escape hides popup menu
if (event.key === 'Esc' || event.key === 'Tab') {
if (event.key === 'Escape' || event.key === 'Tab') {

Check warning on line 331 in src/js/menu/menu-button.js

View check run for this annotation

Codecov / codecov/patch

src/js/menu/menu-button.js#L331

Added line #L331 was not covered by tests
this.removeClass('vjs-hover');
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@
*/
handleSubmenuKeyDown(event) {
// Escape or Tab unpress the 'button'
if (event.key === 'Esc' || event.key === 'Tab') {
if (event.key === 'Escape' || event.key === 'Tab') {
if (this.buttonPressed_) {
this.unpressButton();
}
Expand Down
20 changes: 19 additions & 1 deletion test/unit/menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ QUnit.test('should remove old event listeners when the menu item adds to the new

assert.ok(clickListenerSpy.calledOnce, 'click event listener should be called');
assert.strictEqual(clickListenerSpy.getCall(0).args[0].target, menuItem.el(), 'event target should be the `menuItem`');
assert.ok(unpressButtonSpy.calledOnce, '`menuButton`.`unpressButtion` has been called');
assert.ok(unpressButtonSpy.calledOnce, '`menuButton`.`unpressButton` has been called');
assert.ok(focusSpy.calledOnce, '`menuButton`.`focus` has been called');

unpressButtonSpy.restore();
Expand Down Expand Up @@ -265,3 +265,21 @@ QUnit.test('should remove old event listeners when the menu item adds to the new
oldMenu.dispose();
menuButton.dispose();
});

QUnit.test('Escape should close menu', function(assert) {
const player = TestHelpers.makePlayer();
const menuButton = new MenuButton(player, {});
const unpressButtonSpy = sinon.spy(menuButton, 'unpressButton');

menuButton.createItems = () => [new MenuItem(player, {})];
menuButton.update();
menuButton.handleClick(new window.PointerEvent('click'));
menuButton.menu.children()[0].el_.dispatchEvent(new window.KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true
}));

assert.ok(unpressButtonSpy.calledOnce, '`menuButton`.`unpressButton` has been called');

});
Loading