Work method button control finished.

This commit is contained in:
Макс Овсяников 2022-10-13 13:42:46 +03:00
parent b2dd417ba6
commit ce941a3dad
4 changed files with 48 additions and 3 deletions

View File

@ -94,6 +94,18 @@ export class DropDown {
} }
} }
buttonControl(button, method) {
button.addEventListener('click', () => {
if (method === 'open') {
this.#open(true);
} else if (method === 'close') {
this.#close();
} else {
return;
}
});
}
#init(options) { #init(options) {
this.#options = options; this.#options = options;
const { items, multiselect, url } = this.#options; const { items, multiselect, url } = this.#options;
@ -252,13 +264,18 @@ export class DropDown {
this.#addOptionsBehaviour(); this.#addOptionsBehaviour();
} }
#open() { #open(oneClick) {
this.#list = this.#element.querySelector('.list'); this.#list = this.#element.querySelector('.list');
this.#caret = this.#element.querySelector('.caret'); this.#caret = this.#element.querySelector('.caret');
if (oneClick === true) {
this.#list.classList.add('open');
this.#caret.classList.add('caret_rotate');
} else {
this.#list.classList.toggle('open'); this.#list.classList.toggle('open');
this.#caret.classList.toggle('caret_rotate'); this.#caret.classList.toggle('caret_rotate');
} }
}
#close() { #close() {
this.#list.classList.remove('open'); this.#list.classList.remove('open');

View File

@ -14,6 +14,12 @@
<button class="cg-dropdown cg-dropdown_two"></button> <button class="cg-dropdown cg-dropdown_two"></button>
<button class="cg-dropdown cg-dropdown_three"></button> <button class="cg-dropdown cg-dropdown_three"></button>
<button class="cg-dropdown cg-dropdown_button" style="margin-top: 50px"></button>
</div>
<div class="buttonControlBox">
<button class="buttonControl button__open">Open</button>
<button class="buttonControl button__close">Close</button>
</div> </div>
</body> </body>
<script type="module" src="index.js"></script> <script type="module" src="index.js"></script>

View File

@ -69,3 +69,19 @@ const dropdown3 = new DropDown({
multiselect: true, multiselect: true,
multiselectTag: true, multiselectTag: true,
}); });
const dropdown4 = new DropDown({
selector: '.cg-dropdown_button',
placeholder: 'Выберите авто',
items: ['Russia', 'USA', 'England', 'Turkey', 'France'],
multiselect: true,
multiselectTag: true,
});
// dropdown4.disabled(true);
const buttonOpen = document.querySelector('.button__open');
const buttonClose = document.querySelector('.button__close');
dropdown4.buttonControl(buttonOpen, 'open');
dropdown4.buttonControl(buttonClose, 'close');

View File

@ -12,6 +12,7 @@ body {
display: flex; display: flex;
align-items: baseline; align-items: baseline;
justify-content: space-between; justify-content: space-between;
flex-wrap: wrap;
width: 900px; width: 900px;
} }
@ -195,3 +196,8 @@ input[type='checkbox'] {
.disabled { .disabled {
background-color: #8f9195 !important; background-color: #8f9195 !important;
} }
.buttonControlBox {
margin: -25px auto 0 auto;
width: 300px;
}