@colijnit/corecomponents_v12 12.1.2 → 12.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4387,7 +4387,7 @@ CoDialogComponent.decorators = [
4387
4387
  <ng-container [ngTemplateOutlet]="headerTemplate"></ng-container>
4388
4388
  </div>
4389
4389
  <div class="dialog-close-button" *ngIf="showCloseIcon" (click)="handleCloseDialog($event)">
4390
- <co-icon [icon]="icons.Cancel"></co-icon>
4390
+ <co-icon [icon]="icons.CrossSkinny"></co-icon>
4391
4391
  </div>
4392
4392
  </div>
4393
4393
  <div class="dialog-content" [ngClass]="customCssClass ? customCssClass : undefined">
@@ -6576,6 +6576,9 @@ class InputDateRangePickerComponent extends BaseInputDatePickerDirective {
6576
6576
  this.toggleCalendar();
6577
6577
  }
6578
6578
  }
6579
+ clearDate(index) {
6580
+ this.model[index] = undefined;
6581
+ }
6579
6582
  toggleCalendar() {
6580
6583
  if (this.readonly) {
6581
6584
  return;
@@ -6643,6 +6646,7 @@ InputDateRangePickerComponent.decorators = [
6643
6646
  [leftIconData]="leftIconData"
6644
6647
  [placeholder]="placeholder"
6645
6648
  (blur)="handleFirstDateChanged(firstDateAsString)"
6649
+ (clearIconClick)="clearDate(0)"
6646
6650
  ></co-input-text>
6647
6651
  <co-input-text class="no-focus-line custom-height"
6648
6652
  [(model)]= "secondDateAsString"
@@ -6652,6 +6656,7 @@ InputDateRangePickerComponent.decorators = [
6652
6656
  [rightIcon]="rightIcon"
6653
6657
  (rightIconClick)="toggleCalendar()"
6654
6658
  (blur)="handleSecondDateChanged(secondDateAsString)"
6659
+ (clearIconClick)="clearDate(1)"
6655
6660
  ></co-input-text>
6656
6661
  </div>
6657
6662
  `,
@@ -10230,7 +10235,6 @@ class ListOfValuesPopupComponent {
10230
10235
  this._collection = [];
10231
10236
  this._searchTerm = '';
10232
10237
  this._lovItems = [];
10233
- this._activeIndex = -1;
10234
10238
  }
10235
10239
  set lovItems(children) {
10236
10240
  this._lovItems = children.toArray();
@@ -10256,6 +10260,8 @@ class ListOfValuesPopupComponent {
10256
10260
  }
10257
10261
  set searchTerm(value) {
10258
10262
  this._searchTerm = value;
10263
+ this.model = undefined;
10264
+ this.highLightModel = undefined;
10259
10265
  this.filterViewModels();
10260
10266
  }
10261
10267
  get searchTerm() {
@@ -10264,7 +10270,6 @@ class ListOfValuesPopupComponent {
10264
10270
  ngOnInit() {
10265
10271
  if (this.model) {
10266
10272
  if (!this.multiselect) {
10267
- this._activeIndex = this.viewModelsMain.findIndex(v => v.model === this.model);
10268
10273
  this._scrollIntoView();
10269
10274
  }
10270
10275
  else {
@@ -10277,52 +10282,87 @@ class ListOfValuesPopupComponent {
10277
10282
  }
10278
10283
  }
10279
10284
  }
10285
+ handleInputKeyDown(event) {
10286
+ if (event) {
10287
+ switch (event.code) {
10288
+ case KeyboardKey.Down:
10289
+ this.selectNextOption();
10290
+ return false;
10291
+ case KeyboardKey.Up:
10292
+ this.selectNextOption(true);
10293
+ return false;
10294
+ case KeyboardKey.SpaceBar:
10295
+ if (this.highLightModel) {
10296
+ this.selectViewModel(this.highLightModel, false);
10297
+ return false;
10298
+ }
10299
+ }
10300
+ }
10301
+ }
10280
10302
  filterViewModels() {
10281
10303
  if (!this.collection) {
10282
10304
  return;
10283
10305
  }
10284
10306
  this._prepareViewModels();
10285
10307
  }
10286
- selectViewModel(viewModel) {
10287
- const idx = this.viewModelsMain.findIndex(vm => vm === viewModel);
10308
+ selectViewModel(viewModel, closePopup = true) {
10288
10309
  if (!this.multiselect) {
10289
- this._activeIndex = idx;
10290
- this.selectOptionByActiveIndex();
10310
+ this.selectModelByViewModel(viewModel, closePopup);
10291
10311
  }
10292
10312
  else {
10293
- this.viewModelsMain[idx].checked = !this.viewModelsMain[idx].checked;
10313
+ const idx = this.viewModels.findIndex(vm => vm === viewModel);
10314
+ this.viewModels[idx].checked = !this.viewModels[idx].checked;
10294
10315
  this.selectOptions();
10295
10316
  }
10296
10317
  }
10318
+ selectModelByViewModel(viewModel, closePopup = true) {
10319
+ this.model = this.viewModelsMain.find(vm => vm === viewModel).model;
10320
+ this.modelChange.emit(this.model);
10321
+ this._scrollIntoView();
10322
+ if (closePopup) {
10323
+ this.closePopup.emit();
10324
+ }
10325
+ }
10297
10326
  // for single select
10298
- selectOptionByActiveIndex(closePopup = true) {
10299
- if (this._activeIndex > -1) {
10300
- this.model = this.viewModelsMain[this._activeIndex].model;
10301
- this.modelChange.emit(this.model);
10302
- this._scrollIntoView();
10303
- if (closePopup) {
10304
- this.closePopup.emit();
10327
+ selectOptionAndClosePopup() {
10328
+ if (!this.model && this.searchTerm) {
10329
+ const wishModel = this.viewModelsMain.find(vmm => vmm.model[this.displayField] === this.searchTerm);
10330
+ if (wishModel) {
10331
+ this.selectViewModel(wishModel);
10332
+ }
10333
+ else {
10334
+ this.model = undefined;
10335
+ this.modelChange.emit(this.model);
10336
+ this.searchTerm = '';
10305
10337
  }
10306
10338
  }
10339
+ else {
10340
+ this.closePopup.emit();
10341
+ }
10307
10342
  }
10308
10343
  // for multi select
10309
10344
  selectOptions() {
10310
10345
  this.model = this.viewModelsMain.filter(v => v.checked).map(m => m.model);
10311
10346
  this.modelChange.emit(this.model);
10312
10347
  }
10313
- selectNextOption() {
10314
- if (!this._lovItems || this._activeIndex >= this._lovItems.length - 1) {
10315
- return;
10348
+ selectNextOption(back = false) {
10349
+ let nextModel;
10350
+ if (!this.highLightModel) {
10351
+ nextModel = this.viewModels[back ? this.viewModels.length - 1 : 0];
10316
10352
  }
10317
- this._activeIndex++;
10318
- this.selectOptionByActiveIndex(false);
10319
- }
10320
- selectPreviousOption() {
10321
- if (this._activeIndex <= 0) {
10322
- return;
10353
+ else {
10354
+ const currentViewModelIdx = this.viewModels.findIndex(vm => vm === this.highLightModel);
10355
+ if (back) {
10356
+ nextModel = this.viewModels[currentViewModelIdx <= 0 ? this.viewModels.length - 1 : currentViewModelIdx - 1];
10357
+ }
10358
+ else {
10359
+ nextModel = this.viewModels[currentViewModelIdx >= this.viewModels.length - 1 ? 0 : currentViewModelIdx + 1];
10360
+ }
10361
+ }
10362
+ this.highLightModel = nextModel;
10363
+ if (!this.multiselect) {
10364
+ this.selectViewModel(nextModel, false);
10323
10365
  }
10324
- this._activeIndex--;
10325
- this.selectOptionByActiveIndex(false);
10326
10366
  }
10327
10367
  _prepareViewModelsMain() {
10328
10368
  this.viewModelsMain.length = 0;
@@ -10335,10 +10375,11 @@ class ListOfValuesPopupComponent {
10335
10375
  this.viewModels = this.viewModelsMain.filter(vm => vm.model[this.displayField] && vm.model[this.displayField].toLowerCase().includes(this.searchTerm ? this.searchTerm.toLowerCase() : ""));
10336
10376
  }
10337
10377
  _scrollIntoView() {
10338
- if (!this._lovItems || this._lovItems.length <= 0 || this._activeIndex < 0 || !this._lovItems[this._activeIndex] || !this.dropDownList) {
10378
+ const activeIndex = this.viewModels.findIndex(vmm => vmm === this.highLightModel);
10379
+ if (!this._lovItems || this._lovItems.length <= 0 || activeIndex < 0 || !this.dropDownList) {
10339
10380
  return;
10340
10381
  }
10341
- const activeItem = this._lovItems[this._activeIndex].nativeElement ? this._lovItems[this._activeIndex].nativeElement : undefined;
10382
+ const activeItem = this._lovItems[activeIndex].nativeElement ? this._lovItems[activeIndex].nativeElement : undefined;
10342
10383
  const scrollParent = this.dropDownList.nativeElement ? this.dropDownList.nativeElement : undefined;
10343
10384
  this._scrollActiveItemIntoView(activeItem, scrollParent);
10344
10385
  }
@@ -10362,18 +10403,22 @@ ListOfValuesPopupComponent.decorators = [
10362
10403
  { type: Component, args: [{
10363
10404
  selector: 'co-list-of-values-popup',
10364
10405
  template: `
10365
- <div class="lov-options" #dropDownList [overlay]="parentForOverlay" [inheritWidth]="true" [ngClass]="customCssClass" id="lov-popup"
10406
+ <div class="lov-options" [overlay]="parentForOverlay" [inheritWidth]="true" [ngClass]="customCssClass" id="lov-popup"
10366
10407
  [tabIndex]="-1" role="listbox"
10367
10408
  (clickOutside)="closePopup.emit($event)">
10368
- <co-input-search *ngIf="multiselect" [(model)]="searchTerm" (modelChange)="filterViewModels()" [placeholder]="searchPlaceholder"></co-input-search>
10369
- <ul class="dropdown-list">
10370
- <li #lovItem *ngFor="let viewModel of viewModels; let index = index" [class.selected]="viewModel.model === model"
10371
- (click)="selectViewModel(viewModel)" role="option">
10409
+ <co-input-search *ngIf="multiselect"
10410
+ [(model)]="searchTerm"
10411
+ [placeholder]="searchPlaceholder"
10412
+ (keydown)="handleInputKeyDown($event)"
10413
+ (modelChange)="filterViewModels()"></co-input-search>
10414
+ <ul class="dropdown-list" #dropDownList>
10415
+ <li #lovItem *ngFor="let viewModel of viewModels; let index = index" [class.selected]="viewModel === highLightModel"
10416
+ (click)="selectViewModel(viewModel, false)" role="option">
10372
10417
  <ng-container *ngIf="!multiselect">
10373
10418
  <span class="lov-options-text" [textContent]="viewModel.model[displayField]"></span>
10374
10419
  </ng-container>
10375
10420
  <ng-container *ngIf="multiselect">
10376
- <co-input-checkbox [model]="viewModel.checked" (modelChange)="selectViewModel(viewModel)"></co-input-checkbox>
10421
+ <co-input-checkbox [model]="viewModel.checked" (modelChange)="selectViewModel(viewModel, false)"></co-input-checkbox>
10377
10422
  <span class="lov-options-text" [textContent]="viewModel.model[displayField]"></span>
10378
10423
  </ng-container>
10379
10424
  </li>
@@ -10436,6 +10481,7 @@ class ListOfValuesComponent extends BaseInputComponent {
10436
10481
  if (this._lovPopupComponentRef) {
10437
10482
  this._lovPopupComponentRef.instance.searchTerm = model;
10438
10483
  }
10484
+ this.selectedModel = model;
10439
10485
  }
10440
10486
  handleInputKeyDown(event) {
10441
10487
  if (event) {
@@ -10449,13 +10495,13 @@ class ListOfValuesComponent extends BaseInputComponent {
10449
10495
  this._lovPopupComponentRef.instance.selectNextOption();
10450
10496
  return false;
10451
10497
  case KeyboardKey.Up:
10452
- this._lovPopupComponentRef.instance.selectPreviousOption();
10498
+ this._lovPopupComponentRef.instance.selectNextOption(true);
10453
10499
  return false;
10454
10500
  case KeyboardKey.Enter:
10455
- this._lovPopupComponentRef.instance.selectOptionByActiveIndex();
10501
+ this._lovPopupComponentRef.instance.selectOptionAndClosePopup();
10456
10502
  return false;
10457
10503
  case KeyboardKey.Tab:
10458
- this._lovPopupComponentRef.instance.selectOptionByActiveIndex();
10504
+ this._lovPopupComponentRef.instance.selectOptionAndClosePopup();
10459
10505
  }
10460
10506
  }
10461
10507
  }
@@ -10503,11 +10549,13 @@ class ListOfValuesComponent extends BaseInputComponent {
10503
10549
  }
10504
10550
  }
10505
10551
  optionChosen(option) {
10506
- if (this.multiselect) {
10507
- this.selectedModels = option.map(o => o[this.displayField]);
10508
- }
10509
- else {
10510
- this.selectedModel = option[this.displayField];
10552
+ if (option) {
10553
+ if (this.multiselect) {
10554
+ this.selectedModels = option.map(o => o[this.displayField]);
10555
+ }
10556
+ else {
10557
+ this.selectedModel = option[this.displayField];
10558
+ }
10511
10559
  }
10512
10560
  this.model = option;
10513
10561
  this.modelChange.emit(this.model);
@@ -10518,6 +10566,18 @@ class ListOfValuesComponent extends BaseInputComponent {
10518
10566
  this._lovPopupComponentRef = undefined;
10519
10567
  this.focused = false;
10520
10568
  }
10569
+ checkModel() {
10570
+ if (!this.multiselect && this.selectedModel && this.collection) {
10571
+ const model = this.collection.find(c => c[this.displayField] === this.selectedModel);
10572
+ if (model) {
10573
+ this.model = model;
10574
+ }
10575
+ else {
10576
+ this.model = undefined;
10577
+ }
10578
+ this.modelChange.emit(this.model);
10579
+ }
10580
+ }
10521
10581
  _setSelectedModel() {
10522
10582
  if (this.multiselect) {
10523
10583
  if (this.model) {
@@ -10563,6 +10623,7 @@ ListOfValuesComponent.decorators = [
10563
10623
  (rightIconClick)="toggleSelect()"
10564
10624
  (keydown)="handleInputKeyDown($event)"
10565
10625
  (clearIconClick)="clearModel($event)"
10626
+ (blur)="checkModel()"
10566
10627
  >
10567
10628
  </co-input-text>
10568
10629
  <ng-container *ngIf="multiselect">