Skip to content

Commit

Permalink
Help Center: Enhance back button accessibility (#97974)
Browse files Browse the repository at this point in the history
* Enhance BackButton accessibility: add keyboard support and improve ARIA attributes

* Refactor BackButton component: replace span with Button for improved accessibility and keyboard support

* Refactor BackButton component: add label prop for accessibility and remove unnecessary aria-label

* Remove unnecessary span wrapper and add onTouchStart for improved touch support

* update locator for back button in HelpCenterComponent

* Fix e2e

* Fix e2e

---------

Co-authored-by: heavyweight <kpapazov@gmail.com>
  • Loading branch information
agrullon95 and heavyweight authored Jan 8, 2025
1 parent fbc42bb commit 43c47f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/calypso-e2e/src/lib/components/help-center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class HelpCenterComponent {
* Go back to the previous page.
*/
async goBack(): Promise< void > {
await this.popup.locator( 'span.back-button__help-center' ).click();
await this.popup.getByTestId( 'help-center-back-button' ).click();
}

/**
Expand Down
20 changes: 12 additions & 8 deletions packages/help-center/src/components/back-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Button } from '@wordpress/components';
import { Icon, chevronLeft } from '@wordpress/icons';
import { useI18n } from '@wordpress/react-i18n';
import { useNavigate, useSearchParams, useLocation } from 'react-router-dom';

import './back-button.scss';
Expand All @@ -7,6 +9,7 @@ export const BackButton = () => {
const navigate = useNavigate();
const [ searchParams ] = useSearchParams();
const { pathname } = useLocation();
const { __ } = useI18n();

function handleClick() {
if ( pathname === '/success' ) {
Expand All @@ -19,13 +22,14 @@ export const BackButton = () => {
}

return (
<span className="back-button__help-center">
<Icon
data-testid="back-button-icon"
onClick={ handleClick }
icon={ chevronLeft }
size={ 18 }
/>
</span>
<Button
label={ __( 'Go Back', __i18n_text_domain__ ) }
data-testid="help-center-back-button"
onClick={ handleClick }
onTouchStart={ handleClick }
className="back-button__help-center"
>
<Icon icon={ chevronLeft } size={ 18 } />
</Button>
);
};
4 changes: 2 additions & 2 deletions packages/help-center/src/components/test/back-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe( 'BackButton', () => {
</MemoryRouter>
);

await user.click( screen.getByTestId( 'back-button-icon' ) );
await user.click( screen.getByTestId( 'help-center-back-button' ) );

expect( mockNavigate ).toHaveBeenCalledWith( -1 );
} );
Expand All @@ -45,7 +45,7 @@ describe( 'BackButton', () => {
</MemoryRouter>
);

await user.click( screen.getByTestId( 'back-button-icon' ) );
await user.click( screen.getByTestId( 'help-center-back-button' ) );

expect( mockNavigate ).not.toHaveBeenCalledWith( '/' );
} );
Expand Down

0 comments on commit 43c47f2

Please sign in to comment.