Skip to content

Commit 0a417d0

Browse files
committed
feat: review
1 parent ada51ce commit 0a417d0

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

src/js/accessibility/product.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ export default () => {
5656
const focusMap = new Map<'quickview' | 'main', { id: string }>();
5757

5858
// Save the element before the update
59-
prestashop.on(events.updateProduct, ({ event }: { event: Event }) => {
59+
prestashop.on(events.updateProduct, ({event}: { event: Event }) => {
6060
const target = event?.target as HTMLElement;
61+
6162
if (!target || !target.id) return;
6263

6364
const isInQuickView = !!target.closest(SelectorsMap.quickviewModal);
6465
const context: 'quickview' | 'main' = isInQuickView ? 'quickview' : 'main';
6566

66-
focusMap.set(context, { id: target.id });
67+
focusMap.set(context, {id: target.id});
6768
});
6869

6970
// Restore focus after update
@@ -76,9 +77,9 @@ export default () => {
7677
} else {
7778
container = document.querySelector(SelectorsMap.product.container);
7879
}
79-
80+
8081
if (!container) return;
81-
82+
8283
const elementToFocus = container.querySelector<HTMLElement>(`#${focusData.id}`);
8384

8485
if (elementToFocus) {
@@ -87,7 +88,7 @@ export default () => {
8788
// Emit event to when the focus is restored
8889
prestashop.emit(events.combinationFocusRestored, {
8990
context,
90-
elementId: focusData.id
91+
elementId: focusData.id,
9192
});
9293
}
9394

@@ -96,7 +97,7 @@ export default () => {
9697
});
9798

9899
// Product availability messages announcement
99-
prestashop.on(events.combinationFocusRestored, ({ context }: { context: 'quickview' | 'main' }) => {
100+
prestashop.on(events.combinationFocusRestored, ({context}: { context: 'quickview' | 'main' }) => {
100101
let container: HTMLElement | null = null;
101102

102103
// Get the container of the context

templates/catalog/_partials/product-variants.tpl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
<div class="product__variants js-product-variants">
77
{foreach from=$groups key=id_attribute_group item=group}
88
{if !empty($group.attributes)}
9+
{assign var=groupId value="group_{$id_attribute_group}_{$product.id}"}
10+
{assign var=inputId value="input_{$id_attribute_group}_{$product.id}"}
11+
{assign var=legendId value="legend_{$id_attribute_group}_{$product.id}"}
12+
913
<fieldset class="product-variant">
1014
<div class="product-variant__label">
11-
<legend class="form-label product-variant__legend" id="legend_{$product.id}_{$id_attribute_group}">{$group.name}</legend>
15+
<legend class="form-label product-variant__legend" id="{$legendId}">{$group.name}</legend>
1216
<span class="selected-value product-variant__selected" aria-hidden="true">
1317
{l s=': ' d='Shop.Theme.Catalog'}
1418
{foreach from=$group.attributes key=id_attribute item=group_attribute}
@@ -20,24 +24,25 @@
2024
{if $group.group_type == 'select'}
2125
<select
2226
class="form-select"
23-
id="group_{$product.id}_{$id_attribute_group}"
24-
aria-labelledby="legend_{$product.id}_{$id_attribute_group}"
27+
id="{$inputId}"
28+
aria-labelledby="{$legendId}"
2529
data-product-attribute="{$id_attribute_group}"
2630
name="group[{$id_attribute_group}]">
2731
{foreach from=$group.attributes key=id_attribute item=group_attribute}
2832
<option value="{$id_attribute}" {if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
2933
{/foreach}
3034
</select>
3135
{elseif $group.group_type == 'color'}
32-
<div id="group_{$product.id}_{$id_attribute_group}" class="product-variant__colors" role="radiogroup" aria-labelledby="legend_{$product.id}_{$id_attribute_group}">
36+
<div id="{$groupId}" class="product-variant__colors" role="radiogroup" aria-labelledby="{$legendId}">
3337
{foreach from=$group.attributes key=id_attribute item=group_attribute}
34-
{assign var=optionId value="group_{$product.id}_{$id_attribute_group}_{$id_attribute}"}
35-
{assign var=labelId value="label_{$product.id}_{$id_attribute_group}_{$id_attribute}"}
38+
{assign var=inputId value="input_{$id_attribute_group}_{$id_attribute}_{$product.id}"}
39+
{assign var=labelId value="label_{$id_attribute_group}_{$id_attribute}_{$product.id}"}
40+
3641
<div class="product-variant__color input-color">
3742
<input
3843
class="input-color__input"
3944
type="radio"
40-
id="{$optionId}"
45+
id="{$inputId}"
4146
data-product-attribute="{$id_attribute_group}"
4247
name="group[{$id_attribute_group}]"
4348
value="{$id_attribute}"
@@ -46,7 +51,7 @@
4651
>
4752
<label
4853
class="input-color__label{if $group_attribute.texture} input-color__label--texture{/if}{if $group_attribute.selected} input-color__label--active{/if}"
49-
for="{$optionId}"
54+
for="{$inputId}"
5055
>
5156
<span id="{$labelId}"
5257
{if $group_attribute.texture}
@@ -62,22 +67,23 @@
6267
{/foreach}
6368
</div>
6469
{elseif $group.group_type == 'radio'}
65-
<div id="group_{$product.id}_{$id_attribute_group}" class="product-variant__radios" role="radiogroup" aria-labelledby="legend_{$product.id}_{$id_attribute_group}">
70+
<div id="{$groupId}" class="product-variant__radios" role="radiogroup" aria-labelledby="{$legendId}">
6671
{foreach from=$group.attributes key=id_attribute item=group_attribute}
67-
{assign var=optionId value="group_{$product.id}_{$id_attribute_group}_{$id_attribute}"}
68-
{assign var=labelId value="label_{$product.id}_{$id_attribute_group}_{$id_attribute}"}
72+
{assign var=inputId value="input_{$id_attribute_group}_{$id_attribute}_{$product.id}"}
73+
{assign var=labelId value="label_{$id_attribute_group}_{$id_attribute}_{$product.id}"}
74+
6975
<div class="product-variant__radio form-check">
7076
<input
7177
class="form-check-input"
7278
type="radio"
73-
id="{$optionId}"
79+
id="{$inputId}"
7480
data-product-attribute="{$id_attribute_group}"
7581
name="group[{$id_attribute_group}]"
7682
value="{$id_attribute}"
7783
aria-labelledby="{$labelId}"
7884
{if $group_attribute.selected} checked="checked" aria-checked="true"{/if}
7985
>
80-
<label for="{$optionId}">
86+
<label for="{$inputId}">
8187
<span class="form-check-label" id="{$labelId}"><span class="visually-hidden">{$group.group_name} - </span>{$group_attribute.name}</span>
8288
</label>
8389
</div>

0 commit comments

Comments
 (0)