-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(eslint-plugin-template):
isHiddenFromScreenReader
not supp…
…orting empty `aria-hidden` property
- Loading branch information
1 parent
322e33b
commit e36ed3e
Showing
2 changed files
with
12 additions
and
10 deletions.
There are no files selected for viewing
21 changes: 11 additions & 10 deletions
21
packages/eslint-plugin-template/src/utils/is-hidden-from-screen-reader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters