multiselect WORKING! And added new interface in create-element

This commit is contained in:
MaxOvs
2023-01-09 16:10:43 +03:00
parent 8eeabf44b2
commit 482bd59756
5 changed files with 140 additions and 34 deletions

View File

@@ -0,0 +1,8 @@
import { ICgSelect } from '../../interfaces/cg-select.interface';
export interface IcreateBreadCrumb {
element: Element | null;
option: ICgSelect;
indexes: number[];
selectedItems: string[];
}

View File

@@ -1,3 +1,5 @@
import { IcreateBreadCrumb } from './create-element.interface';
/**
* Метод который создает нативный селект
* @returns {HTMLSelectElement} Возвращает созданный нативный селект
@@ -29,12 +31,17 @@ export function createNativeSelectOption(): HTMLOptionElement {
* @param {string} id уникальное id выбранного элемента
* @returns {HTMLElement} возвращает сформированный HTMLElement chips item
*/
export function createBreadcrumb(data: any, title: string, index: number, id: string) {
export function createBreadcrumb(
data: IcreateBreadCrumb,
title: string,
index: number,
id: string,
) {
const { element, option, indexes, selectedItems } = data;
const { placeholder, styles } = option;
const selected = element.querySelector('.selected');
const nativeOption = element.querySelectorAll('.nativeSelect__nativeOption');
const selected = element!.querySelector('.selected');
const nativeOption = element!.querySelectorAll('.nativeSelect__nativeOption');
const liChip = document.createElement('li');
const textNode = document.createTextNode(title);
@@ -55,7 +62,7 @@ export function createBreadcrumb(data: any, title: string, index: number, id: st
liChip.appendChild(svgIcon);
if (styles) {
const { chips } = styles;
// const { chips } = styles;
// customStylesFormat(chips, liChip);
}
@@ -80,7 +87,7 @@ export function createBreadcrumb(data: any, title: string, index: number, id: st
// checkBox.parentElement.classList.remove('active');
if (!selectedItems.length) {
selected.innerText = placeholder;
//selected?.textContent = placeholder;
}
// liChip.parentElement.removeChild(liChip);