mirror of
				https://github.com/videojs/video.js.git
				synced 2025-10-31 00:08:01 +02:00 
			
		
		
		
	@llun fixed menus from throwing when focused when empty. closes #3218
This commit is contained in:
		
				
					committed by
					
						 Gary Katsevman
						Gary Katsevman
					
				
			
			
				
	
			
			
			
						parent
						
							6845cbedc3
						
					
				
				
					commit
					31b2f9d489
				
			| @@ -2,7 +2,7 @@ CHANGELOG | |||||||
| ========= | ========= | ||||||
|  |  | ||||||
| ## HEAD (Unreleased) | ## HEAD (Unreleased) | ||||||
| _(none)_ | * @llun fixed menus from throwing when focused when empty ([view](https://github.com/videojs/video.js/pull/3218)) | ||||||
|  |  | ||||||
| -------------------- | -------------------- | ||||||
|  |  | ||||||
|   | |||||||
| @@ -118,14 +118,13 @@ class Menu extends Component { | |||||||
|    */ |    */ | ||||||
|   focus (item = 0) { |   focus (item = 0) { | ||||||
|     let children = this.children().slice(); |     let children = this.children().slice(); | ||||||
|     let haveTitle = children[0].className && |     let haveTitle = children.length && children[0].className && | ||||||
|       /vjs-menu-title/.test(children[0].className); |       /vjs-menu-title/.test(children[0].className); | ||||||
|  |  | ||||||
|     if (haveTitle) { |     if (haveTitle) { | ||||||
|       children.shift(); |       children.shift(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     if (children.length > 0) { |     if (children.length > 0) { | ||||||
|       if (item < 0) { |       if (item < 0) { | ||||||
|         item = 0; |         item = 0; | ||||||
|   | |||||||
| @@ -1,11 +1,27 @@ | |||||||
| import MenuButton from '../../src/js/menu/menu-button.js'; | import MenuButton from '../../src/js/menu/menu-button.js'; | ||||||
| import TestHelpers from './test-helpers.js'; | import TestHelpers from './test-helpers.js'; | ||||||
|  | import * as Events from '../../src/js/utils/events.js'; | ||||||
|  |  | ||||||
| q.module('MenuButton'); | q.module('MenuButton'); | ||||||
|  |  | ||||||
| test('should place title list item into ul', function() { | q.test('should not throw an error when there is no children', function() { | ||||||
|   var player, menuButton; |   expect(0); | ||||||
|  |   let player = TestHelpers.makePlayer(); | ||||||
|  |  | ||||||
|  |   let menuButton = new MenuButton(player); | ||||||
|  |   let el = menuButton.el(); | ||||||
|  |  | ||||||
|  |   try { | ||||||
|  |     Events.trigger(el, 'click'); | ||||||
|  |   } catch (error) { | ||||||
|  |     ok(!error, 'click should not throw anything'); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   player.dispose(); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | q.test('should place title list item into ul', function() { | ||||||
|  |   var player, menuButton; | ||||||
|   player = TestHelpers.makePlayer(); |   player = TestHelpers.makePlayer(); | ||||||
|  |  | ||||||
|   menuButton = new MenuButton(player, { |   menuButton = new MenuButton(player, { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user