From 2dcada103c7f0c62617d1111c1880f2fdc85df32 Mon Sep 17 00:00:00 2001 From: usmanonazim Date: Tue, 21 Mar 2023 11:42:23 +0000 Subject: [PATCH] hide menu button on click after hover --- src/js/menu/menu-button.js | 20 +++++++++++++++----- test/unit/menu/menu-button.test.js | 13 +++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/unit/menu/menu-button.test.js diff --git a/src/js/menu/menu-button.js b/src/js/menu/menu-button.js index 7b8ad9aa3..274b48626 100644 --- a/src/js/menu/menu-button.js +++ b/src/js/menu/menu-button.js @@ -58,11 +58,7 @@ class MenuButton extends Component { this.on(this.menuButton_, 'tap', handleClick); this.on(this.menuButton_, 'click', handleClick); this.on(this.menuButton_, 'keydown', (e) => this.handleKeyDown(e)); - this.on(this.menuButton_, 'mouseenter', () => { - this.addClass('vjs-hover'); - this.menu.show(); - Events.on(document, 'keyup', this.handleMenuKeyUp_); - }); + this.on('mouseenter', (e) => this.handleMouseEnter(e)); this.on('mouseleave', (e) => this.handleMouseLeave(e)); this.on('keydown', (e) => this.handleSubmenuKeyDown(e)); } @@ -263,6 +259,20 @@ class MenuButton extends Component { Events.off(document, 'keyup', this.handleMenuKeyUp_); } + /** + * + * @param {Event} event + * The `mouseenter` event that caused this function to be called. + * + * @listens mouseenter + */ + handleMouseEnter(event) { + this.addClass('vjs-hover'); + this.buttonPressed_ = true; + this.menu.show(); + Events.on(document, 'keyup', this.handleMenuKeyUp_); + } + /** * Set the focus to the actual button, not to this element */ diff --git a/test/unit/menu/menu-button.test.js b/test/unit/menu/menu-button.test.js new file mode 100644 index 000000000..3b40fd9c2 --- /dev/null +++ b/test/unit/menu/menu-button.test.js @@ -0,0 +1,13 @@ +/* eslint-env qunit */ +import TestHelpers from '../test-helpers.js'; + +QUnit.module('MenuButton', { + beforeEach(assert) { + this.player = TestHelpers.makePlayer({ + + }); + }, + afterEach(assert) { + this.player.dispose(); + } +});