Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-slide-panel] Disclosing node capturing method update #2095

Merged
merged 11 commits into from
Mar 26, 2024

Conversation

adoroshk
Copy link
Contributor

@adoroshk adoroshk commented Mar 20, 2024

This PR changes slide panel disclosing node capturing method that allows to use slide panel without mainContent prop.

Summary

In order to return the focus to the disclosing node upon closing the Slide panel, the disclosing node needs to be captured upon panel opening. The existing implementation requires a mainContent prop to be passed, which would allow the Slide panel to create a main content node with onClick and onKeyUp event listeners being in charge of capturing disclosing node. With that approach in cases when mainContent prop is omitted, the disclosing node is not captured upon panel opening and there is no node saved to return focus upon panel closing.

What was changed:

  1. The disclosing node capturing was moved from onClick and onKeyUp event listeners attached to the main content, to componentDidUpdate method. The document.activeElement is captured and saved as a panel disclosing node before Slide panel grabs focus on isOpen prop changing to true.
  2. Setting aria-expanded attribute to the disclosing node has been updated to accommodate for the node role. As setting aria-expanded attribute to true with unsupported roles would cause accessibility violations, a method to check whether the role is supported has been added. More info on roles associated with aria-expanded attribute.
  3. The main content node is rendered only if mainContent prop was passed.
  4. A test example and wdio tests for slide panel with no main content prop were added to terra-framework-docs.
  5. WDIO screenshots for terra-agregator test which uses slide panel were updated, as with new functionality added, the disclosing nodes in terra-agregator received the focus.

Testing

This change was tested using:

  • WDIO
  • Jest
  • Visual testing (please attach a screenshot or recording)
  • Other (please describe below)
  • No tests are needed

Reviews

In addition to engineering reviews, this PR needs:

  • UX review
  • Accessibility review
  • Functional review

Additional Details

This PR resolves:

UXPLATFORM-10319

@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 22, 2024 17:08 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 22, 2024 18:49 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 25, 2024 13:50 Destroyed
@adoroshk adoroshk changed the title [terra-slide-panel] POC disclosing node capture update [terra-slide-panel] Disclosing node capturing method update Mar 25, 2024
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 25, 2024 14:14 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 25, 2024 14:29 Destroyed
Copy link
Contributor

@kenk2 kenk2 left a comment

Choose a reason for hiding this comment

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

Just 1 question, otherwise LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this right? This seems like it would result in an accessibility violation because there's not enough contrast.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the highlighted style was updated? May need UX to confirm if this is the correct styling.

Copy link
Contributor Author

@adoroshk adoroshk Mar 25, 2024

Choose a reason for hiding this comment

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

WDIO screenshots for terra-agregator test example which uses slide panel were updated, as with new functionality added, the disclosing node in terra-agregator received the focus. However, the focus style itself hasn't changed, it just wasn't receiving focus before as Slide Panel had no means to return the focus to that node. The affected example is a test example for some other functionality, it is not presented on the doc page and is not relevant to anything important. I don't think we should fix it or log a bug.

* @param {HTMLElement} node - a node to check
* @returns true if node's role is compatible with aria-expanded attribute
*/
const roleIsCompartible = (node) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does compartible mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It checks if node's role is one compatible (sorry for typo, will fix if we won't remove it at the end) with aria-expanded attribute. Here is the documentation for roles associated with aria-expanded attribute.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it is just a typo :). I still don't think we need a method like this though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

this.disclosingNode.setAttribute('aria-expanded', 'false');
if (this.disclosingNode.getAttribute('aria-expanded')) {
// Set aria-expanded attribute to false for nodes that had that attribute only
this.disclosingNode.setAttribute('aria-expanded', 'false');
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not clear on why we need to set the aria-expanded attribute on the disclosing node. That element is not being expanded.

Copy link
Contributor Author

@adoroshk adoroshk Mar 25, 2024

Choose a reason for hiding this comment

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

aria-expanded attribute was not added in this change, it was added before. I'll check with @mjpalazzo if it can be removed.

Comment on lines 94 to 112
const roleIsCompartible = (node) => {
const role = node.getAttribute('role');
return (
role === 'application'
|| role === 'button'
|| role === 'checkbox'
|| role === 'combobox'
|| role === 'gridcell'
|| role === 'link'
|| role === 'listbox'
|| role === 'menuitem'
|| role === 'row'
|| role === 'rowheader'
|| role === 'tab'
|| role === 'treeitem'
|| role === null
|| role === undefined
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not need a method like this. It makes me feel like we might be doing something incorrectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, the role in question changed in the example

Comment on lines 97 to 111
role === 'application'
|| role === 'button'
|| role === 'checkbox'
|| role === 'combobox'
|| role === 'gridcell'
|| role === 'link'
|| role === 'listbox'
|| role === 'menuitem'
|| role === 'row'
|| role === 'rowheader'
|| role === 'tab'
|| role === 'treeitem'
|| role === null
|| role === undefined
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a lot of conditions that will always be sequentially checked. Can we optimize it using a Set and the Set.has method?

Copy link
Contributor

Choose a reason for hiding this comment

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

And I'm confused why are we testing for all the possible values if we don't care that role is null/undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sdadn aria-expanded attribute should be used only with specific roles, otherwise it causes accessibility violation. This attribute was not introduced in this change, but it was causing accessibility violations with specific roles only, so I added a check. I'll double check with @mjpalazzo what would be the best way to address that

Comment on lines 159 to 162
if (roleIsCompartible(node)) {
// Set aria-expanded attribute to true for nodes with associated roles or no role only
node.setAttribute('aria-expanded', 'true');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This node is not being expanded. I don't think we should be adding this role.

Copy link
Contributor Author

@adoroshk adoroshk Mar 25, 2024

Choose a reason for hiding this comment

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

aria-expanded attribute wasn't added by me, it was there before the change, I just added a role check, as it can be added only with specific roles, otherwise it causes accessibility violation. I'll double check with @mjpalazzo if aria-expanded attribute needs to be removed.

@adoroshk
Copy link
Contributor Author

@mjpalazzo, it looks like we need your help.

  1. Slide panel has aria-expanded prop added to the side panel disclosing element (a button that user clicked to open the panel). That was added 11 month ago and my understanding is it was added as a part of accessibility update. As I received engineers questions whether it needs to be removed, please clarify if that should stay.
  2. Per the documentation the aria-expanded attribute can be added only with associated roles, so I added a check it disclosing node's role is compatible with aria-expanded attribute or there is no role at all. Please let me know if that is a correct way to address the issue, or needs to be changed.
    cc: @cm9361, @sdadn

@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 26, 2024 17:10 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 26, 2024 19:15 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 26, 2024 19:40 Destroyed
@adoroshk
Copy link
Contributor Author

  1. The check for the role was removed.
  2. I met with @mjpalazzo, demonstrated existing workflow and discussed a possibility of adding aria-controls attribute. It has been decided to keep existing functionality without aria-controls attribute for now.

@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 26, 2024 21:33 Destroyed
@github-actions github-actions bot temporarily deployed to preview-pr-2095 March 26, 2024 21:46 Destroyed
@adoroshk adoroshk merged commit 9035f5e into main Mar 26, 2024
22 checks passed
@adoroshk adoroshk deleted the slide-panel-return-focus-to-disclosing-node-update branch March 26, 2024 22:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants