Skip to content

Adding toggle calendar icon to the end of the picker #16106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ContentChild, Pipe, PipeTransform, Directive } from '@angular/core';
import { Component, ContentChild, Pipe, PipeTransform, Directive, ViewChild, ViewContainerRef } from '@angular/core';
import { NgControl } from '@angular/forms';
import { IgxInputDirective, IgxInputState } from '../input-group/public_api';
import { IgxInputGroupComponent } from '../input-group/input-group.component';
Expand All @@ -10,7 +10,8 @@ import { IgxIconComponent } from '../icon/icon.component';
import { IgxSuffixDirective } from '../directives/suffix/suffix.directive';
import { IgxButtonDirective } from '../directives/button/button.directive';
import { IgxPrefixDirective } from '../directives/prefix/prefix.directive';
import { NgTemplateOutlet, NgClass } from '@angular/common';
import { NgTemplateOutlet } from '@angular/common';
import { IgxPickerToggleComponent } from '../date-common/public_api';

/** Represents a range between two dates. */
export interface DateRange {
Expand Down Expand Up @@ -67,6 +68,9 @@ export class IgxDateRangeInputsBaseComponent extends IgxInputGroupComponent {
@ContentChild(IgxInputDirective)
public inputDirective: IgxInputDirective;

@ViewChild('toggleSlot', { read: ViewContainerRef, static: false })
public toggleSlot: ViewContainerRef;

@ContentChild(NgControl)
protected ngControl: NgControl;

Expand Down Expand Up @@ -128,7 +132,10 @@ export class IgxDateRangeInputsBaseComponent extends IgxInputGroupComponent {
],
imports: [NgTemplateOutlet, IgxPrefixDirective, IgxButtonDirective, IgxSuffixDirective, IgxIconComponent]
})
export class IgxDateRangeStartComponent extends IgxDateRangeInputsBaseComponent { }
export class IgxDateRangeStartComponent extends IgxDateRangeInputsBaseComponent {
@ContentChild(IgxPickerToggleComponent)
public projectedToggle?: IgxPickerToggleComponent;
}

/**
* Defines the end input for a date range picker
Expand Down Expand Up @@ -163,7 +170,10 @@ export class IgxDateRangeStartComponent extends IgxDateRangeInputsBaseComponent
],
imports: [NgTemplateOutlet, IgxPrefixDirective, IgxButtonDirective, IgxSuffixDirective, IgxIconComponent]
})
export class IgxDateRangeEndComponent extends IgxDateRangeInputsBaseComponent { }
export class IgxDateRangeEndComponent extends IgxDateRangeInputsBaseComponent {
@ContentChild(IgxPickerToggleComponent)
public projectedToggle?: IgxPickerToggleComponent;
}

/**
* Replaces the default separator `to` with the provided value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ng-template>

<ng-template #defIcon>
<igx-icon family="default" name="date_range" [attr.aria-hidden]="true"></igx-icon>
<igx-icon family="default" name="date_range" [attr.aria-hidden]="true" (click)="toggle()"></igx-icon>
</ng-template>

<ng-template #defDateSeparatorTemplate>{{ dateSeparator }}</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,20 @@ describe('IgxDateRangePicker', () => {
expect(inputGroupsStart.children[0].children[0].classes[CSS_CLASS_ICON]).toBeTruthy();
});

it('should render default toggle icon and templated icon via igx-picker-toggle - two inputs', () => {
fixture = TestBed.createComponent(DateRangeTwoInputsTestComponent);
fixture.detectChanges();

const inputGroupsStartCollection = fixture.debugElement.queryAll(By.css(CSS_CLASS_INPUT_START));

expect(inputGroupsStartCollection[0].children[0].nativeElement.innerText).toBe('calendar_view_day');
// has igx-picker-toggle so +1 child level
expect(inputGroupsStartCollection[0].children[0].children[0].classes[CSS_CLASS_ICON]).toBeTruthy();

expect(inputGroupsStartCollection[1].children[0].nativeElement.innerText).toBe(DEFAULT_ICON_TEXT);
expect(inputGroupsStartCollection[1].children[0].classes[CSS_CLASS_ICON]).toBeTruthy();
});

it('should be able to set toggle icon', () => {
const prefixIconText = 'flight_takeoff';
const suffixIconText = 'flight_land';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { IgxPrefixDirective } from '../directives/prefix/prefix.directive';
import { IgxIconComponent } from '../icon/icon.component';
import { getCurrentResourceStrings } from '../core/i18n/resources';
import { fadeIn, fadeOut } from 'igniteui-angular/animations';
import { IgxInputGroupBase } from '../input-group/input-group.common';

const SingleInputDatesConcatenationString = ' - ';

Expand Down Expand Up @@ -293,13 +294,17 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
@ViewChild(IgxInputGroupComponent, { read: ViewContainerRef })
private viewContainerRef: ViewContainerRef;

/** @hidden @internal */
@ViewChild('defIcon', { read: TemplateRef })
private defIcon: TemplateRef<any>;

/** @hidden @internal */
@ViewChild(IgxInputDirective)
public inputDirective: IgxInputDirective;

/** @hidden @internal */
@ContentChildren(IgxDateRangeInputsBaseComponent)
public projectedInputs: QueryList<IgxDateRangeInputsBaseComponent>;
@ContentChildren(IgxInputGroupBase as any, { descendants: true, read: IgxDateRangeInputsBaseComponent })
public projectedInputs!: QueryList<IgxDateRangeInputsBaseComponent>;

@ContentChild(IgxLabelDirective)
public label: IgxLabelDirective;
Expand Down Expand Up @@ -649,6 +654,7 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
this.attachOnTouched();

this.setRequiredToInputs();
this.renderDefaultToggleIcons();

if (this._ngControl) {
this._statusChanges$ = this._ngControl.statusChanges.subscribe(this.onStatusChanged.bind(this));
Expand Down Expand Up @@ -855,6 +861,33 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
});
}

private renderDefaultToggleIcons(): void {
if (!this.projectedInputs || this.projectedInputs.length === 0) {
return;
}

const start = this.projectedInputs.find(i => i instanceof IgxDateRangeStartComponent) as IgxDateRangeStartComponent;
const end = this.projectedInputs.find(i => i instanceof IgxDateRangeEndComponent) as IgxDateRangeEndComponent;

if (start && !this.hasStartToggle) {
start.toggleSlot.createEmbeddedView(this.defIcon);
}

if (end && !this.hasEndToggle) {
end.toggleSlot.createEmbeddedView(this.defIcon);
}
}

private get hasStartToggle(): boolean {
const start = this.projectedInputs.find(i => i instanceof IgxDateRangeStartComponent) as IgxDateRangeStartComponent;
return !!start?.projectedToggle;
}

private get hasEndToggle(): boolean {
const end = this.projectedInputs.find(i => i instanceof IgxDateRangeEndComponent) as IgxDateRangeEndComponent;
return !!end?.projectedToggle;
}

private parseMinValue(value: string | Date): Date | null {
let minValue: Date = parseDate(value);
if (!minValue && this.hasProjectedInputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<div class="igx-input-group__bundle">
<div class="igx-input-group__bundle-start">
<ng-container *ngTemplateOutlet="prefix"></ng-container>
<ng-template #toggleSlot></ng-template>
</div>

<ng-container>
Expand Down Expand Up @@ -107,6 +108,7 @@
<div class="igx-input-group__bundle">
<div class="igx-input-group__bundle-start">
<ng-container *ngTemplateOutlet="prefix"></ng-container>
<ng-template #toggleSlot></ng-template>
</div>


Expand All @@ -133,6 +135,7 @@
<div class="igx-input-group__bundle">
<div class="igx-input-group__bundle-start">
<ng-container *ngTemplateOutlet="prefix"></ng-container>
<ng-template #toggleSlot></ng-template>
</div>

<ng-container *ngTemplateOutlet="input"></ng-container>
Expand Down
Loading