File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
js/__internal/ui/tab_panel
testing/tests/DevExpress.ui.widgets Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,15 @@ class TabPanel extends MultiView<TabPanelProperties> {
259259 . addClass ( TABPANEL_CONTAINER_CLASS )
260260 . appendTo ( $element ) ;
261261 this . _$container . append ( this . _$wrapper ) ;
262+
263+ const { focusStateEnabled, selectedIndex } = this . option ( ) ;
264+ if ( focusStateEnabled && isDefined ( selectedIndex ) ) {
265+ const selectedItem = this . _tabs . itemElements ( ) . get ( selectedIndex ) ;
266+
267+ if ( selectedItem ) {
268+ this . _tabs . option ( { focusedElement : selectedItem } ) ;
269+ }
270+ }
262271 }
263272
264273 _refreshActiveDescendant ( ) : void {
Original file line number Diff line number Diff line change @@ -1035,6 +1035,26 @@ QUnit.module('focus policy', {
10351035
10361036 assert . strictEqual ( $tabPanel . find ( `.${ MULTIVIEW_WRAPPER_CLASS } ` ) . hasClass ( FOCUS_STATE_CLASS ) , false ) ;
10371037 } ) ;
1038+
1039+ QUnit . test ( 'first tab should be focused after initialization (T1277409)' , function ( assert ) {
1040+ const items = Array . from ( { length : 20 } , ( _ , index ) => ( {
1041+ title : `Tab ${ index + 1 } ` ,
1042+ text : `Content ${ index + 1 } `
1043+ } ) ) ;
1044+
1045+ const $tabPanel = $ ( '#tabPanel' ) . dxTabPanel ( {
1046+ items,
1047+ focusStateEnabled : true ,
1048+ } ) ;
1049+
1050+ const $tabs = $tabPanel . find ( toSelector ( TABPANEL_TABS_ITEM_CLASS ) ) ;
1051+ const tabsInstance = $tabPanel . find ( toSelector ( TABS_CLASS ) ) . dxTabs ( 'instance' ) ;
1052+ const $firstTab = $tabs . first ( ) ;
1053+
1054+ assert . strictEqual ( $tabs . filter ( `.${ FOCUS_STATE_CLASS } ` ) . length , 1 , 'only one tab is focused' ) ;
1055+ assert . strictEqual ( $firstTab . hasClass ( FOCUS_STATE_CLASS ) , true , 'first tab is focused' ) ;
1056+ assert . strictEqual ( $ ( tabsInstance . option ( 'focusedElement' ) ) . get ( 0 ) , $firstTab . get ( 0 ) , 'focusedElement is correct' ) ;
1057+ } ) ;
10381058} ) ;
10391059
10401060QUnit . module ( 'keyboard navigation' , {
You can’t perform that action at this time.
0 commit comments