From d286e176ada91d938703fde40579ec08b2e79468 Mon Sep 17 00:00:00 2001 From: Aubrey Quinn Date: Mon, 16 Sep 2024 15:59:38 +0100 Subject: [PATCH 1/5] started implementation for new rule, added helper function --- ...-aria-describedby-for-primary-labelling.md | 40 +++++++++++++++++++ .../buttonBasedComponents.js | 8 ++++ .../inputBasedComponents.js | 8 ++++ lib/rules/image-button-missing-aria.js | 7 +--- lib/rules/input-missing-label.js | 2 +- lib/util/labelUtils.js | 21 +++++++++- 6 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 docs/rules/avoid-using-aria-describedby-for-primary-labelling.md create mode 100644 lib/applicableComponents/buttonBasedComponents.js create mode 100644 lib/applicableComponents/inputBasedComponents.js diff --git a/docs/rules/avoid-using-aria-describedby-for-primary-labelling.md b/docs/rules/avoid-using-aria-describedby-for-primary-labelling.md new file mode 100644 index 0000000..2ad7be6 --- /dev/null +++ b/docs/rules/avoid-using-aria-describedby-for-primary-labelling.md @@ -0,0 +1,40 @@ +# aria-describedby provides additional context and is not meant for primary labeling. (`avoid-using-aria-describedby-for-primary-labelling`) + +You should avoid using `aria-describedby` as a primary labeling mechanism because it is intended to provide supplementary or additional information, not to act as the main label for an element. + +**Purpose:** `aria-describedby` is designed to describe an element in more detail beyond the primary label, such as offering extended help text, usage instructions, or explanations. It’s meant to be used alongside a label, not to replace it. + +**Accessibility and User Experience:** Some screen readers may not announce content associated with `aria-describedby`, or users might disable this feature for various reasons, such as reducing verbosity or simplifying their experience. This makes relying on `aria-describedby` as the primary labeling mechanism risky because it can lead to critical information being missed by users who need it. Screen readers treat `aria-describedby` differently than `aria-labelledby`. The `aria-labelledby` attribute is explicitly used for primary labeling, and it ensures that the name of an element is read in the expected order and with the right emphasis. On the other hand, `aria-describedby` provides additional context that may be read after the main label, so it may confuse users if used as the primary label. + +## Rule Details + +Examples of **incorrect** code for this rule: + +```jsx +

Click to submit your form. This will save your data.

', + '<>

This field is for your full legal name.

' + ], + invalid: [ + { + code: '<>

Click to submit your form. This will save your data.

', - '<>

This field is for your full legal name.

' + '<>', + '<>' ], invalid: [ { - code: '<>