Skip to content

Commit

Permalink
refactor(eslint-plugin-template): isHiddenFromScreenReader not supp…
Browse files Browse the repository at this point in the history
…orting empty `aria-hidden` property
  • Loading branch information
rafaelss95 committed Apr 7, 2021
1 parent 322e33b commit e36ed3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import type { TmplAstElement } from '@angular/compiler';
import { PROPERTY } from './constants';
import { getLiteralValue } from './get-literal-value';
import { getAttributeValue } from './get-attribute-value';
import { getLiteralValue } from './get-literal-value';

/**
* Returns boolean indicating that the aria-hidden prop
* is present or the value is true. Will also return true if
* there is an input with type='hidden'.
*
* <div aria-hidden /> is equivalent to the DOM as <div aria-hidden=true />.
* Whether an element has the `aria-hidden` property and its value is empty or
* `true`. It also returns `true` if the element is an `input` with `type="hidden"`.
*/
export function isHiddenFromScreenReader(node: any): boolean {
export function isHiddenFromScreenReader(node: TmplAstElement): boolean {
if (node.name.toUpperCase() === 'INPUT') {
const hidden = getAttributeValue(node, 'type');
if (typeof hidden === 'string' && hidden.toUpperCase() === 'HIDDEN') {
const typeAttributeValue = getAttributeValue(node, 'type');
if (
typeof typeAttributeValue === 'string' &&
typeAttributeValue.toUpperCase() === 'HIDDEN'
) {
return true;
}
}

const ariaHidden = getLiteralValue(getAttributeValue(node, 'aria-hidden'));
return ariaHidden === PROPERTY || ariaHidden === true;
return ariaHidden === '' || ariaHidden === PROPERTY || ariaHidden === true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ruleTester.run(RULE_NAME, rule, {
{
// It should work when element has aria-hidden.
code: `
<div (click)="onClick()" aria-hidden"></div>
<div (click)="onClick()" aria-hidden="true"></div>
<div (click)="onClick()" [attr.aria-hidden]="true"></div>
<div (click)="onClick()" [attr.aria-hidden]="ariaHidden"></div>
Expand Down

0 comments on commit e36ed3e

Please sign in to comment.