Skip to content

Commit

Permalink
296 Newly added criteria collapse existing
Browse files Browse the repository at this point in the history
  • Loading branch information
cpreisinger committed Dec 17, 2024
1 parent 44ef23f commit de30760
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/javascript/controllers/evaluation_criteria_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default class extends Controller {
this.replacePlaceholders(newCriteria);
this.enableInputs(newCriteria);

this.collapseAllCriteria();
this.expandCriterion(newCriteria);

this.criteriaListTarget.appendChild(newCriteria);

this.updateCriteriaTitles();
Expand All @@ -40,6 +43,26 @@ export default class extends Controller {
this.updateCriteriaTitles();
}

collapseAllCriteria() {
const accordionButtons = this.element.querySelectorAll(
".usa-accordion__button"
);
const accordions = this.element.querySelectorAll(".usa-accordion__content");

accordionButtons.forEach((button) =>
button.setAttribute("aria-expanded", false)
);
accordions.forEach((content) => content.setAttribute("hidden", ""));
}

expandCriterion(criterion) {
const accordionButton = criterion.querySelector(".usa-accordion__button");
const accordionContent = criterion.querySelector(".usa-accordion__content");

if (accordionButton) accordionButton.setAttribute("aria-expanded", true);
if (accordionContent) accordionContent.removeAttribute("hidden");
}

toggleScoringType(event) {
const row = event.target.closest(".criteria-row");
const scoringType = row.querySelector(".scoring-type-radio:checked").value;
Expand Down

0 comments on commit de30760

Please sign in to comment.