Added method On
This commit is contained in:
parent
1c5ee130f9
commit
63d5f0e35f
@ -25,6 +25,11 @@ const dropdown = new CGSelect({
|
|||||||
width: '824px',
|
width: '824px',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// multiselect: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
dropdown.on('select', function (e) {
|
||||||
|
console.log(`this state: ${e}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ------------------------------NativeSelect-----------------------
|
// ------------------------------NativeSelect-----------------------
|
||||||
|
@ -914,4 +914,31 @@ export class CGSelect implements ICgSelect {
|
|||||||
const select: string = options[index].innerText;
|
const select: string = options[index].innerText;
|
||||||
this.render(select);
|
this.render(select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public on(state: string, callback: (state: any) => any) {
|
||||||
|
const options = this.element?.querySelectorAll('.list__item');
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case 'select':
|
||||||
|
options?.forEach((option: Element) => {
|
||||||
|
option.addEventListener('click', () => {
|
||||||
|
console.log('option:select', option.textContent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
callback(state);
|
||||||
|
break;
|
||||||
|
case 'close':
|
||||||
|
this.element!.addEventListener('click', () => {
|
||||||
|
console.log('list:close', this.list!.classList.contains('close'));
|
||||||
|
});
|
||||||
|
callback(state);
|
||||||
|
break;
|
||||||
|
case 'open':
|
||||||
|
this.element!.addEventListener('click', () => {
|
||||||
|
console.log('list:open', this.list!.classList.contains('open'));
|
||||||
|
});
|
||||||
|
callback(state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user