Skip to content

Commit d050b25

Browse files
authored
Merge pull request #6317 from IgniteUI/vslavov/revert-combo-ivy-workaround
refactor(combo): revert Ivy workaround in combo click handler
2 parents 20534c5 + 75eefcc commit d050b25

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IgxComboItemComponent } from './combo-item.component';
2-
import { Component, HostListener } from '@angular/core';
2+
import { Component } from '@angular/core';
33

44
/**
55
* @hidden
@@ -17,18 +17,10 @@ export class IgxComboAddItemComponent extends IgxComboItemComponent {
1717
}
1818

1919
/**
20-
* @hidden
21-
* @internal
22-
* This is related to https://github.com/angular/angular/issues/33300
23-
* When the above is fixed, we can remove the @HostListener decorator and move
24-
* the body of the `handleClick` method back under `clicked`
20+
* @inheritdoc
2521
*/
26-
@HostListener('click')
27-
handleClick() {
22+
clicked(event?) {
2823
this.comboAPI.disableTransitions = false;
2924
this.comboAPI.add_custom_item();
3025
}
31-
32-
clicked(event?) {
33-
}
3426
}

projects/igniteui-angular/src/lib/combo/combo-item.component.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,12 @@ export class IgxComboItemComponent extends IgxDropDownItemComponent implements D
8484
return rect.y >= parentDiv.y;
8585
}
8686

87-
clicked(event) {
87+
/**
88+
* @inheritdoc
89+
*/
90+
clicked(event): void {
8891
this.comboAPI.disableTransitions = false;
89-
if (this.disabled || this.isHeader) {
90-
const focusedItem = this.dropDown.items.find((item) => item.focused);
91-
if (this.dropDown.allowItemsFocus && focusedItem) {
92-
focusedItem.element.nativeElement.focus({ preventScroll: true });
93-
}
94-
return;
95-
}
92+
if (!this.isSelectable) { return; }
9693
this.dropDown.navigateItem(this.index);
9794
this.comboAPI.set_selected_item(this.itemID, event);
9895
}

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ describe('igxCombo', () => {
369369
await wait(30);
370370
items = fix.debugElement.queryAll(By.css('.' + CSS_CLASS_DROPDOWNLISTITEM));
371371
lastItem = items[items.length - 1].componentInstance;
372-
(lastItem as IgxComboAddItemComponent).handleClick();
372+
(lastItem as IgxComboAddItemComponent).clicked();
373373
fix.detectChanges();
374374
// After `Add Item` is clicked, the input is focused and the item is added to the list
375375
expect(dropdown.focusedItem).toEqual(null);

projects/igniteui-angular/src/lib/drop-down/drop-down-item.base.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff 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
/**
@@ -329,4 +329,26 @@ export class IgxDropDownItemBaseDirective implements DoCheck {
329329
}
330330
}
331331
}
332+
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) {
341+
const focusedItem = this.dropDown.items.find((item) => item.focused);
342+
if (!focusedItem) { return; }
343+
focusedItem.element.nativeElement.focus({ preventScroll: true });
344+
}
345+
}
346+
347+
/**
348+
* @hidden
349+
* @internal
350+
*/
351+
@HostListener('click', ['$event'])
352+
clicked(event): void {
353+
}
332354
}

projects/igniteui-angular/src/lib/drop-down/drop-down-item.component.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Component,
3-
HostListener,
43
HostBinding
54
} from '@angular/core';
65
import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
@@ -24,7 +23,7 @@ export class IgxDropDownItemComponent extends IgxDropDownItemBaseDirective {
2423
const focusedIndex = focusedItem ? focusedItem.index : -1;
2524
focusedState = this._index === focusedIndex;
2625
}
27-
return !this.isHeader && !this.disabled && focusedState;
26+
return this.isSelectable && focusedState;
2827
}
2928

3029
/**
@@ -59,7 +58,7 @@ export class IgxDropDownItemComponent extends IgxDropDownItemBaseDirective {
5958
*/
6059
@HostBinding('attr.tabindex')
6160
get setTabIndex() {
62-
const shouldSetTabIndex = this.dropDown.allowItemsFocus && !(this.disabled || this.isHeader);
61+
const shouldSetTabIndex = this.dropDown.allowItemsFocus && this.isSelectable;
6362
if (shouldSetTabIndex) {
6463
return 0;
6564
} else {
@@ -68,15 +67,11 @@ export class IgxDropDownItemComponent extends IgxDropDownItemBaseDirective {
6867
}
6968

7069
/**
71-
* @hidden @internal
70+
* @inheritdoc
7271
*/
73-
@HostListener('click', ['$event'])
74-
clicked(event) {
75-
if (this.disabled || this.isHeader) {
76-
const focusedItem = this.dropDown.items.find((item) => item.focused);
77-
if (this.dropDown.allowItemsFocus && focusedItem) {
78-
focusedItem.element.nativeElement.focus({ preventScroll: true });
79-
}
72+
clicked(event): void {
73+
if (!this.isSelectable) {
74+
this.ensureItemFocus();
8075
return;
8176
}
8277
if (this.selection) {

0 commit comments

Comments
 (0)