77 endKeyDown ,
88 fixtureSync ,
99 homeKeyDown ,
10+ tabKeyDown ,
1011} from '@vaadin/testing-helpers' ;
1112import sinon from 'sinon' ;
1213import { html , PolymerElement } from '@polymer/polymer/polymer-element.js' ;
@@ -33,6 +34,10 @@ customElements.define(
3334 get _vertical ( ) {
3435 return this . hasAttribute ( 'vertical' ) ;
3536 }
37+
38+ get _tabNavigation ( ) {
39+ return this . hasAttribute ( 'tab-navigation' ) ;
40+ }
3641 } ,
3742) ;
3843
@@ -86,11 +91,22 @@ describe('keyboard-direction-mixin', () => {
8691 expect ( element . focused ) . to . be . equal ( items [ 1 ] ) ;
8792 } ) ;
8893
89- it ( 'should move focus to prev element on "arrow-right " keydown in LTR' , ( ) => {
94+ it ( 'should move focus to prev element on "arrow-left " keydown in LTR' , ( ) => {
9095 arrowRightKeyDown ( items [ 0 ] ) ;
9196 arrowLeftKeyDown ( items [ 1 ] ) ;
9297 expect ( element . focused ) . to . be . equal ( items [ 0 ] ) ;
9398 } ) ;
99+
100+ it ( 'should move focus to last element on first element "arrow-left" keydown' , ( ) => {
101+ arrowLeftKeyDown ( items [ 0 ] ) ;
102+ expect ( element . focused ) . to . equal ( items [ 5 ] ) ;
103+ } ) ;
104+
105+ it ( 'should move focus to first element on last element "arrow-right" keydown' , ( ) => {
106+ arrowLeftKeyDown ( items [ 0 ] ) ;
107+ arrowRightKeyDown ( items [ 5 ] ) ;
108+ expect ( element . focused ) . to . equal ( items [ 0 ] ) ;
109+ } ) ;
94110 } ) ;
95111
96112 describe ( 'RTL' , ( ) => {
@@ -108,6 +124,17 @@ describe('keyboard-direction-mixin', () => {
108124 arrowRightKeyDown ( items [ 1 ] ) ;
109125 expect ( element . focused ) . to . be . equal ( items [ 0 ] ) ;
110126 } ) ;
127+
128+ it ( 'should move focus to last element on first element "arrow-right" keydown' , ( ) => {
129+ arrowRightKeyDown ( items [ 0 ] ) ;
130+ expect ( element . focused ) . to . equal ( items [ 5 ] ) ;
131+ } ) ;
132+
133+ it ( 'should move focus to first element on last element "arrow-left" keydown' , ( ) => {
134+ arrowRightKeyDown ( items [ 0 ] ) ;
135+ arrowLeftKeyDown ( items [ 5 ] ) ;
136+ expect ( element . focused ) . to . equal ( items [ 0 ] ) ;
137+ } ) ;
111138 } ) ;
112139 } ) ;
113140
@@ -189,4 +216,33 @@ describe('keyboard-direction-mixin', () => {
189216 } ) ;
190217 } ) ;
191218 } ) ;
219+
220+ describe ( 'Tab navigation' , ( ) => {
221+ beforeEach ( ( ) => {
222+ element . setAttribute ( 'tab-navigation' , '' ) ;
223+ element . focus ( ) ;
224+ } ) ;
225+
226+ it ( 'should move focus to next element on Tab keydown' , ( ) => {
227+ tabKeyDown ( items [ 0 ] ) ;
228+ expect ( element . focused ) . to . be . equal ( items [ 1 ] ) ;
229+ } ) ;
230+
231+ it ( 'should move focus to prev element on Shift + Tab keydown' , ( ) => {
232+ tabKeyDown ( items [ 0 ] ) ;
233+ tabKeyDown ( items [ 1 ] , [ 'shift' ] ) ;
234+ expect ( element . focused ) . to . be . equal ( items [ 0 ] ) ;
235+ } ) ;
236+
237+ it ( 'should not move focus to last element on first element Shift + Tab keydown' , ( ) => {
238+ tabKeyDown ( items [ 0 ] , [ 'shift' ] ) ;
239+ expect ( element . focused ) . to . not . equal ( items [ 5 ] ) ;
240+ } ) ;
241+
242+ it ( 'should not move focus to first element on last element Tab keydown' , ( ) => {
243+ items [ 5 ] . focus ( ) ;
244+ tabKeyDown ( items [ 5 ] ) ;
245+ expect ( element . focused ) . to . not . equal ( items [ 0 ] ) ;
246+ } ) ;
247+ } ) ;
192248} ) ;
0 commit comments