@rifaniponk/ionic-selectable
Version:
An Ionic component similar to Ionic Select, that allows to search items, including async search, group, add, edit, delete items, and much more. Supports Angular 16-20 and Ionic 7-8.
87 lines (80 loc) • 3.16 kB
text/typescript
import { AfterViewInit, Component, ElementRef, HostBinding, HostListener, ViewChild } from '@angular/core';
import { IonContent, IonInfiniteScroll, IonSearchbar, NavParams, IonicModule } from '@ionic/angular';
import { IonicSelectableComponent } from './ionic-selectable.component';
import { FormsModule } from '@angular/forms';
import { NgIf, NgTemplateOutlet, NgFor, NgClass, NgStyle } from '@angular/common';
export class IonicSelectableModalComponent implements AfterViewInit {
_content!: IonContent;
_header!: HTMLElement;
selectComponent: IonicSelectableComponent;
_searchbarComponent!: IonSearchbar;
_infiniteScroll!: IonInfiniteScroll;
_cssClass = true;
get _canClearCssClass(): boolean {
return this.selectComponent.canClear;
}
get _isMultipleCssClass(): boolean {
return this.selectComponent.isMultiple;
}
get _isSearchingCssClass(): boolean {
return this.selectComponent._isSearching;
}
get _isIos(): boolean {
return this.selectComponent._isIos;
}
_isMD(): boolean {
return this.selectComponent._isMD;
}
get _isAddItemTemplateVisibleCssClass(): boolean {
return this.selectComponent._isAddItemTemplateVisible;
}
onResize() {
// ion-footer inside the template might change its height when
// device orientation changes.
this.selectComponent._positionAddItemTemplate();
}
constructor(
private navParams: NavParams,
public _element: ElementRef,
) {
this.selectComponent = this.navParams.get('selectComponent');
this.selectComponent._modalComponent = this;
this.selectComponent._selectedItems = [];
if (!this.selectComponent._isNullOrWhiteSpace(this.selectComponent.value)) {
if (this.selectComponent.isMultiple) {
this.selectComponent.value.forEach((item: any) => {
this.selectComponent._selectedItems.push(item);
});
} else {
this.selectComponent._selectedItems.push(this.selectComponent.value);
}
}
this.selectComponent._setItemsToConfirm(this.selectComponent._selectedItems);
}
ngAfterViewInit() {
this._header = this._element.nativeElement.querySelector('ion-header');
if (this._searchbarComponent && this.selectComponent.shouldFocusSearchbar) {
// Focus after a delay because focus doesn't work without it.
setTimeout(() => {
this._searchbarComponent.setFocus();
}, 1000);
}
}
}