-
Notifications
You must be signed in to change notification settings - Fork 8
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
Improve aria-hidden warning rule to cover some valid use cases for adding it to elements #523
Conversation
Elements with screen reader test Elements with visible text Elements flagged as presentational
This feature was not implemented in this PR since simple_html_dom doesn't have any concept of visibility
…o avoid false passes
There was a problem hiding this 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)
…further aria-hidden pass conditions checked
…e than one sibling
There was a problem hiding this 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.
includes/rules/aria_hidden.php
Outdated
} | ||
|
||
$parent_node = $element->parent(); | ||
if ( $parent_node && ( strtolower( $parent_node->tag ) === 'button' || strtolower( $parent_node->tag ) === 'a' ) ) { |
There was a problem hiding this comment.
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'
)
) {
There was a problem hiding this comment.
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 )
) {
There was a problem hiding this comment.
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'
)
) {
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge.
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.
Closes: #448