Skip to content

Commit 473a31a

Browse files
authored
feat(select): add igxHint support #5584 (#7487)
1 parent 9f1e5c2 commit 473a31a

File tree

6 files changed

+56
-16
lines changed

6 files changed

+56
-16
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ All notable changes for each version of this project will be documented in this
1818
- `IgxGrid`
1919
- `showGroupArea` input is added, which can be used to enable/disable the group area row.
2020

21+
- `IgxSelect` support for `igxHint` directive added.
22+
- Allows the user to add `igxHint` to be displayed bellow the input element.
23+
2124
## 9.1.1
2225

2326
### General

projects/igniteui-angular/src/lib/select/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class MyClass {
4141
}
4242
```
4343

44-
`igx-select` supports prefixes, suffixes, label and placeholder. You can read more about them [*here*](https://www.infragistics.com/products/ignite-ui-angular/angular/components/input_group.html) AND [*here*](https://www.infragistics.com/products/ignite-ui-angular/angular/components/label_input.html).
44+
`igx-select` supports prefixes, suffixes, label, hint and placeholder. You can read more about them [*here*](https://www.infragistics.com/products/ignite-ui-angular/angular/components/input_group.html) AND [*here*](https://www.infragistics.com/products/ignite-ui-angular/angular/components/label_input.html).
4545
- The items' list default exapansion panel arrow uses `IgxSuffix` and it can be changed by the user.
4646
- If more than one `IgxSuffix` is used, the expansion arrow will be displayed always last.
4747

projects/igniteui-angular/src/lib/select/select.component.html

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<igx-input-group #inputGroup class="input-group" (click)="toggle()" [type]="type" [displayDensity]="displayDensity">
1+
<igx-input-group #inputGroup class="input-group" (click)="inputGroupClick($event)" [type]="type" [displayDensity]="displayDensity">
22
<ng-container ngProjectAs="[igxLabel]">
33
<ng-content select="[igxLabel]"></ng-content>
44
</ng-container>
@@ -23,11 +23,14 @@
2323
<ng-content select="igx-suffix,[igxSuffix]"></ng-content>
2424
</ng-container>
2525
<igx-suffix>
26-
<ng-container *ngIf="toggleIconTemplate">
27-
<ng-container *ngTemplateOutlet="toggleIconTemplate; context: {$implicit: this.collapsed}"></ng-container>
28-
</ng-container>
29-
<igx-icon *ngIf="!toggleIconTemplate" fontSet="material">{{ collapsed ? 'arrow_drop_down' : 'arrow_drop_up'}}</igx-icon>
26+
<ng-container *ngIf="toggleIconTemplate">
27+
<ng-container *ngTemplateOutlet="toggleIconTemplate; context: {$implicit: this.collapsed}"></ng-container>
28+
</ng-container>
29+
<igx-icon *ngIf="!toggleIconTemplate" fontSet="material">{{ collapsed ? 'arrow_drop_down' : 'arrow_drop_up'}}</igx-icon>
3030
</igx-suffix>
31+
<ng-container ngProjectAs="igx-hint, [igxHint]" >
32+
<ng-content select="igx-hint, [igxHint]"></ng-content>
33+
</ng-container>
3134
</igx-input-group>
3235
<div igxToggle class="igx-drop-down__list" (mousedown)="mousedownHandler($event);" (onOpening)="onToggleOpening($event)"
3336
(onOpened)="onToggleOpened()" (onClosing)="onToggleClosing($event)" (onClosed)="onToggleClosed()">

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

+29-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FormsModule, FormGroup, FormBuilder, FormControl, Validators, ReactiveF
55
import { By } from '@angular/platform-browser';
66
import { IgxDropDownModule, IgxDropDownItemComponent } from '../drop-down/public_api';
77
import { IgxIconModule } from '../icon/public_api';
8-
import { IgxInputGroupModule } from '../input-group/public_api';
8+
import { IgxInputGroupModule, IgxHintDirective } from '../input-group/public_api';
99
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
1010
import { IgxSelectComponent } from './select.component';
1111
import { IgxSelectItemComponent } from './select-item.component';
@@ -107,7 +107,6 @@ describe('igxSelect', () => {
107107
]
108108
}).compileComponents();
109109
}));
110-
111110
describe('General tests: ', () => {
112111
beforeEach(fakeAsync(() => {
113112
fixture = TestBed.createComponent(IgxSelectSimpleComponent);
@@ -2486,7 +2485,6 @@ describe('igxSelect', () => {
24862485
expect(selectList.nativeElement.nextElementSibling).toBeNull();
24872486
}));
24882487
});
2489-
24902488
describe('Test CDR - Expression changed after it was checked', () => {
24912489
beforeEach(fakeAsync(() => {
24922490
fixture = TestBed.createComponent(IgxSelectCDRComponent);
@@ -2511,6 +2509,33 @@ describe('igxSelect', () => {
25112509
expect(selectCDR.value).toBe('ID');
25122510
});
25132511
});
2512+
describe('Input with input group directives - hint, label, prefix, suffix: ', () => {
2513+
beforeEach(fakeAsync(() => {
2514+
fixture = TestBed.createComponent(IgxSelectAffixComponent);
2515+
select = fixture.componentInstance.select;
2516+
fixture.detectChanges();
2517+
}));
2518+
it('should not open dropdown on hint container click',
2519+
fakeAsync(() => {
2520+
const hint = fixture.debugElement.query(By.directive(IgxHintDirective));
2521+
const hintContainer: HTMLElement = hint.nativeElement.parentElement;
2522+
2523+
expect(select.collapsed).toBeTruthy();
2524+
hintContainer.click();
2525+
tick();
2526+
fixture.detectChanges();
2527+
expect(select.collapsed).toBeTruthy();
2528+
}));
2529+
it('should not open dropdown on hint element click',
2530+
fakeAsync(() => {
2531+
const hint = fixture.debugElement.query(By.directive(IgxHintDirective));
2532+
expect(select.collapsed).toBeTruthy();
2533+
hint.nativeElement.click();
2534+
tick();
2535+
fixture.detectChanges();
2536+
expect(select.collapsed).toBeTruthy();
2537+
}));
2538+
});
25142539
});
25152540

25162541
describe('igxSelect ControlValueAccessor Unit', () => {
@@ -2704,6 +2729,7 @@ class IgxSelectBottomComponent {
27042729
<igx-suffix>
27052730
<igx-icon fontSet="material">alarm</igx-icon>
27062731
</igx-suffix>
2732+
<igx-hint>I am a Hint</igx-hint>
27072733
<igx-select-item *ngFor="let item of items" [value]="item">
27082734
{{ item }}
27092735
</igx-select-item>
@@ -2723,7 +2749,6 @@ class IgxSelectAffixComponent {
27232749
'Option 7'];
27242750
}
27252751

2726-
27272752
@Component({
27282753
template: `
27292754
<form [formGroup]="reactiveForm" (ngSubmit)="onSubmitReactive()">

projects/igniteui-angular/src/lib/select/select.component.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ import { IgxDropDownComponent } from './../drop-down/drop-down.component';
3737
import { IgxSelectItemComponent } from './select-item.component';
3838
import { SelectPositioningStrategy } from './select-positioning-strategy';
3939
import { IgxSelectBase } from './select.common';
40-
41-
42-
40+
import { IgxHintDirective } from '../input-group/public_api';
4341

4442
/** @hidden @internal */
4543
@Directive({
@@ -109,12 +107,14 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
109107
/** @hidden @internal */
110108
@ViewChild('input', { read: IgxInputDirective, static: true }) public input: IgxInputDirective;
111109

110+
@ContentChild(IgxHintDirective, { read: ElementRef }) private hintElement: ElementRef;
111+
112112
/** @hidden @internal */
113113
@ContentChildren(forwardRef(() => IgxSelectItemComponent), { descendants: true })
114114
public children: QueryList<IgxSelectItemComponent>;
115115

116116
/** @hidden @internal */
117-
@ContentChild(forwardRef(() => IgxLabelDirective), { static: true }) label: IgxLabelDirective;
117+
@ContentChild(forwardRef(() => IgxLabelDirective), { static: true }) public label: IgxLabelDirective;
118118

119119
/** @hidden @internal */
120120
public allowItemsFocus = false;
@@ -280,9 +280,7 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
280280

281281
//#region ControlValueAccessor
282282

283-
/** @hidden @internal */
284283
private _onChangeCallback: (_: any) => void = noop;
285-
/** @hidden @internal */
286284
private _onTouchedCallback: () => void = noop;
287285

288286
/** @hidden @internal */
@@ -358,6 +356,15 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
358356
super.open(Object.assign({}, this._overlayDefaults, this.overlaySettings, overlaySettings));
359357
}
360358

359+
public inputGroupClick(event: MouseEvent, overlaySettings?: OverlaySettings) {
360+
const targetElement = event.target as HTMLElement;
361+
362+
if (this.hintElement && targetElement.contains(this.hintElement.nativeElement)) {
363+
return;
364+
}
365+
this.toggle(Object.assign({}, this._overlayDefaults, this.overlaySettings, overlaySettings));
366+
}
367+
361368
/** @hidden @internal */
362369
ngAfterContentInit() {
363370
this._overlayDefaults = {

src/app/select/select.sample.html

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ <h4 class="sample-title">Select - declare items in html template</h4>
6868
<igx-suffix>
6969
<igx-icon fontSet="material">alarm</igx-icon>
7070
</igx-suffix>
71+
<igx-hint>I am a Hint</igx-hint>
7172
<igx-select-item>None</igx-select-item>
7273
<igx-select-item [value]="1">Sofia</igx-select-item>
7374
<igx-select-item [value]="2">London</igx-select-item>
@@ -85,6 +86,7 @@ <h4 class="sample-title">Select - disabled item</h4>
8586
(onSelection)="testOnSelection($event)"
8687
[disabled]="false"
8788
[type]="'border'">
89+
<igx-hint>I am a Hint</igx-hint>
8890
<igx-select-item [value] = "'Apple'" [disabled]="true">Apple</igx-select-item>
8991
<igx-select-item [value] = "'Orange'">Orange</igx-select-item>
9092
<igx-select-item [value] = "'Grapes'">Grapes</igx-select-item>

0 commit comments

Comments
 (0)