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

Improve aria-hidden warning rule to cover some valid use cases for adding it to elements #523

Merged
merged 18 commits into from
Mar 18, 2024

Conversation

pattonwebz
Copy link
Member

@pattonwebz pattonwebz commented Mar 7, 2024

Right now, the aria-hidden rule flags a warning for every instance that it detects and tasks users with looking at each one and its context to determine whether it is valid. If they find it valid, they are instructed to ignore the issue.

This PR seeks to add some smarts to the checker so that it can try not to flag some instances as warnings when we can tell they are valid already.

It was pretty easy to detect items with labels on the parent, but screen reader text and visible text are a little more challenging and are still being worked through.

  • Unit tests have been added to try to cover all the new functionality

Closes: #448

@pattonwebz pattonwebz marked this pull request as ready for review March 12, 2024 17:40
Copy link
Member

@SteveJonesDev SteveJonesDev left a comment

Choose a reason for hiding this comment

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

See comment on issue: #448 (comment)

Copy link
Member

@SteveJonesDev SteveJonesDev left a comment

Choose a reason for hiding this comment

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

The inner text change works nicely. Just a couple readability changes and this should be good to merge.

}

$parent_node = $element->parent();
if ( $parent_node && ( strtolower( $parent_node->tag ) === 'button' || strtolower( $parent_node->tag ) === 'a' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Improve readability

			if ( 
				$parent_node && 
				( 
					strtolower( $parent_node->tag ) === 'button' || 
					strtolower( $parent_node->tag ) === 'a' 
				) 
			) {

Copy link
Member Author

@pattonwebz pattonwebz Mar 15, 2024

Choose a reason for hiding this comment

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

Seeing it laid out like this makes me think that I should reduce the number of lines in the condition. What do you think of this alternative?

			$parent_node             = $element->parent();
			$tags_for_further_checks = array(
				'button',
				'a',
			);
			if (
				$parent_node &&
				in_array( strtolower($parent_node->tag), $tags_for_further_checks, true )
			) {

Copy link
Member

@SteveJonesDev SteveJonesDev Mar 18, 2024

Choose a reason for hiding this comment

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

I'd rather it be a direct comparison than taking on the additional overhead of the in_array since the array isn't likely to change. It's a marginal performance improvement but it can add up throughout the code base. I was tempted to ask you to make the $attributes_that_make_this_valid_hidden_use a direct comparison as well but I think that one is okay for now.

I know code readability is subjective but I find this more readable anyways.

			if ( 
				$parent_node && 
				( 
					strtolower( $parent_node->tag ) === 'button' || 
					strtolower( $parent_node->tag ) === 'a' 
				) 
			) {

Copy link
Member Author

Choose a reason for hiding this comment

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

@SteveJonesDev gotcha, I updated this to align with your suggestion now. LMK if there was any other feedback.

includes/rules/aria_hidden.php Outdated Show resolved Hide resolved
Copy link
Member

@SteveJonesDev SteveJonesDev left a comment

Choose a reason for hiding this comment

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

Good to merge.

@pattonwebz pattonwebz merged commit bacfd53 into develop Mar 18, 2024
16 checks passed
@SteveJonesDev SteveJonesDev added this to the v1.10.0 milestone Mar 18, 2024
@pattonwebz pattonwebz deleted the william/448/improve-aria-hidden-warning-checks branch March 28, 2024 18:26
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.

Make aria-hidden warning smarter
2 participants