Added constructor.js

This commit is contained in:
MaxOvs19
2023-02-16 17:32:08 +03:00
parent 2cd1920eb5
commit a3c433d328
8 changed files with 173 additions and 39 deletions

View File

@@ -917,17 +917,19 @@ export class CGSelect implements ICgSelect {
* @param callback
* @method on
*/
public on(state: string, callback: (state: any) => any) {
public on(state: string, callback: (state: any, value?: string) => any) {
const options = this.element?.querySelectorAll('.list__item');
let value = '';
switch (state) {
case 'select':
options?.forEach((option: Element) => {
option.addEventListener('click', () => {
console.log('option:select', option.textContent);
value = option.textContent!;
callback(state, value);
});
});
callback(state);
break;
case 'close':
this.element!.addEventListener('click', () => {