multiselect WORKING! And added new interface in create-element
This commit is contained in:
		| @@ -1,7 +1,12 @@ | ||||
| import { IItems } from "../../interfaces/items.interface"; | ||||
| import { IItems } from '../../interfaces/items.interface'; | ||||
|  | ||||
| export interface IDataItem{ | ||||
|     category?: string; | ||||
|     categoryItems?: string; | ||||
|     ItemValue: string | IItems | number; | ||||
| } | ||||
| export interface IDataItem { | ||||
|   category?: string; | ||||
|   categoryItems?: string; | ||||
|   ItemValue: string | IItems | number; | ||||
| } | ||||
|  | ||||
| export interface ITextSelect { | ||||
|   placeholder?: string; | ||||
|   selected?: string; | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| import { ICgSelect } from '../../interfaces/cg-select.interface'; | ||||
| import { IItems } from '../../interfaces/items.interface'; | ||||
| import { IDataItem } from './urils.interface'; | ||||
| import { IDataItem, ITextSelect } from './urils.interface'; | ||||
|  | ||||
| /** | ||||
|  * Преобразование каждого елемента полученного из поля Items; | ||||
| @@ -25,6 +26,28 @@ export function getFormatItem(dataItem: any, index: number): IItems { | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Вставка изначального текста селекта(до выбора) | ||||
|  * @param {ITextSelect} data объект в котором находяться title селекта | ||||
|  * @param {HTMLElement | null | undefined} select елемент селекта, куда будет вставляться title | ||||
|  * @returns {HTMLElement} возвращает сформированный елемент селекта | ||||
|  */ | ||||
| export function getSelectText( | ||||
|   data: ITextSelect, | ||||
|   select: HTMLElement | null | undefined, | ||||
| ): HTMLElement { | ||||
|   const { placeholder, selected } = data; | ||||
|  | ||||
|   if (placeholder) { | ||||
|     select!.innerText = placeholder; | ||||
|   } else if (selected) { | ||||
|     select!.innerText = selected; | ||||
|   } else { | ||||
|     select!.innerText = 'Select...'; | ||||
|   } | ||||
|   return select!; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Проверка содержит ли item  указанные свойства, | ||||
|  * @param {object} item проверяемый на определенную структуру элемент | ||||
| @@ -92,3 +115,29 @@ export function nativeOptionOrdinary(element: NodeListOf<Element> | undefined, i | ||||
|     } | ||||
|   }); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Поведение нативного(Multiple) селекта при выборе в кастомном | ||||
|  * @param {NodeListOf<Element> | undefined} element NodeList нативного селекта | ||||
|  * @param {string} item выбранный элемент в кастомном селекте | ||||
|  * @param {boolean} condition специальный флаг при котором добавляются/убераются атрибуты у нативного селекта | ||||
|  */ | ||||
| export function nativeOptionMultiple( | ||||
|   element: NodeListOf<Element> | undefined, | ||||
|   item: string, | ||||
|   condition: boolean, | ||||
| ) { | ||||
|   element!.forEach((option) => { | ||||
|     if (condition == true) { | ||||
|       if (option.textContent === item) { | ||||
|         option.setAttribute('selected', 'selected'); | ||||
|       } | ||||
|     } else if (condition == false) { | ||||
|       if (option.textContent === item) { | ||||
|         option.removeAttribute('selected'); | ||||
|       } | ||||
|     } else { | ||||
|       return; | ||||
|     } | ||||
|   }); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 MaxOvs
					MaxOvs