@@ -2119,6 +2119,145 @@ QUnit.module('format: caret boundaries', moduleConfig, () => {
21192119 } ) ;
21202120} ) ;
21212121
2122+ QUnit . module ( 'format: scroll position on boundary keys (T1330133)' , {
2123+ beforeEach : function ( ) {
2124+ moduleConfig . beforeEach . call ( this ) ;
2125+
2126+ this . scrollState = { scrollWidth : 200 , scrollLeft : 0 } ;
2127+
2128+ Object . defineProperty ( this . inputElement , 'scrollWidth' , {
2129+ get : ( ) => this . scrollState . scrollWidth ,
2130+ configurable : true ,
2131+ } ) ;
2132+
2133+ Object . defineProperty ( this . inputElement , 'scrollLeft' , {
2134+ get : ( ) => this . scrollState . scrollLeft ,
2135+ set : ( value ) => { this . scrollState . scrollLeft = value ; } ,
2136+ configurable : true ,
2137+ } ) ;
2138+
2139+ this . assertScrolledTo = ( assert , expected , message ) => {
2140+ const actual = expected === 'end' ? this . scrollState . scrollWidth : 0 ;
2141+ assert . strictEqual ( this . scrollState . scrollLeft , actual , message ) ;
2142+ } ;
2143+ } ,
2144+ afterEach : function ( ) {
2145+ delete this . inputElement . scrollLeft ;
2146+ delete this . inputElement . scrollWidth ;
2147+ moduleConfig . afterEach . call ( this ) ;
2148+ }
2149+ } , ( ) => {
2150+ QUnit . module ( 'arrow keys' , ( ) => {
2151+ QUnit . test ( 'left arrow at the start boundary scrolls the input to the start edge so the minus sign becomes visible (T1330133)' , function ( assert ) {
2152+ this . instance . option ( {
2153+ format : '#,##0.00' ,
2154+ value : - 4589999.89 ,
2155+ } ) ;
2156+
2157+ this . scrollState . scrollLeft = 50 ;
2158+ this . keyboard . caret ( 1 ) . keyDown ( 'left' ) ;
2159+
2160+ assert . ok ( this . keyboard . event . isDefaultPrevented ( ) , 'default is still prevented' ) ;
2161+ assert . deepEqual ( this . keyboard . caret ( ) , { start : 1 , end : 1 } , 'caret stays on the start boundary' ) ;
2162+ this . assertScrolledTo ( assert , 'start' , 'input is scrolled to the start edge' ) ;
2163+ } ) ;
2164+
2165+ QUnit . test ( 'left arrow at the prefix-stub boundary scrolls the input to the start edge' , function ( assert ) {
2166+ this . instance . option ( {
2167+ format : '$#' ,
2168+ value : 1 ,
2169+ } ) ;
2170+
2171+ this . scrollState . scrollLeft = 50 ;
2172+ this . keyboard . caret ( 1 ) . keyDown ( 'left' ) ;
2173+
2174+ assert . ok ( this . keyboard . event . isDefaultPrevented ( ) , 'default is still prevented' ) ;
2175+ this . assertScrolledTo ( assert , 'start' , 'input is scrolled so the prefix stub becomes visible' ) ;
2176+ } ) ;
2177+
2178+ QUnit . test ( 'right arrow at the end boundary scrolls the input to the end edge' , function ( assert ) {
2179+ this . instance . option ( {
2180+ format : '#d' ,
2181+ value : 1 ,
2182+ } ) ;
2183+
2184+ this . scrollState . scrollLeft = 0 ;
2185+ this . keyboard . caret ( 1 ) . keyDown ( 'right' ) ;
2186+
2187+ assert . ok ( this . keyboard . event . isDefaultPrevented ( ) , 'default is still prevented' ) ;
2188+ this . assertScrolledTo ( assert , 'end' , 'input is scrolled to the end edge' ) ;
2189+ } ) ;
2190+
2191+ QUnit . test ( 'arrow key within boundaries does not adjust the scroll position' , function ( assert ) {
2192+ this . instance . option ( {
2193+ format : '#,##0.00' ,
2194+ value : - 4589999.89
2195+ } ) ;
2196+
2197+ this . scrollState . scrollLeft = 42 ;
2198+ this . keyboard . caret ( 5 ) . keyDown ( 'left' ) ;
2199+
2200+ assert . notOk ( this . keyboard . event . isDefaultPrevented ( ) , 'default is not prevented inside the boundaries' ) ;
2201+ assert . strictEqual ( this . scrollState . scrollLeft , 42 , 'scroll position is not adjusted' ) ;
2202+ } ) ;
2203+ } ) ;
2204+
2205+ QUnit . module ( 'Home, End keys' , ( ) => {
2206+ QUnit . test ( 'Home scrolls the input to the start edge so the prefix becomes visible (T1330133)' , function ( assert ) {
2207+ this . instance . option ( {
2208+ format : '#,##0.00' ,
2209+ value : - 4589999.89 ,
2210+ } ) ;
2211+
2212+ this . scrollState . scrollLeft = 50 ;
2213+ this . keyboard . caret ( 13 ) . keyDown ( 'home' ) ;
2214+
2215+ assert . deepEqual ( this . keyboard . caret ( ) , { start : 1 , end : 1 } , 'caret is on the start boundary' ) ;
2216+ this . assertScrolledTo ( assert , 'start' , 'input is scrolled so the minus sign becomes visible' ) ;
2217+ } ) ;
2218+
2219+ QUnit . test ( 'End scrolls the input to the end edge so the trailing digits become visible (T1330133)' , function ( assert ) {
2220+ this . instance . option ( {
2221+ format : '#,##0.00' ,
2222+ value : - 4589999.89 ,
2223+ } ) ;
2224+
2225+ this . scrollState . scrollLeft = 0 ;
2226+ this . keyboard . caret ( 1 ) . keyDown ( 'end' ) ;
2227+
2228+ assert . deepEqual ( this . keyboard . caret ( ) , { start : 13 , end : 13 } , 'caret is on the end boundary' ) ;
2229+ this . assertScrolledTo ( assert , 'end' , 'input is scrolled so the trailing digits become visible' ) ;
2230+ } ) ;
2231+
2232+ [ 'home' , 'end' ] . forEach ( ( key ) => {
2233+ QUnit . test ( `shift+${ key } does not adjust the scroll position` , function ( assert ) {
2234+ this . scrollState . scrollLeft = 30 ;
2235+ this . keyboard . keyDown ( key , { shiftKey : true } ) ;
2236+
2237+ assert . strictEqual ( this . scrollState . scrollLeft , 30 , 'scroll position is not adjusted' ) ;
2238+ } ) ;
2239+ } ) ;
2240+ } ) ;
2241+
2242+ QUnit . module ( 'focus-in semantics' , ( ) => {
2243+ QUnit . test ( 'focus on integer-only format does not force-scroll the input to a boundary' , function ( assert ) {
2244+ this . instance . option ( {
2245+ format : '#,##0' ,
2246+ value : - 4589999 ,
2247+ } ) ;
2248+
2249+ this . scrollState . scrollLeft = 42 ;
2250+
2251+ this . input . focus ( ) ;
2252+ this . clock . tick ( CARET_TIMEOUT_DURATION ) ;
2253+
2254+ assert . notStrictEqual ( this . scrollState . scrollLeft , this . scrollState . scrollWidth , 'scroll is not forced to the end edge on focus' ) ;
2255+ assert . notStrictEqual ( this . scrollState . scrollLeft , 0 , 'scroll is not forced to the start edge on focus' ) ;
2256+ assert . strictEqual ( this . scrollState . scrollLeft , 42 , 'scroll position is left to the browser' ) ;
2257+ } ) ;
2258+ } ) ;
2259+ } ) ;
2260+
21222261QUnit . module ( 'format: custom parser and formatter' , moduleConfig , ( ) => {
21232262 QUnit . test ( 'custom parser and formatter should work' , function ( assert ) {
21242263 this . instance . option ( {
0 commit comments