Skip to content
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

@W-12627180@ Improve keyboard accessibility of product scroller #1559

Merged
merged 14 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/template-retail-react-app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix improper nesting of elements in product tile [#1541](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1541)
- Ensure all interactive functionality is operable with the keyboard [#1546](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1546)
- Make security code tooltip receive keyboard focus [#1551](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1551)
- Improve keyboard accessibility of product scroller [#1559](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1559)

### Other Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@salesforce/retail-react-app/app/components/shared/ui'
import ProductTile from '@salesforce/retail-react-app/app/components/product-tile'
import {ChevronLeftIcon, ChevronRightIcon} from '@salesforce/retail-react-app/app/components/icons'
import {useIntl} from 'react-intl'

/**
* Renders a scrollable, horizontal container of products with native scroll
Expand All @@ -35,6 +36,7 @@ const ProductScroller = forwardRef(
},
ref
) => {
const intl = useIntl()
const scrollRef = useRef()

// Renders nothing if we aren't loading and have no products.
Expand Down Expand Up @@ -72,6 +74,7 @@ const ProductScroller = forwardRef(
wrap="nowrap"
overflowX="scroll"
px={{base: 4, md: 8, lg: 0}}
py={1}
{...scrollProps}
sx={{
scrollPadding: {base: 16, md: 32, lg: 0},
Expand All @@ -80,43 +83,52 @@ const ProductScroller = forwardRef(
...scrollProps?.sx
}}
>
{(isLoading ? [0, 1, 2, 4] : products).map((product, idx) => {
return (
<Box
key={product?.id || idx}
flex="0 0 auto"
width={itemWidth}
style={{scrollSnapAlign: 'start'}}
>
{isLoading ? (
<Stack data-testid="product-scroller-item-skeleton">
<AspectRatio ratio={1}>
<Skeleton />
</AspectRatio>
<Stack spacing={2}>
<Skeleton width="150px" height={5} />
<Skeleton width="75px" height={5} />
</Stack>
</Stack>
) : (
<ProductTile
data-testid="product-scroller-item"
product={product}
{...(typeof productTileProps === 'function'
? {...productTileProps(product)}
: {...productTileProps})}
dynamicImageProps={{
widths: ['70vw', '70vw', '40vw', '30vw']
}}
/>
)}
</Box>
)
})}
{isLoading
? [0, 1, 2, 3].map((key) => {
return (
<Box
key={key}
flex="0 0 auto"
width={itemWidth}
style={{scrollSnapAlign: 'start'}}
>
<Stack data-testid="product-scroller-item-skeleton">
<AspectRatio ratio={1}>
<Skeleton />
</AspectRatio>
<Stack spacing={2}>
<Skeleton width="150px" height={5} />
<Skeleton width="75px" height={5} />
</Stack>
</Stack>
</Box>
)
})
: products.map((product, idx) => {
return (
<Box
key={product?.id || idx}
flex="0 0 auto"
width={itemWidth}
style={{scrollSnapAlign: 'start'}}
>
<ProductTile
data-testid="product-scroller-item"
product={product}
{...(typeof productTileProps === 'function'
? {...productTileProps(product)}
: {...productTileProps})}
dynamicImageProps={{
widths: ['70vw', '70vw', '40vw', '30vw']
}}
/>
</Box>
)
})}
</Stack>
</Stack>

{products?.length > 3 && (
{!isLoading && products?.length > 3 && (
<>
<Box
display={{
Expand All @@ -130,7 +142,10 @@ const ProductScroller = forwardRef(
>
<IconButton
data-testid="product-scroller-nav-left"
aria-label="Scroll products left"
aria-label={intl.formatMessage({
id: 'product_scroller.assistive_msg.scroll_left',
defaultMessage: 'Scroll products left'
})}
icon={<ChevronLeftIcon color="black" />}
borderRadius="full"
colorScheme="whiteAlpha"
Expand All @@ -150,7 +165,10 @@ const ProductScroller = forwardRef(
>
<IconButton
data-testid="product-scroller-nav-right"
aria-label="Scroll products right"
aria-label={intl.formatMessage({
id: 'product_scroller.assistive_msg.scroll_right',
defaultMessage: 'Scroll products right'
})}
icon={<ChevronRightIcon color="black" />}
borderRadius="full"
colorScheme="whiteAlpha"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,23 @@ const ProductTile = (props) => {
}}
>
<IconButtonWithRegistration
aria-label={intl.formatMessage({
id: 'product_tile.assistive_msg.wishlist',
defaultMessage: 'Wishlist'
})}
aria-label={
isFavourite
? intl.formatMessage(
{
id: 'product_tile.assistive_msg.add_to_wishlist',
defaultMessage: 'Add {product} to wishlist'
},
{product: localizedProductName}
)
: intl.formatMessage(
{
id: 'product_tile.assistive_msg.remove_from wishlist',
defaultMessage: 'Remove {product} from wishlist'
},
{product: localizedProductName}
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the messages should be reversed: if it's favourite, then clicking the icon means removing the product from wishlist.

icon={isFavourite ? <HeartSolidIcon /> : <HeartIcon />}
{...styles.favIcon}
disabled={isFavouriteLoading}
Expand Down Expand Up @@ -190,7 +203,7 @@ ProductTile.propTypes = {
*/
enableFavourite: PropTypes.bool,
/**
* Display the product as a faviourite.
* Display the product as a favourite.
*/
isFavourite: PropTypes.bool,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2301,10 +2301,44 @@
"value": "sortOption"
}
],
"product_tile.assistive_msg.wishlist": [
"product_scroller.assistive_msg.scroll_left": [
{
"type": 0,
"value": "Wishlist"
"value": "Scroll products left"
}
],
"product_scroller.assistive_msg.scroll_right": [
{
"type": 0,
"value": "Scroll products right"
}
],
"product_tile.assistive_msg.add_to_wishlist": [
{
"type": 0,
"value": "Add "
},
{
"type": 1,
"value": "product"
},
{
"type": 0,
"value": " to wishlist"
}
],
"product_tile.assistive_msg.remove_from wishlist": [
{
"type": 0,
"value": "Remove "
},
{
"type": 1,
"value": "product"
},
{
"type": 0,
"value": " from wishlist"
}
],
"product_tile.label.starting_at_price": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2301,10 +2301,44 @@
"value": "sortOption"
}
],
"product_tile.assistive_msg.wishlist": [
"product_scroller.assistive_msg.scroll_left": [
{
"type": 0,
"value": "Wishlist"
"value": "Scroll products left"
}
],
"product_scroller.assistive_msg.scroll_right": [
{
"type": 0,
"value": "Scroll products right"
}
],
"product_tile.assistive_msg.add_to_wishlist": [
{
"type": 0,
"value": "Add "
},
{
"type": 1,
"value": "product"
},
{
"type": 0,
"value": " to wishlist"
}
],
"product_tile.assistive_msg.remove_from wishlist": [
{
"type": 0,
"value": "Remove "
},
{
"type": 1,
"value": "product"
},
{
"type": 0,
"value": " from wishlist"
}
],
"product_tile.label.starting_at_price": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4925,14 +4925,72 @@
"value": "]"
}
],
"product_tile.assistive_msg.wishlist": [
"product_scroller.assistive_msg.scroll_left": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Ẇīşħŀīşŧ"
"value": "Şƈřǿǿŀŀ ƥřǿǿḓŭŭƈŧş ŀḗḗƒŧ"
},
{
"type": 0,
"value": "]"
}
],
"product_scroller.assistive_msg.scroll_right": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Şƈřǿǿŀŀ ƥřǿǿḓŭŭƈŧş řīɠħŧ"
},
{
"type": 0,
"value": "]"
}
],
"product_tile.assistive_msg.add_to_wishlist": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Ȧḓḓ "
},
{
"type": 1,
"value": "product"
},
{
"type": 0,
"value": " ŧǿǿ ẇīşħŀīşŧ"
},
{
"type": 0,
"value": "]"
}
],
"product_tile.assistive_msg.remove_from wishlist": [
{
"type": 0,
"value": "["
},
{
"type": 0,
"value": "Řḗḗḿǿǿṽḗḗ "
},
{
"type": 1,
"value": "product"
},
{
"type": 0,
"value": " ƒřǿǿḿ ẇīşħŀīşŧ"
},
{
"type": 0,
Expand Down
13 changes: 11 additions & 2 deletions packages/template-retail-react-app/translations/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,17 @@
"product_list.select.sort_by": {
"defaultMessage": "Sort By: {sortOption}"
},
"product_tile.assistive_msg.wishlist": {
"defaultMessage": "Wishlist"
"product_scroller.assistive_msg.scroll_left": {
"defaultMessage": "Scroll products left"
},
"product_scroller.assistive_msg.scroll_right": {
"defaultMessage": "Scroll products right"
},
"product_tile.assistive_msg.add_to_wishlist": {
"defaultMessage": "Add {product} to wishlist"
},
"product_tile.assistive_msg.remove_from wishlist": {
"defaultMessage": "Remove {product} from wishlist"
},
"product_tile.label.starting_at_price": {
"defaultMessage": "Starting at {price}"
Expand Down
13 changes: 11 additions & 2 deletions packages/template-retail-react-app/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,17 @@
"product_list.select.sort_by": {
"defaultMessage": "Sort By: {sortOption}"
},
"product_tile.assistive_msg.wishlist": {
"defaultMessage": "Wishlist"
"product_scroller.assistive_msg.scroll_left": {
"defaultMessage": "Scroll products left"
},
"product_scroller.assistive_msg.scroll_right": {
"defaultMessage": "Scroll products right"
},
"product_tile.assistive_msg.add_to_wishlist": {
"defaultMessage": "Add {product} to wishlist"
},
"product_tile.assistive_msg.remove_from wishlist": {
"defaultMessage": "Remove {product} from wishlist"
},
"product_tile.label.starting_at_price": {
"defaultMessage": "Starting at {price}"
Expand Down