Skip to content

Commit 936c38c

Browse files
committed
PR feedback
1 parent 701e0a5 commit 936c38c

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Any use of third-party trademarks or logos are subject to those third-party's po
124124
| [dropdown-needs-labelling](docs/rules/dropdown-needs-labelling.md) | Accessibility: Dropdown menu must have an id and it needs to be linked via htmlFor of a Label | ✅ | | |
125125
| [field-needs-labelling](docs/rules/field-needs-labelling.md) | Accessibility: Field must have label | ✅ | | |
126126
| [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 | ✅ | | |
127-
| [image-needs-alt](docs/rules/image-needs-alt.md) | Accessibility: Image must have alt attribute with a meaningful description of the image | ✅ | | |
127+
| [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="". | ✅ | | |
128128
| [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 | ✅ | | |
129129
| [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. | ✅ | | 🔧 |
130130
| [menu-item-needs-labelling](docs/rules/menu-item-needs-labelling.md) | Accessibility: MenuItem without label must have an accessible and visual label: aria-labelledby | ✅ | | |

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export type LabeledControlConfig = {
2828
description: string;
2929
/** Properties that are required to have a non-`null` and non-`undefined` value. @example ["alt"] */
3030
requiredProps?: string[];
31-
/** Properties that are required to be defined and not empty. @example ["aria-label", "title", "label"] */
32-
requiredNonEmptyProps?: string[];
31+
/** Labeling properties that are required to have at least one non-empty value. @example ["aria-label", "title", "label"] */
32+
labelProps?: string[];
3333
/** Accept a parent `<Field label="...">` wrapper as providing the label. */
3434
allowFieldParent: boolean;
3535
/** Accept `<label htmlFor="...">` association. */
@@ -76,12 +76,12 @@ export function hasAccessibleLabel(node: TSESTree.JSXOpeningElement, context: an
7676
allowDescribedBy,
7777
allowLabeledChild,
7878
requiredProps,
79-
requiredNonEmptyProps
79+
labelProps
8080
} = config;
8181

8282
if (allowFieldParent && hasFieldParent(context)) return true;
83-
if (requiredProps?.some(p => hasDefinedProp(node.attributes, p))) return true;
84-
if (requiredNonEmptyProps?.some(p => hasNonEmptyProp(node.attributes, p))) return true;
83+
if (requiredProps?.every(p => hasDefinedProp(node.attributes, p))) return true;
84+
if (labelProps?.some(p => hasNonEmptyProp(node.attributes, p))) return true;
8585
if (allowWrappingLabel && isInsideLabelTag(context)) return true;
8686
if (allowHtmlFor && hasAssociatedLabelViaHtmlFor(node, context)) return true;
8787
if (allowLabelledBy && hasAssociatedLabelViaAriaLabelledBy(node, context)) return true;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("hasAccessibleLabel (unit)", () => {
8080
const cfg: Required<LabeledControlConfig> = {
8181
component: "RadioGroup",
8282
requiredProps: ["alt"],
83-
requiredNonEmptyProps: ["label", "aria-label"],
83+
labelProps: ["label", "aria-label"],
8484
allowFieldParent: true,
8585
allowHtmlFor: true,
8686
allowLabelledBy: true,
@@ -202,7 +202,7 @@ describe("makeLabeledControlRule (RuleTester integration)", () => {
202202
const baseCfg: Required<LabeledControlConfig> = {
203203
component: "RadioGroup",
204204
requiredProps: ["alt"],
205-
requiredNonEmptyProps: ["label", "aria-label"],
205+
labelProps: ["label", "aria-label"],
206206
allowFieldParent: true,
207207
allowHtmlFor: true,
208208
allowLabelledBy: true,

0 commit comments

Comments
 (0)