@@ -1798,15 +1798,93 @@ describe('igxCombo', () => {
17981798 fixture . detectChanges ( ) ;
17991799 expect ( firstVisibleItem . classList . contains ( CSS_CLASS_FOCUSED ) ) . toBeTruthy ( ) ;
18001800 } ) ) ;
1801- it ( 'should close the dropdown list on pressing Tab key' , fakeAsync ( ( ) => {
1801+ it ( 'should close the dropdown list on pressing Tab key and focus the next focusable element ' , fakeAsync ( ( ) => {
18021802 combo . toggle ( ) ;
18031803 fixture . detectChanges ( ) ;
18041804
18051805 const dropdownContent = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_CONTENT } ` ) ) ;
1806+ const dropdownList = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_DROPDOWNLIST_SCROLL } ` ) ) . nativeElement ;
1807+ UIInteractions . triggerEventHandlerKeyDown ( 'Tab' , dropdownContent ) ;
1808+ tick ( ) ;
1809+ fixture . detectChanges ( ) ;
1810+ expect ( combo . collapsed ) . toBeTruthy ( ) ;
1811+
1812+ combo . toggle ( ) ;
1813+ fixture . detectChanges ( ) ;
1814+ expect ( combo . collapsed ) . toBeFalsy ( ) ;
1815+
1816+ let focusedItems = dropdownList . querySelectorAll ( `.${ CSS_CLASS_FOCUSED } ` ) ;
1817+ let selectedItems = dropdownList . querySelectorAll ( `.${ CSS_CLASS_SELECTED } ` ) ;
1818+ expect ( focusedItems . length ) . toEqual ( 0 ) ;
1819+ expect ( selectedItems . length ) . toEqual ( 0 ) ;
1820+
1821+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , dropdownContent ) ;
1822+ fixture . detectChanges ( ) ;
1823+ focusedItems = dropdownList . querySelectorAll ( `.${ CSS_CLASS_FOCUSED } ` ) ;
1824+ expect ( focusedItems . length ) . toEqual ( 1 ) ;
1825+
18061826 UIInteractions . triggerEventHandlerKeyDown ( 'Tab' , dropdownContent ) ;
18071827 tick ( ) ;
18081828 fixture . detectChanges ( ) ;
18091829 expect ( combo . collapsed ) . toBeTruthy ( ) ;
1830+ expect ( document . activeElement ) . not . toEqual ( combo . comboInput . nativeElement ) ;
1831+
1832+ combo . toggle ( ) ;
1833+ fixture . detectChanges ( ) ;
1834+ expect ( combo . collapsed ) . toBeFalsy ( ) ;
1835+
1836+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , dropdownContent ) ;
1837+ fixture . detectChanges ( ) ;
1838+ focusedItems = dropdownList . querySelectorAll ( `.${ CSS_CLASS_FOCUSED } ` ) ;
1839+ expect ( focusedItems . length ) . toEqual ( 1 ) ;
1840+
1841+ UIInteractions . triggerEventHandlerKeyDown ( 'Space' , dropdownContent ) ;
1842+ fixture . detectChanges ( ) ;
1843+ selectedItems = dropdownList . querySelectorAll ( `.${ CSS_CLASS_SELECTED } ` ) ;
1844+ expect ( selectedItems . length ) . toEqual ( 1 ) ;
1845+
1846+ UIInteractions . triggerEventHandlerKeyDown ( 'Tab' , dropdownContent ) ;
1847+ tick ( ) ;
1848+ fixture . detectChanges ( ) ;
1849+ expect ( combo . collapsed ) . toBeTruthy ( ) ;
1850+ expect ( document . activeElement ) . not . toEqual ( combo . comboInput . nativeElement ) ;
1851+ } ) ) ;
1852+ it ( 'should clear the selection and preserve the focus when the combo is collapsed and Escape key is pressed' , fakeAsync ( ( ) => {
1853+ combo . comboInput . nativeElement . focus ( ) ;
1854+ fixture . detectChanges ( ) ;
1855+ expect ( document . activeElement ) . toEqual ( combo . comboInput . nativeElement ) ;
1856+
1857+ combo . select ( [ combo . data [ 0 ] [ combo . valueKey ] ] ) ;
1858+ expect ( combo . selection . length ) . toEqual ( 1 ) ;
1859+ fixture . detectChanges ( ) ;
1860+
1861+ combo . onEscape ( UIInteractions . getKeyboardEvent ( 'keydown' , 'Escape' ) ) ;
1862+ tick ( ) ;
1863+ fixture . detectChanges ( ) ;
1864+ expect ( document . activeElement ) . toEqual ( combo . comboInput . nativeElement ) ;
1865+ expect ( combo . selection . length ) . toEqual ( 0 ) ;
1866+ } ) ) ;
1867+ it ( 'should close the combo and preserve the focus when Escape key is pressed' , fakeAsync ( ( ) => {
1868+ combo . comboInput . nativeElement . focus ( ) ;
1869+ fixture . detectChanges ( ) ;
1870+ expect ( document . activeElement ) . toEqual ( combo . comboInput . nativeElement ) ;
1871+
1872+ combo . toggle ( ) ;
1873+ fixture . detectChanges ( ) ;
1874+ expect ( combo . collapsed ) . toBeFalsy ( ) ;
1875+
1876+ const dropdownContent = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_CONTENT } ` ) ) ;
1877+
1878+ UIInteractions . triggerEventHandlerKeyDown ( 'ArrowDown' , dropdownContent ) ;
1879+ fixture . detectChanges ( ) ;
1880+
1881+ UIInteractions . triggerEventHandlerKeyDown ( 'Escape' , dropdownContent ) ;
1882+ fixture . detectChanges ( ) ;
1883+ expect ( document . activeElement ) . toEqual ( combo . comboInput . nativeElement ) ;
1884+
1885+ tick ( ) ;
1886+ fixture . detectChanges ( ) ;
1887+ expect ( combo . collapsed ) . toBeTruthy ( ) ;
18101888 } ) ) ;
18111889 } ) ;
18121890 describe ( 'primitive data dropdown: ' , ( ) => {
@@ -2137,37 +2215,6 @@ describe('igxCombo', () => {
21372215 cancel : false
21382216 } ) ;
21392217 } ) ;
2140- it ( 'should toggle combo dropdown on Enter of the focused toggle icon' , fakeAsync ( ( ) => {
2141- spyOn ( combo , 'toggle' ) . and . callThrough ( ) ;
2142- const toggleBtn = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_TOGGLEBUTTON } ` ) ) ;
2143-
2144- UIInteractions . triggerEventHandlerKeyDown ( 'Enter' , toggleBtn ) ;
2145- tick ( ) ;
2146- fixture . detectChanges ( ) ;
2147- expect ( combo . toggle ) . toHaveBeenCalledTimes ( 1 ) ;
2148- expect ( combo . collapsed ) . toEqual ( false ) ;
2149-
2150- UIInteractions . triggerEventHandlerKeyDown ( 'Enter' , toggleBtn ) ;
2151- tick ( ) ;
2152- fixture . detectChanges ( ) ;
2153- expect ( combo . toggle ) . toHaveBeenCalledTimes ( 2 ) ;
2154- expect ( combo . collapsed ) . toEqual ( true ) ;
2155- } ) ) ;
2156- it ( 'should clear the selection on Enter of the focused clear icon' , ( ) => {
2157- const selectedItem_1 = combo . dropdown . items [ 1 ] ;
2158- combo . toggle ( ) ;
2159- fixture . detectChanges ( ) ;
2160- simulateComboItemClick ( 1 ) ;
2161- expect ( combo . selection [ 0 ] ) . toEqual ( selectedItem_1 . value ) ;
2162- expect ( combo . value [ 0 ] ) . toEqual ( selectedItem_1 . value [ combo . valueKey ] ) ;
2163-
2164- const clearBtn = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_CLEARBUTTON } ` ) ) ;
2165- UIInteractions . triggerEventHandlerKeyDown ( 'Enter' , clearBtn ) ;
2166- fixture . detectChanges ( ) ;
2167- expect ( input . nativeElement . value ) . toEqual ( '' ) ;
2168- expect ( combo . selection . length ) . toEqual ( 0 ) ;
2169- expect ( combo . value . length ) . toEqual ( 0 ) ;
2170- } ) ;
21712218 it ( 'should not be able to select group header' , ( ) => {
21722219 spyOn ( combo . selectionChanging , 'emit' ) . and . callThrough ( ) ;
21732220 combo . toggle ( ) ;
0 commit comments