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 @@ -225,6 +225,15 @@ const TabPanel = MultiView.inherit({
225225 . addClass ( TABPANEL_CONTAINER_CLASS )
226226 . appendTo ( $element ) ;
227227 this . _$container . append ( this . _$wrapper ) ;
228+
229+ const { focusStateEnabled, selectedIndex } = this . option ( ) ;
230+ if ( focusStateEnabled && isDefined ( selectedIndex ) ) {
231+ const selectedItem = this . _tabs . itemElements ( ) . get ( selectedIndex ) ;
232+
233+ if ( selectedItem ) {
234+ this . _tabs . option ( { focusedElement : selectedItem } ) ;
235+ }
236+ }
228237 } ,
229238
230239 _refreshActiveDescendant ( ) {
Original file line number Diff line number Diff line change @@ -604,6 +604,26 @@ QUnit.module('focus policy', {
604604
605605 assert . strictEqual ( $tabPanel . find ( `.${ MULTIVIEW_WRAPPER_CLASS } ` ) . hasClass ( FOCUS_STATE_CLASS ) , false ) ;
606606 } ) ;
607+
608+ QUnit . test ( 'first tab should be focused after initialization (T1277409)' , function ( assert ) {
609+ const items = Array . from ( { length : 20 } , ( _ , index ) => ( {
610+ title : `Tab ${ index + 1 } ` ,
611+ text : `Content ${ index + 1 } `
612+ } ) ) ;
613+
614+ const $tabPanel = $ ( '#tabPanel' ) . dxTabPanel ( {
615+ items,
616+ focusStateEnabled : true ,
617+ } ) ;
618+
619+ const $tabs = $tabPanel . find ( toSelector ( TABPANEL_TABS_ITEM_CLASS ) ) ;
620+ const tabsInstance = $tabPanel . find ( toSelector ( TABS_CLASS ) ) . dxTabs ( 'instance' ) ;
621+ const $firstTab = $tabs . first ( ) ;
622+
623+ assert . strictEqual ( $tabs . filter ( `.${ FOCUS_STATE_CLASS } ` ) . length , 1 , 'only one tab is focused' ) ;
624+ assert . strictEqual ( $firstTab . hasClass ( FOCUS_STATE_CLASS ) , true , 'first tab is focused' ) ;
625+ assert . strictEqual ( $ ( tabsInstance . option ( 'focusedElement' ) ) . get ( 0 ) , $firstTab . get ( 0 ) , 'focusedElement is correct' ) ;
626+ } ) ;
607627} ) ;
608628
609629QUnit . module ( 'keyboard navigation' , {
You can’t perform that action at this time.
0 commit comments