From d4a08deb108f081e80eded4e8afbf20394a0b48b Mon Sep 17 00:00:00 2001 From: mister-ben Date: Tue, 11 May 2021 00:28:31 +0200 Subject: [PATCH] fix: Don't hide menus with one item and a title (#7215) Menus with one item are hidden if they have a title, because adding the title increments the hide threshold, but the title is not counted as an item. e.g. the chapters menu if there is a single chapter. --- src/js/menu/menu-button.js | 2 -- test/unit/menu.test.js | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/js/menu/menu-button.js b/src/js/menu/menu-button.js index ce523fa08..c341d45f7 100644 --- a/src/js/menu/menu-button.js +++ b/src/js/menu/menu-button.js @@ -120,8 +120,6 @@ class MenuButton extends Component { tabIndex: -1 }); - this.hideThreshold_ += 1; - const titleComponent = new Component(this.player_, {el: titleEl}); menu.addItem(titleComponent); diff --git a/test/unit/menu.test.js b/test/unit/menu.test.js index 7f07e8b0e..eca8f1e0e 100644 --- a/test/unit/menu.test.js +++ b/test/unit/menu.test.js @@ -43,6 +43,24 @@ QUnit.test('should place title list item into ul', function(assert) { player.dispose(); }); +QUnit.test('should not include menu title in hide threshold', function(assert) { + const player = TestHelpers.makePlayer(); + + const menuButton = new MenuButton(player, { + title: 'testTitle' + }); + + assert.strictEqual(menuButton.hideThreshold_, 0, 'title should not increment hideThreshold_'); + + menuButton.createItems = () => [new MenuItem(player, { label: 'menu-item1' })]; + menuButton.update(); + + assert.strictEqual(menuButton.hasClass('vjs-hidden'), false, 'menu button with single (non-title) item is not hidden'); + + menuButton.dispose(); + player.dispose(); +}); + QUnit.test('clicking should display the menu', function(assert) { assert.expect(6);