| 
									
										
										
										
											2018-03-28 19:24:49 -07:00
										 |  |  | import IvyTabsTablistComponent from 'ivy-tabs/components/ivy-tabs-tablist'; | 
					
						
							| 
									
										
										
										
											2018-06-25 23:42:28 -07:00
										 |  |  | import { noop } from 'wherehows-web/utils/helpers/functions'; | 
					
						
							| 
									
										
										
										
											2018-03-28 19:24:49 -07:00
										 |  |  | import { scheduleOnce } from '@ember/runloop'; | 
					
						
							| 
									
										
										
										
											2018-08-17 11:58:47 -07:00
										 |  |  | import { Keyboard } from 'wherehows-web/constants/keyboard'; | 
					
						
							| 
									
										
										
										
											2018-03-28 19:24:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default IvyTabsTablistComponent.extend({ | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Overwrites the ofiginal ivy-tabs-tablist component's on('keydown') method, which lets the | 
					
						
							|  |  |  |    * user navigate through the tabs using the arrow keys. As we don't want up and down arrows | 
					
						
							|  |  |  |    * to interfere with page scroll, we change this to a noop function. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   navigateOnKeyDown: noop, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Using the more modern approach to handling component events, we include the functionality | 
					
						
							|  |  |  |    * to scroll between tabs with the left and right arrow keys. This way, the user can scroll | 
					
						
							|  |  |  |    * between tabs with the left/right keys and use the up/down keys to scroll the page, without | 
					
						
							|  |  |  |    * interruption | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   keyDown(event: KeyboardEvent) { | 
					
						
							|  |  |  |     switch (event.keyCode) { | 
					
						
							| 
									
										
										
										
											2018-08-17 11:58:47 -07:00
										 |  |  |       case Keyboard.ArrowLeft: | 
					
						
							| 
									
										
										
										
											2018-03-28 19:24:49 -07:00
										 |  |  |         this.selectPreviousTab(); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2018-08-17 11:58:47 -07:00
										 |  |  |       case Keyboard.ArrowRight: | 
					
						
							| 
									
										
										
										
											2018-03-28 19:24:49 -07:00
										 |  |  |         this.selectNextTab(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     event.preventDefault(); | 
					
						
							|  |  |  |     scheduleOnce('afterRender', this, this.focusSelectedTab); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); |