From 17b9e0cc508df1cef7b56e7351f7be8a3cf786e6 Mon Sep 17 00:00:00 2001 From: Alex Vuong Date: Mon, 28 Oct 2024 15:48:16 -0700 Subject: [PATCH] Fix link list to follow with a11y practise (#2098) * fix link list to follow with a11y practise --- .../template-retail-react-app/CHANGELOG.md | 5 +++ .../app/components/links-list/index.jsx | 44 +++++++++---------- .../app/components/links-list/index.test.js | 9 ++-- .../theme/components/project/links-list.js | 5 +++ 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/packages/template-retail-react-app/CHANGELOG.md b/packages/template-retail-react-app/CHANGELOG.md index d7a2bb043d..9782bd1507 100644 --- a/packages/template-retail-react-app/CHANGELOG.md +++ b/packages/template-retail-react-app/CHANGELOG.md @@ -1,3 +1,8 @@ +## v5.1.0 (TBD) + +### Accessibility Improvements +- [a11y] Fix LinkList component to follow a11y practise [#2098])(https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2098) + ## v5.0.0 (TBD) ### New Features diff --git a/packages/template-retail-react-app/app/components/links-list/index.jsx b/packages/template-retail-react-app/app/components/links-list/index.jsx index fe4f41419d..5fa48891b5 100644 --- a/packages/template-retail-react-app/app/components/links-list/index.jsx +++ b/packages/template-retail-react-app/app/components/links-list/index.jsx @@ -11,7 +11,6 @@ import { List, ListItem, Heading, - HStack, useMultiStyleConfig } from '@salesforce/retail-react-app/app/components/shared/ui' import Link from '@salesforce/retail-react-app/app/components/link' @@ -44,24 +43,24 @@ const LinksList = ({ {heading} ))} - {links && ( - - {variant === 'horizontal' ? ( - - {links.map((link, i) => ( - - - {link.text} - - - ))} - - ) : ( - links.map((link, i) => ( + {links && + (variant === 'horizontal' ? ( + + {links.map((link, i) => ( + + + {link.text} + + + ))} + + ) : ( + + {links.map((link, i) => ( - )) - )} - - )} + ))} + + ))} ) } diff --git a/packages/template-retail-react-app/app/components/links-list/index.test.js b/packages/template-retail-react-app/app/components/links-list/index.test.js index f0cabe69cd..06104c50f9 100644 --- a/packages/template-retail-react-app/app/components/links-list/index.test.js +++ b/packages/template-retail-react-app/app/components/links-list/index.test.js @@ -21,7 +21,7 @@ const links = [ text: 'Privacy Policy' } ] -const horizontalVariantSelector = 'ul > .chakra-stack > li' +const horizontalVariantSelector = 'ul > li' const FooterStylesProvider = ({children}) => { const styles = useMultiStyleConfig('Footer') @@ -41,7 +41,7 @@ test('renders LinksList with default arguments', () => { expect(screen.getAllByRole('listitem')).toHaveLength(1) expect(screen.getByRole('link', {name: links[0].text})).toBeInTheDocument() expect(screen.queryByRole('heading')).toBeNull() - expect(document.querySelector(horizontalVariantSelector)).toBeNull() + expect(screen.queryByTestId('horizontal-list')).toBeNull() }) test('renders LinksList with heading', () => { @@ -55,11 +55,12 @@ test('renders LinksList with heading', () => { }) test('renders LinksList with horizontal variant', () => { - renderWithProviders( + const {container} = renderWithProviders( ) + screen.logTestingPlaygroundURL() - expect(document.querySelector(horizontalVariantSelector)).toBeInTheDocument() + expect(container.querySelector(horizontalVariantSelector)).toBeInTheDocument() }) diff --git a/packages/template-retail-react-app/app/theme/components/project/links-list.js b/packages/template-retail-react-app/app/theme/components/project/links-list.js index 2bec61b52b..c7a6ad8dde 100644 --- a/packages/template-retail-react-app/app/theme/components/project/links-list.js +++ b/packages/template-retail-react-app/app/theme/components/project/links-list.js @@ -25,6 +25,11 @@ export default { variants: { vertical: {}, horizontal: { + list: { + display: 'flex', + flexDirection: 'row', + gap: '0.5rem' + }, listItem: { borderLeft: '1px solid', paddingLeft: 2