From 8c0f44b09cbc84e3c5512dbe7474d52ee5733826 Mon Sep 17 00:00:00 2001 From: Will Howat-Comandre Date: Tue, 11 Jun 2024 15:38:00 +0200 Subject: [PATCH 1/6] Fix: Conversion center - Contact button - accessibility for expandable state --- .../js/frontend/handlers/contact-buttons.js | 37 ++++++++++++++++++- .../render/contact-buttons-render-base.php | 2 +- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/modules/conversion-center/assets/js/frontend/handlers/contact-buttons.js b/modules/conversion-center/assets/js/frontend/handlers/contact-buttons.js index a5de4a9755eb..3161c87b6e94 100644 --- a/modules/conversion-center/assets/js/frontend/handlers/contact-buttons.js +++ b/modules/conversion-center/assets/js/frontend/handlers/contact-buttons.js @@ -192,10 +192,11 @@ export default class ContactButtonsHandler extends Base { if ( this.elements.contentWrapper ) { this.elements.contentWrapper.classList.remove( hidden ); + this.elements.contentWrapper.setAttribute( 'aria-hidden', 'false' ); } if ( this.elements.chatButton ) { - this.elements.chatButton.setAttribute( 'aria-expanded', 'false' ); + this.elements.chatButton.setAttribute( 'aria-expanded', 'true' ); } if ( this.elements.closeButton ) { @@ -214,10 +215,11 @@ export default class ContactButtonsHandler extends Base { if ( this.elements.contentWrapper ) { this.elements.contentWrapper.classList.add( hidden ); + this.elements.contentWrapper.setAttribute( 'aria-hidden', 'true' ); } if ( this.elements.chatButton ) { - this.elements.chatButton.setAttribute( 'aria-expanded', 'true' ); + this.elements.chatButton.setAttribute( 'aria-expanded', 'false' ); } if ( this.elements.closeButton ) { @@ -274,6 +276,37 @@ export default class ContactButtonsHandler extends Base { } initDefaultState() { + // Manage a11ly + const { hidden } = this.getSettings( 'constants' ); + const randomishId = String( + Date.now().toString( 32 ) + + Math.random().toString( 16 ), + ).replace( /\./g, '' ); + + const wrapperID = this.elements.contentWrapper.id + ? this.elements.contentWrapper.id + : `e-contact-buttons__content-wrapper-${ randomishId }`; + + const isHidden = this.elements.contentWrapper + ? this.elements.contentWrapper.classList.contains( hidden ) + : false; + + if ( this.elements.contentWrapper ) { + this.elements.contentWrapper.setAttribute( 'id', wrapperID ); + this.elements.contentWrapper.setAttribute( 'aria-hidden', isHidden ); + } + + if ( this.elements.chatButton ) { + this.elements.chatButton.setAttribute( 'aria-expanded', ! isHidden ); + this.elements.chatButton.setAttribute( 'aria-controls', wrapperID ); + } + + if ( this.elements.closeButton ) { + this.elements.closeButton.setAttribute( 'aria-expanded', ! isHidden ); + this.elements.closeButton.setAttribute( 'aria-controls', wrapperID ); + } + + // Default to open in Editor if ( elementorFrontend.isEditMode() ) { this.openChatBox(); } diff --git a/modules/conversion-center/classes/render/contact-buttons-render-base.php b/modules/conversion-center/classes/render/contact-buttons-render-base.php index 61da4712a212..63a2a1f2b641 100644 --- a/modules/conversion-center/classes/render/contact-buttons-render-base.php +++ b/modules/conversion-center/classes/render/contact-buttons-render-base.php @@ -83,7 +83,7 @@ protected function render_chat_button(): void { ?>
-