From 4cf49dcf47fd2654387dbc95931dff7e07062a63 Mon Sep 17 00:00:00 2001
From: Paritosh Maurya <47924620+mauryapari@users.noreply.github.com>
Date: Thu, 18 Jul 2024 00:32:09 +0530
Subject: [PATCH] feat: add rules for prohibiting use of aria-hidden and
role='presentation' on focusable elements. (#1169)
* Added rule for prohibiting use of aria-hidden and role=presentaion on focusable elements
* Refactored code into seprate files and utility file
* Added EOL for files with prettier errors
* Removed nested ifs
* Fixed EOL errors
* Added more lines
* Fixed prettier issues
* Removed commented code
---
docs/rules/no-aria-hidden-on-focusable.md | 79 +++++++++++++++++++
.../no-role-presentation-on-focusable.md | 79 +++++++++++++++++++
.../no-aria-hidden-on-focusable.test.ts | 31 ++++++++
.../no-role-presentation-on-focusable.test.ts | 31 ++++++++
src/rules/no-aria-hidden-on-focusable.ts | 37 +++++++++
.../no-role-presentation-on-focusable.ts | 38 +++++++++
src/utils.ts | 1 +
src/utils/hasFocusableElement.ts | 21 +++++
8 files changed, 317 insertions(+)
create mode 100644 docs/rules/no-aria-hidden-on-focusable.md
create mode 100644 docs/rules/no-role-presentation-on-focusable.md
create mode 100644 src/rules/__tests__/no-aria-hidden-on-focusable.test.ts
create mode 100644 src/rules/__tests__/no-role-presentation-on-focusable.test.ts
create mode 100644 src/rules/no-aria-hidden-on-focusable.ts
create mode 100644 src/rules/no-role-presentation-on-focusable.ts
create mode 100644 src/utils/hasFocusableElement.ts
diff --git a/docs/rules/no-aria-hidden-on-focusable.md b/docs/rules/no-aria-hidden-on-focusable.md
new file mode 100644
index 00000000..bf2701a3
--- /dev/null
+++ b/docs/rules/no-aria-hidden-on-focusable.md
@@ -0,0 +1,79 @@
+# no-aria-hidden-on-focusbable
+
+Enforce that `aria-hidden="true"` is not set on focusable elements or parent of focusable elements.
+
+`aria-hidden="true"` can be used to hide purely decorative content from screen reader users. An element with `aria-hidden="true"` that can also be reached by keyboard can lead to confusion or unexpected behavior for screen reader users. Avoid using `aria-hidden="true"` on focusable elements.
+
+See more in [WAI-ARIA Use in HTML](https://www.w3.org/TR/using-aria/#fourth).
+
+### ✔ Succeed
+
+```vue
+
+
+
+```
+
+```vue
+
+
+
+```
+
+```vue
+
+
+
+```
+
+```vue
+
+ Icon
+
+```
diff --git a/docs/rules/no-role-presentation-on-focusable.md b/docs/rules/no-role-presentation-on-focusable.md
new file mode 100644
index 00000000..2d5f0f3b
--- /dev/null
+++ b/docs/rules/no-role-presentation-on-focusable.md
@@ -0,0 +1,79 @@
+# no-role-presentaion-on-focusbable
+
+Enforce that `role="presentation"` is not set on focusable elements or parent of focusbale elements.
+
+`role="presentation` can be used to hide purely decorative content from screen reader users. An element with `role="presentation"` that can also be reached by keyboard can lead to confusion or unexpected behavior for screen reader users. Avoid using `role="presentation"` on focusable elements.
+
+See more in [WAI-ARIA Use in HTML](https://www.w3.org/TR/using-aria/#fourth).
+
+### ✔ Succeed
+
+```vue
+
+
+
+```
+
+```vue
+
+
+
+```
+
+```vue
+
+