@@ -102,6 +102,58 @@ describe('VOtpInput', () => {
102102 expect ( getActiveSlotIndex ( ) ) . toBe ( 2 )
103103 } )
104104
105+ it ( 'navigates using arrows it in rtl' , async ( ) => {
106+ render ( ( ) => ( < VOtpInput length = { 6 } /> ) , null , {
107+ locale : { rtl : { en : true } } ,
108+ } )
109+
110+ await focusInput ( )
111+ await userEvent . keyboard ( '1234' )
112+ expect ( getActiveSlotIndex ( ) ) . toBe ( 4 )
113+
114+ for ( const expected of [ 3 , 2 , 1 , 0 ] ) {
115+ await userEvent . keyboard ( '{ArrowRight}' )
116+ expect ( getActiveSlotIndex ( ) ) . toBe ( expected )
117+ }
118+
119+ await userEvent . keyboard ( '{ArrowRight}' ) // overshoot, no-op
120+ expect ( getActiveSlotIndex ( ) ) . toBe ( 0 )
121+
122+ for ( const expected of [ 1 , 2 ] ) {
123+ await userEvent . keyboard ( '{ArrowLeft}' )
124+ expect ( getActiveSlotIndex ( ) ) . toBe ( expected )
125+ }
126+
127+ await userEvent . keyboard ( '{Delete}' )
128+ expect ( getInput ( ) . value ) . toBe ( '124' )
129+ expect ( getActiveSlotIndex ( ) ) . toBe ( 2 )
130+ } )
131+
132+ it ( 'navigates using arrows it in ltr' , async ( ) => {
133+ render ( ( ) => ( < VOtpInput length = { 6 } /> ) )
134+
135+ await focusInput ( )
136+ await userEvent . keyboard ( '1234' )
137+ expect ( getActiveSlotIndex ( ) ) . toBe ( 4 )
138+
139+ for ( const expected of [ 3 , 2 , 1 , 0 ] ) {
140+ await userEvent . keyboard ( '{ArrowLeft}' )
141+ expect ( getActiveSlotIndex ( ) ) . toBe ( expected )
142+ }
143+
144+ await userEvent . keyboard ( '{ArrowLeft}' ) // overshoot, no-op
145+ expect ( getActiveSlotIndex ( ) ) . toBe ( 0 )
146+
147+ for ( const expected of [ 1 , 2 ] ) {
148+ await userEvent . keyboard ( '{ArrowRight}' )
149+ expect ( getActiveSlotIndex ( ) ) . toBe ( expected )
150+ }
151+
152+ await userEvent . keyboard ( '{Delete}' )
153+ expect ( getInput ( ) . value ) . toBe ( '124' )
154+ expect ( getActiveSlotIndex ( ) ) . toBe ( 2 )
155+ } )
156+
105157 it ( 'removes value and goes back when using backspace' , async ( ) => {
106158 render ( ( ) => ( < VOtpInput /> ) )
107159 const input = getInput ( )
0 commit comments