Skip to content

Commit 17b9e0c

Browse files
authored
Fix link list to follow with a11y practise (#2098)
* fix link list to follow with a11y practise
1 parent 7fff71d commit 17b9e0c

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

packages/template-retail-react-app/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v5.1.0 (TBD)
2+
3+
### Accessibility Improvements
4+
- [a11y] Fix LinkList component to follow a11y practise [#2098])(https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2098)
5+
16
## v5.0.0 (TBD)
27

38
### New Features

packages/template-retail-react-app/app/components/links-list/index.jsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
List,
1212
ListItem,
1313
Heading,
14-
HStack,
1514
useMultiStyleConfig
1615
} from '@salesforce/retail-react-app/app/components/shared/ui'
1716
import Link from '@salesforce/retail-react-app/app/components/link'
@@ -44,24 +43,24 @@ const LinksList = ({
4443
<Heading {...styles.heading}>{heading}</Heading>
4544
))}
4645

47-
{links && (
48-
<List spacing={5} {...styles.list}>
49-
{variant === 'horizontal' ? (
50-
<HStack>
51-
{links.map((link, i) => (
52-
<ListItem key={i} {...styles.listItem} sx={styles.listItemSx}>
53-
<Link
54-
to={link.href}
55-
onClick={onLinkClick}
56-
{...(link.styles ? link.styles : {})}
57-
>
58-
{link.text}
59-
</Link>
60-
</ListItem>
61-
))}
62-
</HStack>
63-
) : (
64-
links.map((link, i) => (
46+
{links &&
47+
(variant === 'horizontal' ? (
48+
<List {...styles.list} data-testid="horizontal-list">
49+
{links.map((link, i) => (
50+
<ListItem key={i} {...styles.listItem} sx={styles.listItemSx}>
51+
<Link
52+
to={link.href}
53+
onClick={onLinkClick}
54+
{...(link.styles ? link.styles : {})}
55+
>
56+
{link.text}
57+
</Link>
58+
</ListItem>
59+
))}
60+
</List>
61+
) : (
62+
<List spacing={5} {...styles.list}>
63+
{links.map((link, i) => (
6564
<ListItem key={i}>
6665
<Link
6766
to={link.href}
@@ -71,10 +70,9 @@ const LinksList = ({
7170
{link.text}
7271
</Link>
7372
</ListItem>
74-
))
75-
)}
76-
</List>
77-
)}
73+
))}
74+
</List>
75+
))}
7876
</Box>
7977
)
8078
}

packages/template-retail-react-app/app/components/links-list/index.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const links = [
2121
text: 'Privacy Policy'
2222
}
2323
]
24-
const horizontalVariantSelector = 'ul > .chakra-stack > li'
24+
const horizontalVariantSelector = 'ul > li'
2525

2626
const FooterStylesProvider = ({children}) => {
2727
const styles = useMultiStyleConfig('Footer')
@@ -41,7 +41,7 @@ test('renders LinksList with default arguments', () => {
4141
expect(screen.getAllByRole('listitem')).toHaveLength(1)
4242
expect(screen.getByRole('link', {name: links[0].text})).toBeInTheDocument()
4343
expect(screen.queryByRole('heading')).toBeNull()
44-
expect(document.querySelector(horizontalVariantSelector)).toBeNull()
44+
expect(screen.queryByTestId('horizontal-list')).toBeNull()
4545
})
4646

4747
test('renders LinksList with heading', () => {
@@ -55,11 +55,12 @@ test('renders LinksList with heading', () => {
5555
})
5656

5757
test('renders LinksList with horizontal variant', () => {
58-
renderWithProviders(
58+
const {container} = renderWithProviders(
5959
<FooterStylesProvider>
6060
<LinksList links={links} variant="horizontal" />
6161
</FooterStylesProvider>
6262
)
63+
screen.logTestingPlaygroundURL()
6364

64-
expect(document.querySelector(horizontalVariantSelector)).toBeInTheDocument()
65+
expect(container.querySelector(horizontalVariantSelector)).toBeInTheDocument()
6566
})

packages/template-retail-react-app/app/theme/components/project/links-list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export default {
2525
variants: {
2626
vertical: {},
2727
horizontal: {
28+
list: {
29+
display: 'flex',
30+
flexDirection: 'row',
31+
gap: '0.5rem'
32+
},
2833
listItem: {
2934
borderLeft: '1px solid',
3035
paddingLeft: 2

0 commit comments

Comments
 (0)