From 4b6b0f688cd9d17ceb84ea6878f8f5fa2d3275fc Mon Sep 17 00:00:00 2001 From: Aubrey Quinn Date: Thu, 18 Sep 2025 10:03:33 +0100 Subject: [PATCH 1/4] added rules for all swatch components --- COVERAGE.md | 8 +- docs/rules/colorswatch-needs-labelling.md | 110 +++++++++++++ docs/rules/emptyswatch-needs-labelling.md | 109 +++++++++++++ docs/rules/imageswatch-needs-labelling.md | 108 +++++++++++++ lib/index.ts | 6 + lib/rules/colorswatch-needs-labelling.ts | 26 +++ lib/rules/emptyswatch-needs-labelling.ts | 26 +++ lib/rules/imageswatch-needs-labelling.ts | 26 +++ lib/rules/index.ts | 3 + lib/util/ruleFactory.ts | 96 +++++++++-- .../rules/colorswatch-needs-labelling.test.ts | 78 +++++++++ .../rules/emptyswatch-needs-labelling.test.ts | 100 ++++++++++++ .../rules/imageswatch-needs-labelling.test.ts | 108 +++++++++++++ tests/lib/rules/utils/ruleFactory.test.ts | 151 +++++++++++++++--- 14 files changed, 911 insertions(+), 44 deletions(-) create mode 100644 docs/rules/colorswatch-needs-labelling.md create mode 100644 docs/rules/emptyswatch-needs-labelling.md create mode 100644 docs/rules/imageswatch-needs-labelling.md create mode 100644 lib/rules/colorswatch-needs-labelling.ts create mode 100644 lib/rules/emptyswatch-needs-labelling.ts create mode 100644 lib/rules/imageswatch-needs-labelling.ts create mode 100644 tests/lib/rules/colorswatch-needs-labelling.test.ts create mode 100644 tests/lib/rules/emptyswatch-needs-labelling.test.ts create mode 100644 tests/lib/rules/imageswatch-needs-labelling.test.ts diff --git a/COVERAGE.md b/COVERAGE.md index d65a83b..872b914 100644 --- a/COVERAGE.md +++ b/COVERAGE.md @@ -64,10 +64,10 @@ We currently cover the following components: - [x] SpinButton - [x] Spinner - [x] SwatchPicker - - [] ColorSwatch - - [] ImageSwatch - - [] EmptySwatch - - [] SwatchPickerRow + - [x] ColorSwatch + - [x] ImageSwatch + - [x] EmptySwatch + - [N/A] SwatchPickerRow - [x] Switch - [] SearchBox - [] Table diff --git a/docs/rules/colorswatch-needs-labelling.md b/docs/rules/colorswatch-needs-labelling.md new file mode 100644 index 0000000..d076f50 --- /dev/null +++ b/docs/rules/colorswatch-needs-labelling.md @@ -0,0 +1,110 @@ +# Accessibility: ColorSwatch must have an accessible name (`@microsoft/fluentui-jsx-a11y/colorswatch-needs-labelling`) + +πŸ’Ό This rule is enabled in the βœ… `recommended` config. + + + +All interactive elements must have an accessible name. + +`ColorSwatch` without a supported label lacks an accessible name for assistive technology users. + +## Allowed labelling strategies + +- βœ… `aria-label` **on `ColorSwatch`** +- βœ… `aria-labelledby` **on `ColorSwatch`** +- βœ… `htmlFor`/`id` +- βœ… Wrapping native `` +- βœ… `Tooltip` parent with `relationship="label"` +- βœ… `Field` parent label +- βœ… Text content child +- ❌ Container-only label (e.g., only the surrounding `SwatchPicker` is labelled) + +## Ways to fix + +- Add `aria-label` / `aria-labelledby`. +- Use `