From da3b70027f08b05c051c0cc3b532be9810f70195 Mon Sep 17 00:00:00 2001 From: Michael Dickson Date: Thu, 8 Aug 2024 16:33:02 -0400 Subject: [PATCH] disable increment/decrement instead of hide --- blocks/gmo-program-details/gmo-program-details.css | 4 ++++ scripts/program-calendar.js | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/blocks/gmo-program-details/gmo-program-details.css b/blocks/gmo-program-details/gmo-program-details.css index 646a18b..464632f 100644 --- a/blocks/gmo-program-details/gmo-program-details.css +++ b/blocks/gmo-program-details/gmo-program-details.css @@ -224,6 +224,10 @@ body { transform: rotate(180deg); } } + &.disabled { + background-color: #c6c6c6; + cursor: default; + } } & .current-year { line-height: 32px; diff --git a/scripts/program-calendar.js b/scripts/program-calendar.js index fd53430..b4b041f 100644 --- a/scripts/program-calendar.js +++ b/scripts/program-calendar.js @@ -52,9 +52,9 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period) // get array of all years to be included let years = calendarYears(viewStartYear, viewEndYear); + // disable increment/decrement if only one year in view if (years.length === 1) { - document.querySelector('.inc-dec-wrapper > .year-switch').classList.add('inactive'); - document.querySelector('.inc-dec-wrapper > .current-year').classList.add('single'); + document.querySelector('.inc-dec-wrapper > .year-switch').classList.add('disabled'); } // build the calendar background here as we already know the period and style @@ -261,7 +261,9 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period) document.querySelector('.gmo-program-details.block').addEventListener('click', dismissDropdown); block.querySelectorAll('.year-switch > .year-toggle').forEach((control) => { control.removeEventListener('click', changePeriod); - control.addEventListener('click', changePeriod); + if (years.length > 1) { + control.addEventListener('click', changePeriod); + } }); block.querySelector('.right-controls .today-button').addEventListener('click', () => { const calendarWrapper = document.querySelector('.calendar-wrapper')