File tree Expand file tree Collapse file tree 3 files changed +18
-18
lines changed
projects/igniteui-angular/src/lib Expand file tree Collapse file tree 3 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ export class IgxComboItemComponent extends IgxDropDownItemComponent implements D
8989 */
9090 clicked ( event ) : void {
9191 this . comboAPI . disableTransitions = false ;
92- if ( ! this . shouldSelect ) { return ; }
92+ if ( ! this . isSelectable ) { return ; }
9393 this . dropDown . navigateItem ( this . index ) ;
9494 this . comboAPI . set_selected_item ( this . itemID , event ) ;
9595 }
Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ export class IgxDropDownItemBaseDirective implements DoCheck {
178178 */
179179 @HostBinding ( 'class.igx-drop-down__item--focused' )
180180 get focused ( ) : boolean {
181- return ( ! this . isHeader && ! this . disabled ) && this . _focused ;
181+ return this . isSelectable && this . _focused ;
182182 }
183183
184184 /**
@@ -330,20 +330,17 @@ export class IgxDropDownItemBaseDirective implements DoCheck {
330330 }
331331 }
332332
333- /**
334- * If the clicked item is a header or is disabled,
335- * should not attempt to select it.
336- * If `allowItemsFocus` is true, should move the focus to the actual item.
337- */
338- protected get shouldSelect ( ) : boolean {
339- if ( this . disabled || this . isHeader ) {
333+ /** Returns true if the items is not a header or disabled */
334+ protected get isSelectable ( ) : boolean {
335+ return ! ( this . disabled || this . isHeader ) ;
336+ }
337+
338+ /** If `allowItemsFocus` is enabled, keep the browser focus on the active item */
339+ protected ensureItemFocus ( ) {
340+ if ( this . dropDown . allowItemsFocus ) {
340341 const focusedItem = this . dropDown . items . find ( ( item ) => item . focused ) ;
341- if ( this . dropDown . allowItemsFocus && focusedItem ) {
342- focusedItem . element . nativeElement . focus ( { preventScroll : true } ) ;
343- }
344- return false ;
345- } else {
346- return true ;
342+ if ( ! focusedItem ) { return ; }
343+ focusedItem . element . nativeElement . focus ( { preventScroll : true } ) ;
347344 }
348345 }
349346
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export class IgxDropDownItemComponent extends IgxDropDownItemBaseDirective {
2323 const focusedIndex = focusedItem ? focusedItem . index : - 1 ;
2424 focusedState = this . _index === focusedIndex ;
2525 }
26- return ! this . isHeader && ! this . disabled && focusedState ;
26+ return this . isSelectable && focusedState ;
2727 }
2828
2929 /**
@@ -58,7 +58,7 @@ export class IgxDropDownItemComponent extends IgxDropDownItemBaseDirective {
5858 */
5959 @HostBinding ( 'attr.tabindex' )
6060 get setTabIndex ( ) {
61- const shouldSetTabIndex = this . dropDown . allowItemsFocus && ! ( this . disabled || this . isHeader ) ;
61+ const shouldSetTabIndex = this . dropDown . allowItemsFocus && this . isSelectable ;
6262 if ( shouldSetTabIndex ) {
6363 return 0 ;
6464 } else {
@@ -70,7 +70,10 @@ export class IgxDropDownItemComponent extends IgxDropDownItemBaseDirective {
7070 * @inheritdoc
7171 */
7272 clicked ( event ) : void {
73- if ( ! this . shouldSelect ) { return ; }
73+ if ( ! this . isSelectable ) {
74+ this . ensureItemFocus ( ) ;
75+ return ;
76+ }
7477 if ( this . selection ) {
7578 this . dropDown . selectItem ( this , event ) ;
7679 }
You can’t perform that action at this time.
0 commit comments