This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YSHOP2-1031: COD themes > theme 1 > dropdown menu bugs (#416)
## Ticket [YSHOP2-1031](https://youcanshop.atlassian.net/browse/YSHOP2-1031) ## QA Steps - [ ] `pnpm i` - [ ] `pnpm dev` - [ ] Make sure that you have more than one dropdown variant in your product - [ ] Verify that we have corrected the functionality of the dropdown menu [YSHOP2-1031]: https://youcanshop.atlassian.net/browse/YSHOP2-1031?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
3 changed files
with
54 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,66 @@ | ||
const dropdownBtn = $('.dropbtn'); | ||
const dropdownContent = $('.dropdown-content'); | ||
const dropdownOptions = dropdownContent?.querySelectorAll('li'); | ||
|
||
function showDropDownMenu(customContent) { | ||
if(customContent) { | ||
customContent.classList.toggle('show'); | ||
} else if (dropdownContent) { | ||
dropdownContent.classList.toggle('show'); | ||
} | ||
/** | ||
* @param {HTMLElement} element | ||
*/ | ||
function showDropDownMenu(element) { | ||
element.classList.toggle('show'); | ||
} | ||
|
||
const hideDropDownMenu = (event) => { | ||
/** | ||
* @param {HTMLElement} element | ||
* @param {Event} event | ||
*/ | ||
function hideDropDownMenu(element, event) { | ||
if (!event.target.matches('.dropbtn, .dropbtn *')) { | ||
dropdownContent?.classList.remove('show'); | ||
element?.classList.remove('show'); | ||
} | ||
}; | ||
|
||
window.addEventListener('click', (event) => hideDropDownMenu(event)); | ||
} | ||
|
||
function selectOption(e) { | ||
const selectedOption = e.target; | ||
/** | ||
* @param {HTMLElement} element | ||
* @param {HTMLElement} options | ||
* @param {Event} event | ||
*/ | ||
function selectOption(element, options, event) { | ||
const selectedOption = event.target; | ||
|
||
dropdownOptions.forEach((option) => { | ||
options.forEach((option) => { | ||
option.classList.remove('selected'); | ||
}); | ||
|
||
selectedOption.classList.add('selected'); | ||
dropdownBtn.firstElementChild.textContent = selectedOption.textContent; | ||
element.firstElementChild.textContent = selectedOption.textContent; | ||
} | ||
|
||
if(dropdownOptions) { | ||
dropdownOptions.forEach((option) => { | ||
option.addEventListener('click', selectOption); | ||
function dropdownMenu() { | ||
const dropdownInputs = document.querySelectorAll('.dropdown-input'); | ||
|
||
if(dropdownInputs.length === 0) { | ||
return; | ||
} | ||
|
||
dropdownInputs.forEach((dropDownInput) => { | ||
const selectInput = dropDownInput.querySelector('.dropbtn'); | ||
const dropdownContent = dropDownInput.querySelector('.dropdown-content'); | ||
|
||
window.addEventListener('DOMContentLoaded', (event) => { | ||
if (option.classList.contains('selected')) { | ||
dropdownBtn.firstElementChild.textContent = option.textContent; | ||
} | ||
selectInput.addEventListener('click', () => showDropDownMenu(dropdownContent)); | ||
window.addEventListener('click', (event) => hideDropDownMenu(dropdownContent, event)); | ||
|
||
const selectOptions = dropdownContent.querySelectorAll('li'); | ||
|
||
if(selectOptions.length === 0) { | ||
return; | ||
} | ||
|
||
selectOptions.forEach((option) => { | ||
option.addEventListener('click', (event) => selectOption(selectInput, selectOptions, event)); | ||
|
||
window.addEventListener('DOMContentLoaded', (event) => { | ||
if (option.classList.contains('selected')) { | ||
selectInput.firstElementChild.textContent = option.textContent; | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
dropdownMenu(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters