Skip to content

Commit e784abf

Browse files
committed
refactor(combo): revert Ivy workaround in combo click handler
1 parent e383aa7 commit e784abf

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
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.shouldSelect) { 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
@@ -368,7 +368,7 @@ describe('igxCombo', () => {
368368
await wait(30);
369369
items = fix.debugElement.queryAll(By.css('.' + CSS_CLASS_DROPDOWNLISTITEM));
370370
lastItem = items[items.length - 1].componentInstance;
371-
(lastItem as IgxComboAddItemComponent).handleClick();
371+
(lastItem as IgxComboAddItemComponent).clicked();
372372
fix.detectChanges();
373373
// After `Add Item` is clicked, the input is focused and the item is added to the list
374374
expect(dropdown.focusedItem).toEqual(null);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,29 @@ export class IgxDropDownItemBaseDirective implements DoCheck {
329329
}
330330
}
331331
}
332+
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) {
340+
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;
347+
}
348+
}
349+
350+
/**
351+
* @hidden
352+
* @internal
353+
*/
354+
@HostListener('click', ['$event'])
355+
clicked(event): void {
356+
}
332357
}

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

Lines changed: 3 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';
@@ -68,17 +67,10 @@ 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-
}
80-
return;
81-
}
72+
clicked(event): void {
73+
if (!this.shouldSelect) { return; }
8274
if (this.selection) {
8375
this.dropDown.selectItem(this, event);
8476
}

0 commit comments

Comments
 (0)