-
Notifications
You must be signed in to change notification settings - Fork 91
Countdown Accessibility Changes #871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gilbert-hernandez
merged 16 commits into
accessibility_audit
from
KAD-4904_count_down_pause_button
Jan 12, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
217a233
KAD-4904 Add play/pause button to countdown block. Also respect prefe…
gilbert-hernandez 076fde4
Fix code style issues with ESLint
lint-action 446c2b3
Merge branch 'master' of https://github.com/stellarwp/kadence-blocks …
gilbert-hernandez 14f4ede
KAD-4907 Add function to announce to screen readers.
gilbert-hernandez b82ea9c
Fix code style issues with ESLint
lint-action 60b6ddf
KAD-4905 Add timer role to the countdown.
gilbert-hernandez 62f0b6f
Merge branch 'KAD-4904_count_down_pause_button' of https://github.com…
gilbert-hernandez ed55359
KAD-4904 Add select control for pause button placement.
gilbert-hernandez 55755ff
Fix code style issues with ESLint
lint-action d1d1da1
KAD-4904 Update frontend pause style.
gilbert-hernandez 9cb0e2c
Merge branch 'accessibility_audit' into KAD-4904_count_down_pause_button
ravinderk 374e815
KAD-4904 Added text domain for aria label, title, and announcement tr…
gilbert-hernandez 117a306
Fix code style issues with ESLint
lint-action 882b5f8
Merge branch 'accessibility_audit' into KAD-4904_count_down_pause_button
ravinderk 4afdff3
KAD-4904 Update play/pause icons with SVGs.
gilbert-hernandez 46e9944
Fix code style issues with ESLint
lint-action File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| timers: JSON.parse(kadence_blocks_countdown.timers), | ||
| listenerCache: {}, | ||
| sliderEventCache: {}, | ||
| prefersReducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches, | ||
| isInViewport(el) { | ||
| const rect = el.getBoundingClientRect(); | ||
| return ( | ||
|
|
@@ -168,7 +169,32 @@ | |
| } | ||
| return element; | ||
| }, | ||
| announceToScreenReader(message) { | ||
| // Create or get the live region for announcements | ||
| let liveRegion = document.getElementById('kb-countdown-announcements'); | ||
| if (!liveRegion) { | ||
| liveRegion = document.createElement('div'); | ||
| liveRegion.id = 'kb-countdown-announcements'; | ||
| liveRegion.setAttribute('role', 'status'); | ||
| liveRegion.setAttribute('aria-live', 'polite'); | ||
| liveRegion.setAttribute('aria-atomic', 'true'); | ||
| liveRegion.className = 'screen-reader-text'; | ||
| liveRegion.style.cssText = | ||
| 'position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden;'; | ||
| document.body.appendChild(liveRegion); | ||
| } | ||
| // Clear previous message and set new one | ||
| liveRegion.textContent = ''; | ||
| setTimeout(() => { | ||
| liveRegion.textContent = message; | ||
| }, 100); | ||
| }, | ||
| updateTimerInterval(element, id, parent) { | ||
| // Check if paused | ||
| if (this.cache[id] && this.cache[id].paused) { | ||
| return; | ||
| } | ||
|
|
||
| const currentTimeStamp = new Date(); | ||
| const userTimezoneOffset = -1 * (new Date().getTimezoneOffset() / 60); | ||
| let total = ''; | ||
|
|
@@ -317,6 +343,10 @@ | |
| window.location.href = window.kadenceCountdown.timers[id].redirect; | ||
| } | ||
| } else if ('hide' === window.kadenceCountdown.timers[id].action) { | ||
| // Announce to screen readers before hiding | ||
| window.kadenceCountdown.announceToScreenReader( | ||
| wp.i18n.__('Countdown timer has ended.', 'kadence-blocks') | ||
| ); | ||
| parent.style.display = 'none'; | ||
| } else if ('message' === window.kadenceCountdown.timers[id].action) { | ||
| if (parent.querySelector('.kb-countdown-inner-first')) { | ||
|
|
@@ -328,8 +358,26 @@ | |
| if (parent.querySelector('.kb-countdown-inner-second')) { | ||
| parent.querySelector('.kb-countdown-inner-second').style.display = 'none'; | ||
| } | ||
| if (parent.querySelector('.kb-countdown-inner-complete')) { | ||
| parent.querySelector('.kb-countdown-inner-complete').style.display = 'block'; | ||
| const completeContent = parent.querySelector('.kb-countdown-inner-complete'); | ||
| if (completeContent) { | ||
| completeContent.style.display = 'block'; | ||
| // Make the replacement content a live region for screen readers | ||
| completeContent.setAttribute('role', 'status'); | ||
| completeContent.setAttribute('aria-live', 'polite'); | ||
| completeContent.setAttribute('aria-atomic', 'true'); | ||
| // Announce the content change | ||
| const completeText = window.kadenceCountdown.stripHtml( | ||
| completeContent.textContent || completeContent.innerText || '' | ||
| ); | ||
| if (completeText.trim()) { | ||
| window.kadenceCountdown.announceToScreenReader( | ||
| wp.i18n.__('Countdown timer has ended.', 'kadence-blocks') + ' ' + completeText | ||
| ); | ||
| } else { | ||
| window.kadenceCountdown.announceToScreenReader( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gilbert-hernandez can we make this translatable? |
||
| wp.i18n.__('Countdown timer has ended. New content is now available.', 'kadence-blocks') | ||
| ); | ||
| } | ||
| } | ||
| parent.style.opacity = 1; | ||
| if (window.kadenceCountdown.timers[id].revealOnLoad) { | ||
|
|
@@ -585,7 +633,9 @@ | |
| if (sticky && !window.kadenceCountdown.timers[id].timer) { | ||
| setTimeout(function () { | ||
| parent.style.height = parent.scrollHeight + 'px'; | ||
| sticky.style.transition = 'height 0.8s ease'; | ||
| if (!window.kadenceCountdown.prefersReducedMotion) { | ||
| sticky.style.transition = 'height 0.8s ease'; | ||
| } | ||
| sticky.style.height = Math.floor(sticky.scrollHeight + parent.scrollHeight) + 'px'; | ||
| }, 200); | ||
| setTimeout(function () { | ||
|
|
@@ -632,12 +682,84 @@ | |
| { element: slider, event: 'splide:moved', handler: movedHandler }, | ||
| ]; | ||
| }, | ||
| togglePause(id, button) { | ||
| if (!window.kadenceCountdown.cache[id]) { | ||
| return; | ||
| } | ||
|
|
||
| const isPaused = window.kadenceCountdown.cache[id].paused || false; | ||
|
|
||
| if (isPaused) { | ||
| // Resume | ||
| window.kadenceCountdown.cache[id].paused = false; | ||
| button.setAttribute('aria-pressed', 'false'); | ||
| button.setAttribute('aria-label', wp.i18n.__('Pause countdown timer', 'kadence-blocks')); | ||
| button.setAttribute('title', wp.i18n.__('Pause countdown', 'kadence-blocks')); | ||
| const icon = button.querySelector('.kb-countdown-pause-icon'); | ||
| if (icon) { | ||
| icon.innerHTML = | ||
| '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="6" y="4" width="4" height="16" rx="1" fill="currentColor" /><rect x="14" y="4" width="4" height="16" rx="1" fill="currentColor" /></svg>'; | ||
| } | ||
| button.classList.remove('kb-countdown-paused'); | ||
|
|
||
| // Restart the interval | ||
| if (window.kadenceCountdown.cache[id].element && window.kadenceCountdown.cache[id].parent) { | ||
| // Update immediately | ||
| window.kadenceCountdown.updateTimerInterval( | ||
| window.kadenceCountdown.cache[id].element, | ||
| id, | ||
| window.kadenceCountdown.cache[id].parent | ||
| ); | ||
| // Then set up interval | ||
| window.kadenceCountdown.cache[id].interval = setInterval(function () { | ||
| window.kadenceCountdown.updateTimerInterval( | ||
| window.kadenceCountdown.cache[id].element, | ||
| id, | ||
| window.kadenceCountdown.cache[id].parent | ||
| ); | ||
| }, 1000); | ||
| } | ||
| } else { | ||
| // Pause | ||
| window.kadenceCountdown.cache[id].paused = true; | ||
| button.setAttribute('aria-pressed', 'true'); | ||
| button.setAttribute('aria-label', wp.i18n.__('Resume countdown timer', 'kadence-blocks')); | ||
| button.setAttribute('title', wp.i18n.__('Resume countdown', 'kadence-blocks')); | ||
| const icon = button.querySelector('.kb-countdown-pause-icon'); | ||
| if (icon) { | ||
| icon.innerHTML = | ||
| '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8 5v14l11-7z" fill="currentColor" /></svg>'; | ||
| } | ||
| button.classList.add('kb-countdown-paused'); | ||
|
|
||
| // Clear the interval | ||
| if (window.kadenceCountdown.cache[id].interval) { | ||
| clearInterval(window.kadenceCountdown.cache[id].interval); | ||
| window.kadenceCountdown.cache[id].interval = null; | ||
| } | ||
| } | ||
| }, | ||
| checkAndStartTimer(id, element, parent) { | ||
| // Only check for evergreen timers | ||
| if (window.kadenceCountdown.timers[id].type !== 'evergreen') { | ||
| return; | ||
| } | ||
|
|
||
| // Don't start if user prefers reduced motion | ||
| if (window.kadenceCountdown.prefersReducedMotion) { | ||
| // Just update once to show the initial time | ||
| if (!window.kadenceCountdown.cache[id].started) { | ||
| window.kadenceCountdown.cache[id].started = true; | ||
| window.kadenceCountdown.updateTimerInterval(element, id, parent); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Don't start if paused | ||
| if (window.kadenceCountdown.cache[id] && window.kadenceCountdown.cache[id].paused) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if timer should start based on viewport and active slide | ||
| if (window.kadenceCountdown.isInViewport(parent) && window.kadenceCountdown.isInActiveSlide(parent)) { | ||
| // Start the timer if it hasn't been started yet | ||
|
|
@@ -671,6 +793,15 @@ | |
| window.kadenceCountdown.cache[id].revealed = false; | ||
| window.kadenceCountdown.cache[id].cookie = ''; | ||
| window.kadenceCountdown.cache[id].started = false; | ||
| window.kadenceCountdown.cache[id].paused = false; // Start unpaused so initial display works | ||
| window.kadenceCountdown.cache[id].element = element; | ||
| window.kadenceCountdown.cache[id].parent = parent; | ||
|
|
||
| // Add accessibility role and live region to timer element. | ||
| if (element) { | ||
| element.setAttribute('role', 'timer'); | ||
| element.setAttribute('aria-live', 'polite'); | ||
| } | ||
|
|
||
| if ( | ||
| window.kadenceCountdown.timers[id].type === 'evergreen' && | ||
|
|
@@ -681,6 +812,51 @@ | |
| ); | ||
| } | ||
|
|
||
| // Always update once to show the initial time (before setting paused state) | ||
| window.kadenceCountdown.updateTimerInterval(element, id, parent); | ||
|
|
||
| // Setup pause button if it exists | ||
| const pauseButton = parent.querySelector('.kb-countdown-pause-button'); | ||
| if (pauseButton) { | ||
| // Remove any existing event listeners by cloning | ||
| const newButton = pauseButton.cloneNode(true); | ||
| pauseButton.parentNode.replaceChild(newButton, pauseButton); | ||
|
|
||
| // If prefers reduced motion, set button to play state initially and pause the timer | ||
| if (window.kadenceCountdown.prefersReducedMotion) { | ||
| window.kadenceCountdown.cache[id].paused = true; | ||
| newButton.setAttribute('aria-pressed', 'true'); | ||
| newButton.setAttribute('aria-label', wp.i18n.__('Resume countdown timer', 'kadence-blocks')); | ||
| newButton.setAttribute('title', wp.i18n.__('Resume countdown', 'kadence-blocks')); | ||
| const icon = newButton.querySelector('.kb-countdown-pause-icon'); | ||
| if (icon) { | ||
| icon.innerHTML = | ||
| '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8 5v14l11-7z" fill="currentColor" /></svg>'; | ||
| } | ||
| newButton.classList.add('kb-countdown-paused'); | ||
| } | ||
|
|
||
| // Add click handler | ||
| newButton.addEventListener('click', (e) => { | ||
| e.preventDefault(); | ||
| window.kadenceCountdown.togglePause(id, newButton); | ||
| }); | ||
|
|
||
| // Keyboard support | ||
| newButton.addEventListener('keydown', (e) => { | ||
| if (e.key === 'Enter' || e.key === ' ') { | ||
| e.preventDefault(); | ||
| window.kadenceCountdown.togglePause(id, newButton); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Check if user prefers reduced motion - if so, don't start countdown interval | ||
| if (window.kadenceCountdown.prefersReducedMotion) { | ||
| // Timer is already displayed and paused, just don't start the interval | ||
| return; | ||
| } | ||
|
|
||
| // For evergreen timers, check viewport and active slide before starting | ||
| if (window.kadenceCountdown.timers[id].type === 'evergreen') { | ||
| // Setup scroll listener | ||
|
|
@@ -716,6 +892,27 @@ | |
| } | ||
| }, | ||
| }; | ||
| // Listen for changes to prefers-reduced-motion | ||
| if (window.matchMedia) { | ||
| const motionQuery = window.matchMedia('(prefers-reduced-motion: reduce)'); | ||
| const handleMotionChange = (e) => { | ||
| const wasReduced = window.kadenceCountdown.prefersReducedMotion; | ||
| window.kadenceCountdown.prefersReducedMotion = e.matches; | ||
|
|
||
| // If preference changed, restart all timers | ||
| if (wasReduced !== e.matches) { | ||
| // Reinitialize all timers | ||
| window.kadenceCountdown.initTimer(); | ||
| } | ||
| }; | ||
|
|
||
| if (motionQuery.addEventListener) { | ||
| motionQuery.addEventListener('change', handleMotionChange); | ||
| } else { | ||
| // Fallback for older browsers | ||
| motionQuery.addListener(handleMotionChange); | ||
| } | ||
| } | ||
| if ('loading' === document.readyState) { | ||
| // The DOM has not yet been loaded. | ||
| document.addEventListener('DOMContentLoaded', window.kadenceCountdown.initTimer); | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gilbert-hernandez can we make this translatable?