File
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Outputs
|
|
HostListeners
|
|
Accessors
|
|
_selectedDpdwnInput
|
Type : any
|
|
dropdownList
|
Type : Array<any>
|
|
dynamicplaceholder
|
Type : string
|
|
selectedFilters
|
Type : Array<any>
|
|
Outputs
errorOutput
|
Type : EventEmitter<any>
|
|
selectionChanged
|
Type : EventEmitter<any>
|
|
HostListeners
document:click
|
Arguments : '$event'
|
document:click(event: any)
|
|
Methods
clickout
|
clickout(event: any)
|
Decorators :
@HostListener('document:click', ['$event'])
|
|
Parameters :
Name |
Type |
Optional |
event |
any
|
No
|
|
DisplayDropdown
|
DisplayDropdown()
|
|
|
dropDownSelectedShow
|
dropDownSelectedShow()
|
|
|
DropdownValueSelected
|
DropdownValueSelected(listItem)
|
|
Parameters :
Name |
Optional |
listItem |
No
|
|
isChecked
|
isChecked(item)
|
|
|
ngOnChanges
|
ngOnChanges()
|
|
|
writeValue
|
writeValue(value?: any)
|
|
Parameters :
Name |
Type |
Optional |
value |
any
|
Yes
|
|
_dropdownList
|
Type : Array<any>
|
|
Private
_placeholder
|
Type : string
|
|
_selectedFilters
|
Type : Array<any>
|
|
displayDropdown
|
Default value : false
|
|
searchField
|
Type : ElementRef
|
Decorators :
@ViewChild('autocompleteInput')
|
|
selected
|
Type : []
|
Default value : []
|
|
Accessors
selectedFilters
|
getselectedFilters()
|
|
setselectedFilters(val)
|
|
|
dropdownList
|
getdropdownList()
|
|
setdropdownList(val)
|
|
|
selectedDpdwnInput
|
getselectedDpdwnInput()
|
|
setselectedDpdwnInput(val)
|
|
|
import { Component, Input, HostListener, ElementRef, Output, EventEmitter, OnChanges, ViewChild, ChangeDetectorRef } from '@angular/core';
import { ToasterService } from '../../services/toaster/toaster.service';
@Component({
selector: 'app-material-auto-complete',
templateUrl: './material-auto-complete.component.html',
styleUrls: ['./material-auto-complete.component.scss']
})
export class MaterialAutoCompleteComponent implements OnChanges {
@Input() dynamicplaceholder:string;
@Input() dependency;
@Input() checkFilters;
@Input()
get selectedFilters() {
return this._selectedFilters;
}
set selectedFilters(val) {
this._selectedFilters = val;
this.selected = val;
this.dropDownSelectedShow();
}
@Input()
get dropdownList() {
return this._dropdownList;
}
set dropdownList(val) {
this._dropdownList = val;
this.dropDownSelectedShow();
}
constructor(private _elementRef: ElementRef<HTMLElement>, private changeDetectorRef: ChangeDetectorRef, public toasterService: ToasterService) {}
get selectedDpdwnInput() {
return this._selectedDpdwnInput;
}
set selectedDpdwnInput(val) {
this._selectedDpdwnInput = val;
}
_selectedFilters: Array<any>;
_dropdownList: Array<any>;
selected = [];
@ViewChild('autocompleteInput') searchField: ElementRef;
@Output() selectionChanged: EventEmitter<any> = new EventEmitter<any>();
@Output() errorOutput: EventEmitter<any> = new EventEmitter<any>();
displayDropdown = false;
private _placeholder: string;
@Input() _selectedDpdwnInput: any;
@HostListener('document:click', ['$event'])
clickout(event: any) {
if (!(this._elementRef && this._elementRef.nativeElement.contains(event.target))) {
this.displayDropdown = false;
}
}
ngOnChanges() {
if (!this.dropdownList) {
throw new TypeError('\'dropdownList\' is Required');
} else if (!(this.dropdownList instanceof Array)) {
throw new TypeError('\'dropdownList\' should be an Array of objects');
}
}
DropdownValueSelected(listItem) {
if (listItem) {
if (this.selected.includes(listItem)) {
this.selected = this.selected.filter(item => {
if (item == listItem) {
return false;
} else {
return true;
}
});
} else {
this.selected.push(listItem);
}
}
this.selectionChanged.emit(this.selected);
this.dropDownSelectedShow();
}
dropDownSelectedShow() {
if (this.selected.length > 0) {
this.writeValue(`${this.selected.length} selections`);
} else {
this.writeValue(`Select ${this.dynamicplaceholder.toLowerCase()}`);
}
}
DisplayDropdown() {
if(!this.dependency || (this.dependency && this.checkFilters && this.checkFilters[this.dependency.reference])){
this.displayDropdown = true;
this.changeDetectorRef.detectChanges();
setTimeout(() => {
this.searchField.nativeElement.focus();
}, 100);
this.errorOutput.emit(null)
}else{
this.errorOutput.emit({displayName: this.dependency.displayName})
}
}
isChecked(item) {
if (this.selected.includes(item)) {
return true;
} else {
return false;
}
}
writeValue(value?: any) {
this.selectedDpdwnInput = value;
}
}
<div class="sb-autocomp-dropdown">
<mat-form-field class="sb-autocomp-dropdown__formfield">
<input matInput (focus)="DisplayDropdown()" readonly name="selectedDpdwnInput"
[value]="_selectedDpdwnInput ? _selectedDpdwnInput : ''" />
</mat-form-field>
<div class="sb-autocomp-dropdown__list" *ngIf="displayDropdown">
<input matInput #autocompleteInput placeholder="Search" name="search"/>
<ul>
<li *ngFor="let listItem of dropdownList | autocomplete: {filterKey: autocompleteInput.value}">
<mat-checkbox class="sb-mat__checkbox sb-mat__checkbox--primary" [checked]="isChecked(listItem)" (change)="DropdownValueSelected(listItem)">{{ listItem }}
</mat-checkbox>
</li>
</ul>
</div>
</div>
@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
.sb-autocomp-dropdown {
position: relative;
width: 100%;
min-width: calculateRem(280px);
&__list {
position: absolute;
top: 100%;
background: var(--sb-dropdown-menu-bg);
border-radius: calculateRem(4px);
z-index: 1;
width: 100%;
max-height: calculateRem(280px);
overflow: auto;
box-shadow: 0 calculateRem(2px) calculateRem(3px) 0 rgb(34 36 38 / 15%);
::ng-deep {
ul {
padding-left: calculateRem(16px);
li {
margin-bottom: calculateRem(8px);
}
}
.mat-input-element.mat-form-field-autofill-control {
padding: calculateRem(8px) calculateRem(24px);
margin-top: calculateRem(8px);
border-radius: calculateRem(24px);
}
.mat-checkbox-checkmark-path {
stroke: var(--sb-dropdown-menu-bg) !important;
}
}
}
::ng-deep {
.mat-form-field {
width: 100%;
height: calculateRem(32px);
padding: 0 calculateRem(20px);
border: calculateRem(1px) solid var(--gray-100);
background: var(--sb-dropdown-menu-bg);
border-radius: calculateRem(4px);
&.mat-form-field-appearance-legacy {
.mat-form-field-wrapper {
padding-bottom: 0;
}
.mat-form-field-wrapper,
.mat-form-field-flex {
height: 100%;
}
.mat-form-field-flex {
align-items: center;
}
.mat-form-field-underline {
height: 0;
}
.mat-form-field-infix {
padding: 0;
width: 100%;
border: none;
}
}
}
.mat-checkbox-indeterminate.mat-accent .mat-checkbox-background,
.mat-checkbox-checked.mat-accent .mat-checkbox-background {
background-color: var(--primary-color);
}
}
}
::ng-deep {
html[layout="joy"] .sb-autocomp-dropdown .mat-form-field, .sb-autocomp-dropdown__list {
border-radius: calculateRem(24px);
}
html[data-mode="darkmode"] .sb-mat__checkbox.sb-mat__checkbox--primary .mat-checkbox-frame {
border-color: var(--gray-100);
}
.sb-autocomp-dropdown__list {
top: 0px !important;
}
.sb-autocomp-dropdown__list ul {
list-style: none !important
}
.sb-autocomp-dropdown .mat-form-field {
height: 2.5rem !important;
}
}
Legend
Html element with directive