Skip to content

Commit 3f7c777

Browse files
authored
Merge pull request #5815 from IgniteUI/iganchev/date-picker-select-text
Add text selection directive for editable input (dropdown mode) scenarios
2 parents 8f716a4 + 284379a commit 3f7c777

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<igx-icon>today</igx-icon>
1616
</igx-prefix>
1717
<label *ngIf="labelVisibility" igxLabel>{{label}}</label>
18-
<input #editableInput class="igx-date-picker__input-date" igxInput type="text" [value]="transformedDate"
18+
<input #editableInput class="igx-date-picker__input-date" igxInput [igxTextSelection]="true"
19+
type="text" [value]="transformedDate"
1920
[igxMask]="inputMask" [placeholder]="mask" [disabled]="disabled" [displayValuePipe]="displayValuePipe"
2021
[focusedValuePipe]="inputValuePipe" (blur)="onBlur($event)" (wheel)="onWheel($event)"
2122
(input)="onInput($event)" (focus)="onFocus()" />
@@ -25,4 +26,4 @@
2526
</igx-input-group>
2627
</ng-template>
2728

28-
<ng-container *ngTemplateOutlet="template; context: context"></ng-container>
29+
<ng-container *ngTemplateOutlet="template; context: context"></ng-container>

projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IgxLabelDirective } from '../directives/label/label.directive';
88
import { IgxInputDirective } from '../directives/input/input.directive';
99
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
1010
import { IgxInputGroupModule } from '../input-group';
11-
11+
import { IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive';
1212
import { configureTestSuite } from '../test-utils/configure-suite';
1313
import { DateRangeType } from 'igniteui-angular';
1414
import { IgxButtonModule } from '../directives/button/button.directive';
@@ -32,7 +32,8 @@ describe('IgxDatePicker', () => {
3232
IgxDropDownDatePickerRetemplatedComponent,
3333
IgxDatePickerOpeningComponent
3434
],
35-
imports: [IgxDatePickerModule, FormsModule, NoopAnimationsModule, IgxInputGroupModule, IgxCalendarModule, IgxButtonModule]
35+
imports: [IgxDatePickerModule, FormsModule, NoopAnimationsModule, IgxInputGroupModule, IgxCalendarModule,
36+
IgxButtonModule, IgxTextSelectionModule]
3637
})
3738
.compileComponents();
3839
}));
@@ -1089,6 +1090,29 @@ describe('IgxDatePicker', () => {
10891090
expect(instance.getEditElement()).toBe(editElement);
10901091
});
10911092
});
1093+
1094+
describe('Drop-down mode select all text on focus', () => {
1095+
let fixture: ComponentFixture<IgxDatePickerEditableComponent>;
1096+
let datePicker: IgxDatePickerComponent;
1097+
1098+
beforeEach(() => {
1099+
fixture = TestBed.createComponent(IgxDatePickerEditableComponent);
1100+
datePicker = fixture.componentInstance.datePicker;
1101+
fixture.detectChanges();
1102+
});
1103+
1104+
it('Should select all input text on input focus', fakeAsync(() => {
1105+
const input = fixture.debugElement.query(By.directive(IgxInputDirective)).nativeElement;
1106+
input.focus();
1107+
fixture.detectChanges();
1108+
tick(100);
1109+
1110+
expect(input).toEqual(document.activeElement);
1111+
expect(input.selectionEnd).toEqual(input.value.length);
1112+
expect(input.selectionStart).toEqual(0);
1113+
expect(input.value.substring(input.selectionStart, input.selectionEnd)).toEqual(input.value);
1114+
}));
1115+
});
10921116
});
10931117

10941118
@Component({

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { IgxInputGroupModule, IgxInputDirective, IgxInputGroupComponent } from '
3232
import { Subject, fromEvent, animationFrameScheduler, interval } from 'rxjs';
3333
import { filter, takeUntil, throttle } from 'rxjs/operators';
3434
import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive';
35+
import { IgxTextSelectionModule} from '../directives/text-selection/text-selection.directive';
3536
import {
3637
OverlaySettings,
3738
IgxOverlayService,
@@ -1379,7 +1380,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
13791380
IgxDatePickerTemplateDirective, DatePickerDisplayValuePipe, DatePickerInputValuePipe],
13801381
exports: [IgxDatePickerComponent, IgxDatePickerTemplateDirective, IgxDatePickerActionsDirective,
13811382
DatePickerDisplayValuePipe, DatePickerInputValuePipe],
1382-
imports: [CommonModule, IgxIconModule, IgxInputGroupModule, IgxCalendarModule, IgxButtonModule, IgxRippleModule, IgxMaskModule],
1383+
imports: [CommonModule, IgxIconModule, IgxInputGroupModule, IgxCalendarModule, IgxButtonModule,
1384+
IgxRippleModule, IgxMaskModule, IgxTextSelectionModule],
13831385
entryComponents: [IgxCalendarContainerComponent]
13841386
})
13851387
export class IgxDatePickerModule { }

0 commit comments

Comments
 (0)