Skip to content

Commit 9e09a31

Browse files
committed
PR feedback
1 parent 23a0211 commit 9e09a31

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Any use of third-party trademarks or logos are subject to those third-party's po
126126
| [emptyswatch-needs-labelling](docs/rules/emptyswatch-needs-labelling.md) | Accessibility: EmptySwatch must have an accessible name via aria-label, Tooltip, aria-labelledby, etc.. | ✅ | | |
127127
| [field-needs-labelling](docs/rules/field-needs-labelling.md) | Accessibility: Field must have label | ✅ | | |
128128
| [image-button-missing-aria](docs/rules/image-button-missing-aria.md) | Accessibility: Image buttons must have accessible labelling: title, aria-label, aria-labelledby, aria-describedby | ✅ | | |
129-
| [image-needs-alt](docs/rules/image-needs-alt.md) | Accessibility: Image must have alt attribute with a meaningful description of the image | ✅ | | |
129+
| [image-needs-alt](docs/rules/image-needs-alt.md) | Accessibility: Image must have alt attribute with a meaningful description of the image. If the image is decorative, use alt="". | ✅ | | |
130130
| [imageswatch-needs-labelling](docs/rules/imageswatch-needs-labelling.md) | Accessibility: ImageSwatch must have an accessible name via aria-label, Tooltip, aria-labelledby, etc.. | ✅ | | |
131131
| [input-components-require-accessible-name](docs/rules/input-components-require-accessible-name.md) | Accessibility: Input fields must have accessible labelling: aria-label, aria-labelledby or an associated label | ✅ | | |
132132
| [link-missing-labelling](docs/rules/link-missing-labelling.md) | Accessibility: Image links must have an accessible name. Add either text content, labelling to the image or labelling to the link itself. | ✅ | | 🔧 |

docs/rules/image-needs-alt.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Accessibility: Image must have alt attribute with a meaningful description of the image (`@microsoft/fluentui-jsx-a11y/image-needs-alt`)
1+
# Accessibility: Image must have alt attribute with a meaningful description of the image. If the image is decorative, use alt="" (`@microsoft/fluentui-jsx-a11y/image-needs-alt`)
22

33
💼 This rule is enabled in the ✅ `recommended` config.
44

55
<!-- end auto-generated rule header -->
66

77
## Rule details
88

9-
This rule requires all `<Image>` components have non-empty alternative text. The `alt` attribute should provide a clear and concise text replacement for the image's content. It should *not* describe the presence of the image itself or the file name of the image.
9+
This rule requires all `<Image>` components have non-empty alternative text. The `alt` attribute should provide a clear and concise text replacement for the image's content. It should *not* describe the presence of the image itself or the file name of the image. Purely decorative images should have empty `alt` text (`alt=""`).
1010

1111

1212
Examples of **incorrect** code for this rule:
@@ -15,10 +15,6 @@ Examples of **incorrect** code for this rule:
1515
<Image src="image.png" />
1616
```
1717

18-
```jsx
19-
<Image src="image.png" alt="" />
20-
```
21-
2218
```jsx
2319
<Image src="image.png" alt={null} />
2420
```
@@ -29,6 +25,10 @@ Examples of **correct** code for this rule:
2925
<Image src="image.png" alt="A dog playing in a park." />
3026
```
3127

28+
```jsx
29+
<Image src="decorative-image.png" alt="" />
30+
```
31+
3232
## Further Reading
3333

3434
- [`<img>` Accessibility](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/img#accessibility)

lib/rules/image-needs-alt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const rule = ESLintUtils.RuleCreator.withoutDocs(
1212
makeLabeledControlRule({
1313
component: "Image",
1414
messageId: "imageNeedsAlt",
15-
description: "Accessibility: Image must have alt attribute with a meaningful description of the image",
15+
description:
16+
'Accessibility: Image must have alt attribute with a meaningful description of the image. If the image is decorative, use alt="".',
1617
requiredProps: ["alt"],
1718
allowFieldParent: false,
1819
allowHtmlFor: false,

lib/rules/swatchpicker-needs-labelling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default ESLintUtils.RuleCreator.withoutDocs(
1313
component: "SwatchPicker",
1414
messageId: "noUnlabeledSwatchPicker",
1515
description: "Accessibility: SwatchPicker must have an accessible name via aria-label, aria-labelledby, Field component, etc..",
16-
requiredNonEmptyProps: ["aria-label"],
16+
labelProps: ["aria-label"],
1717
allowFieldParent: true,
1818
allowHtmlFor: false,
1919
allowLabelledBy: true,

lib/util/ruleFactory.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export type LabeledControlConfig = {
2929
description: string;
3030
/** Properties that are required to have a non-`null` and non-`undefined` value. @example ["alt"] */
3131
requiredProps?: string[];
32-
/** Properties that are required to be defined and not empty. @example ["aria-label", "title", "label"] */
33-
requiredNonEmptyProps?: string[];
32+
/** Labeling properties that are required to have at least one non-empty value. @example ["aria-label", "title", "label"] */
33+
labelProps?: string[];
3434
/** Accept a parent `<Field label="...">` wrapper as providing the label. */
3535
allowFieldParent: boolean;
3636
/** Accept `<label htmlFor="...">` association. */
@@ -83,14 +83,14 @@ export function hasAccessibleLabel(
8383
allowTooltipParent,
8484
allowDescribedBy,
8585
allowLabeledChild,
86-
requiredNonEmptyProps,
87-
requiredProps
86+
requiredProps,
87+
labelProps
8888
} = config;
8989
const allowTextContentChild = !!config.allowTextContentChild;
9090

9191
if (allowFieldParent && hasFieldParent(context)) return true;
92-
if (requiredProps?.some(p => hasDefinedProp(opening.attributes, p))) return true;
93-
if (requiredNonEmptyProps?.some(p => hasNonEmptyProp(opening.attributes, p))) return true;
92+
if (requiredProps?.every(p => hasDefinedProp(node.attributes, p))) return true;
93+
if (labelProps?.some(p => hasNonEmptyProp(node.attributes, p))) return true;
9494
if (allowWrappingLabel && isInsideLabelTag(context)) return true;
9595
if (allowHtmlFor && hasAssociatedLabelViaHtmlFor(opening, context)) return true;
9696
if (allowLabelledBy && hasAssociatedLabelViaAriaLabelledBy(opening, context)) return true;

tests/lib/rules/utils/ruleFactory.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("hasAccessibleLabel (unit)", () => {
107107
const cfg: Required<LabeledControlConfig> = {
108108
component: "RadioGroup",
109109
requiredProps: ["alt"],
110-
requiredNonEmptyProps: ["label", "aria-label"],
110+
labelProps: ["label", "aria-label"],
111111
allowFieldParent: true,
112112
allowHtmlFor: true,
113113
allowLabelledBy: true,
@@ -292,7 +292,7 @@ describe("makeLabeledControlRule (RuleTester integration)", () => {
292292
const baseCfg: Required<LabeledControlConfig> = {
293293
component: "RadioGroup",
294294
requiredProps: ["alt"],
295-
requiredNonEmptyProps: ["label", "aria-label"],
295+
labelProps: ["label", "aria-label"],
296296
allowFieldParent: true,
297297
allowHtmlFor: true,
298298
allowLabelledBy: true,

0 commit comments

Comments
 (0)