Skip to content

Commit

Permalink
[MWPW-165791] Table select aria-label and column cell role added
Browse files Browse the repository at this point in the history
  • Loading branch information
DKos95 committed Jan 20, 2025
1 parent 66f90cb commit 7ca0dd5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libs/blocks/table/table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-plusplus */
import { createTag, MILO_EVENTS } from '../../utils/utils.js';
import { createTag, getConfig, MILO_EVENTS } from '../../utils/utils.js';
import { decorateButtons } from '../../utils/decorate.js';
import { debounce } from '../../utils/action.js';
import { replaceKey } from '../../features/placeholders.js';

const DESKTOP_SIZE = 900;
const MOBILE_SIZE = 768;
Expand Down Expand Up @@ -63,7 +64,7 @@ function handleHeading(table, headingCols) {
});

const headingContent = createTag('div', { class: 'heading-content' });
const headingButton = createTag('div', { class: 'heading-button' });
const headingButton = createTag('div', { class: 'heading-button', role: 'cell' });

[...elements].forEach((e) => {
if (e.classList.contains('pricing') && isPriceBottom) headingButton.appendChild(e);
Expand Down Expand Up @@ -448,6 +449,13 @@ function applyStylesBasedOnScreenSize(table, originTable) {
if ((!isMerch && !table.querySelector('.col-3'))
|| (isMerch && !table.querySelector('.col-2'))) return;

async function setAriaLabelsForElements(first, second) {
const config = getConfig();
const ariaLabel = await replaceKey('choose-table-column', config);
first.setAttribute('aria-label', ariaLabel);
second.setAttribute('aria-label', ariaLabel);

Check warning on line 456 in libs/blocks/table/table.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/table/table.js#L455-L456

Added lines #L455 - L456 were not covered by tests
}

const filterChangeEvent = () => {
table.innerHTML = originTable.innerHTML;
reAssignEvents(table);
Expand Down Expand Up @@ -508,6 +516,7 @@ function applyStylesBasedOnScreenSize(table, originTable) {
table.parentElement.insertBefore(filters, table);
table.parentElement.classList.add(`table-${table.classList.contains('merch') ? 'merch-' : ''}section`);
filterChangeEvent();
setAriaLabelsForElements(colSelect0, colSelect1);
}
};

Expand Down

0 comments on commit 7ca0dd5

Please sign in to comment.