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

[MWPW-165791] Table select aria-label and column cell role added #3513

Open
wants to merge 9 commits into
base: stage
Choose a base branch
from

Conversation

DKos95
Copy link
Contributor

@DKos95 DKos95 commented Jan 20, 2025

This resolves the issues where a table row was missing an adequate role and select on mobile was missing a label causing accessibility issues.

Resolves: MWPW-165791

Before After
Screenshot 2025-01-20 at 12 33 12 Screenshot 2025-01-20 at 12 33 18

Test URLs:

Copy link
Contributor

aem-code-sync bot commented Jan 20, 2025

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

Copy link
Contributor

aem-code-sync bot commented Jan 20, 2025

Copy link

codecov bot commented Jan 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.47%. Comparing base (66f90cb) to head (3d358d3).
Report is 15 commits behind head on stage.

Additional details and impacted files
@@           Coverage Diff            @@
##            stage    #3513    +/-   ##
========================================
  Coverage   96.46%   96.47%            
========================================
  Files         259      260     +1     
  Lines       60217    60601   +384     
========================================
+ Hits        58090    58465   +375     
- Misses       2127     2136     +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DKos95 DKos95 force-pushed the table-select-cell branch from d562bf0 to 7ca0dd5 Compare January 20, 2025 12:05
@aem-code-sync aem-code-sync bot temporarily deployed to table-select-cell January 20, 2025 12:05 Inactive
@aem-code-sync aem-code-sync bot temporarily deployed to table-select-cell January 20, 2025 15:50 Inactive
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to future-proof this a bit, in case we'll have another number of columns visible on different breakpoints. So let's send these in an Array and have a single argument for setAriaLabelsForElements that iterates over the array's elements to set the aria-label.

Comment on lines 9 to 10
config.env = { locale: { contentRoot: `${window.location.origin}` } };
setConfig(config);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this end up actually making the placeholders call during the unit tests? We generally avoid network requests, so this should be mocked. I suspect the palceholders tests should have a way of doing this already.

it('should apply aria-label to all selects within .filters on mobile', async () => {
window.innerWidth = 375;
window.dispatchEvent(new Event('resize'));
await delay(500);
Copy link
Contributor

Choose a reason for hiding this comment

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

We try to avoid any wait time in our unit tests as to not delay the whole suite. You can look up await clock.runAllAsync(); in the codebase and that should provide a hint on how to wait for things to happen without impact on run time.

await delay(500);
const selectElements = document.querySelectorAll('.filters select');
selectElements.forEach((selectElement) => {
expect(selectElement.getAttribute('aria-label')).to.equal('choose table column');
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, we should probably mock the placeholders logic/values, so we might need to adapt the expected value here as well.

@aem-code-sync aem-code-sync bot temporarily deployed to table-select-cell January 21, 2025 13:15 Inactive
"value": "choose table column"
}
]
}
Copy link
Contributor

@mokimo mokimo Jan 22, 2025

Choose a reason for hiding this comment

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

Nit: Missing end of file

@aem-code-sync aem-code-sync bot temporarily deployed to table-select-cell January 22, 2025 12:19 Inactive
@@ -153,6 +153,15 @@ function handleAddOnContent(table) {
table.addEventListener('mas:resolved', debounce(() => { handleEqualHeight(table, '.row-heading'); }));
}

async function setAriaLabelsForExpandableIcons() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a unit test for this as well?

async function setAriaLabelsForExpandableIcons() {
const config = getConfig();
const ariaLabel = await replaceKey('toggle-row', config);
const icons = document.querySelectorAll('.icon.expand[role="button"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

Although I agree that all expand icons should get the aria-label attribute, I'm not sure this is the place to do it. I'd either apply the behavior in a more general icon file or scope these changes to just the table we're decorating.

Comment on lines 460 to 467
async function setAriaLabelsForElements(selectArray) {
const config = getConfig();
const ariaLabel = await replaceKey('choose-table-column', config);

selectArray.forEach((item) => {
item.setAttribute('aria-label', ariaLabel);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic and the one from setAriaLabelsForExpandableIcons, are quite similar, I'd suggest we combine them into a more general method that we can call. Another tip: there is a replaceKeyArray with which you could get all the placeholders in one go, if that's helpful for the generic method.

Comment on lines +9 to +12
const locales = { '': { ietf: 'en-US', tk: 'hah7vzn.css' } };
const conf = { locales, contentRoot: '/test/blocks/table/mocks' };
setConfig(conf);
const config = getConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem to be relevant to a single test, should we scope them to that particular test? I'm not sure how we treat this in other unit tests, might be worth a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to not be possible since in table.test.js we are initializing table.js and the calls for aria label get executed immediately and not just for that test.

@aem-code-sync aem-code-sync bot temporarily deployed to table-select-cell January 24, 2025 13:00 Inactive
@aem-code-sync aem-code-sync bot temporarily deployed to table-select-cell January 24, 2025 13:01 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants