Skip to content

Commit

Permalink
Merge pull request #91 from microsoft/shubhakanta-dialog
Browse files Browse the repository at this point in the history
Added rules for dialog
  • Loading branch information
aubreyquinn authored Sep 17, 2024
2 parents 3e9d62c + 784dc9a commit 5728487
Show file tree
Hide file tree
Showing 10 changed files with 534 additions and 29 deletions.
2 changes: 1 addition & 1 deletion COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ We currently cover the following components:
- [x] Checkbox
- [x] Combobox
- [] DataGrid
- [] Dialog
- [x] Dialog
- [N/A] Divider
- [] Drawer
- [X] Dropdown
Expand Down
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,32 @@ Any use of third-party trademarks or logos are subject to those third-party's po
✅ Set in the `recommended` configuration.\
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).

| Name                                  | Description | 💼 | ⚠️ | 🔧 |
| :------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :- | :- | :- |
| [accordion-header-needs-labelling](docs/rules/accordion-header-needs-labelling.md) | The accordion header is a button and it needs an accessibile name e.g. text content, aria-label, aria-labelledby. | ✅ | | |
| [accordion-item-needs-header-and-panel](docs/rules/accordion-item-needs-header-and-panel.md) | An AccordionItem needs exactly one header and one panel | ✅ | | |
| [avatar-needs-name](docs/rules/avatar-needs-name.md) | Accessibility: Avatar must have an accessible labelling: name, aria-label, aria-labelledby | ✅ | | |
| [breadcrumb-needs-labelling](docs/rules/breadcrumb-needs-labelling.md) | All interactive elements must have an accessible name | ✅ | | |
| [checkbox-needs-labelling](docs/rules/checkbox-needs-labelling.md) | Accessibility: Checkbox without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [combobox-needs-labelling](docs/rules/combobox-needs-labelling.md) | All interactive elements must have an accessible name | ✅ | | |
| [compound-button-needs-labelling](docs/rules/compound-button-needs-labelling.md) | Accessibility: Compound buttons must have accessible labelling: title, aria-label, aria-labelledby, aria-describedby | ✅ | | |
| [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 | ✅ | | |
| [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 | ✅ | | |
| [image-link-missing-aria](docs/rules/image-link-missing-aria.md) | Accessibility: Image links must have an accessible name | ✅ | | 🔧 |
| [input-missing-label](docs/rules/input-missing-label.md) | Accessibility: Input fields must have accessible labelling: aria-label, aria-labelledby or an associated label | ✅ | | |
| [menu-item-needs-labelling](docs/rules/menu-item-needs-labelling.md) | Accessibility: MenuItem without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [no-empty-buttons](docs/rules/no-empty-buttons.md) | Accessibility: Button, ToggleButton, SplitButton, MenuButton, CompoundButton must either text content or icon or child component | ✅ | | |
| [no-empty-components](docs/rules/no-empty-components.md) | FluentUI components should not be empty | ✅ | | |
| [prefer-aria-over-title-attribute](docs/rules/prefer-aria-over-title-attribute.md) | The title attribute is not consistently read by screen readers, and its behavior can vary depending on the screen reader and the user's settings. | | ✅ | 🔧 |
| [radio-button-missing-label](docs/rules/radio-button-missing-label.md) | Accessibility: Radio button without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [radiogroup-missing-label](docs/rules/radiogroup-missing-label.md) | Accessibility: RadioGroup without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [spin-button-needs-labelling](docs/rules/spin-button-needs-labelling.md) | Accessibility: SpinButtons must have an accessible label | ✅ | | |
| [spin-button-unrecommended-labelling](docs/rules/spin-button-unrecommended-labelling.md) | Accessibility: Unrecommended accessibility labelling - SpinButton | ✅ | | |
| [switch-needs-labelling](docs/rules/switch-needs-labelling.md) | Accessibility: Switch must have an accessible label | ✅ | | |
| [text-area-missing-label](docs/rules/text-area-missing-label.md) | Accessibility: Textarea must have an accessible name | ✅ | | |
| [toolbar-missing-aria](docs/rules/toolbar-missing-aria.md) | Accessibility: Toolbars need accessible labelling: aria-label or aria-labelledby | ✅ | | |
| [tooltip-not-recommended](docs/rules/tooltip-not-recommended.md) | Accessibility: Prefer text content or aria over a tooltip for these components MenuItem, SpinButton | ✅ | | |
| Name                                       | Description | 💼 | ⚠️ | 🔧 |
| :----------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :- | :- | :- |
| [accordion-header-needs-labelling](docs/rules/accordion-header-needs-labelling.md) | The accordion header is a button and it needs an accessibile name e.g. text content, aria-label, aria-labelledby. | ✅ | | |
| [accordion-item-needs-header-and-panel](docs/rules/accordion-item-needs-header-and-panel.md) | An AccordionItem needs exactly one header and one panel | ✅ | | |
| [avatar-needs-name](docs/rules/avatar-needs-name.md) | Accessibility: Avatar must have an accessible labelling: name, aria-label, aria-labelledby | ✅ | | |
| [breadcrumb-needs-labelling](docs/rules/breadcrumb-needs-labelling.md) | All interactive elements must have an accessible name | ✅ | | |
| [checkbox-needs-labelling](docs/rules/checkbox-needs-labelling.md) | Accessibility: Checkbox without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [combobox-needs-labelling](docs/rules/combobox-needs-labelling.md) | All interactive elements must have an accessible name | ✅ | | |
| [compound-button-needs-labelling](docs/rules/compound-button-needs-labelling.md) | Accessibility: Compound buttons must have accessible labelling: title, aria-label, aria-labelledby, aria-describedby | ✅ | | |
| [dialogbody-needs-title-content-and-actions](docs/rules/dialogbody-needs-title-content-and-actions.md) | A DialogBody should have a header(DialogTitle), content(DialogContent), and footer(DialogActions) | ✅ | | |
| [dialogsurface-needs-aria](docs/rules/dialogsurface-needs-aria.md) | DialogueSurface need accessible labelling: aria-describedby on DialogueSurface and aria-label or aria-labelledby(if DialogueTitle is missing) | ✅ | | |
| [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 | ✅ | | |
| [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 | ✅ | | |
| [image-link-missing-aria](docs/rules/image-link-missing-aria.md) | Accessibility: Image links must have an accessible name | ✅ | | 🔧 |
| [input-missing-label](docs/rules/input-missing-label.md) | Accessibility: Input fields must have accessible labelling: aria-label, aria-labelledby or an associated label | ✅ | | |
| [menu-item-needs-labelling](docs/rules/menu-item-needs-labelling.md) | Accessibility: MenuItem without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [no-empty-buttons](docs/rules/no-empty-buttons.md) | Accessibility: Button, ToggleButton, SplitButton, MenuButton, CompoundButton must either text content or icon or child component | ✅ | | |
| [no-empty-components](docs/rules/no-empty-components.md) | FluentUI components should not be empty | ✅ | | |
| [prefer-aria-over-title-attribute](docs/rules/prefer-aria-over-title-attribute.md) | The title attribute is not consistently read by screen readers, and its behavior can vary depending on the screen reader and the user's settings. | | ✅ | 🔧 |
| [radio-button-missing-label](docs/rules/radio-button-missing-label.md) | Accessibility: Radio button without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [radiogroup-missing-label](docs/rules/radiogroup-missing-label.md) | Accessibility: RadioGroup without label must have an accessible and visual label: aria-labelledby | ✅ | | |
| [spin-button-needs-labelling](docs/rules/spin-button-needs-labelling.md) | Accessibility: SpinButtons must have an accessible label | ✅ | | |
| [spin-button-unrecommended-labelling](docs/rules/spin-button-unrecommended-labelling.md) | Accessibility: Unrecommended accessibility labelling - SpinButton | ✅ | | |
| [switch-needs-labelling](docs/rules/switch-needs-labelling.md) | Accessibility: Switch must have an accessible label | ✅ | | |
| [text-area-missing-label](docs/rules/text-area-missing-label.md) | Accessibility: Textarea must have an accessible name | ✅ | | |
| [toolbar-missing-aria](docs/rules/toolbar-missing-aria.md) | Accessibility: Toolbars need accessible labelling: aria-label or aria-labelledby | ✅ | | |
| [tooltip-not-recommended](docs/rules/tooltip-not-recommended.md) | Accessibility: Prefer text content or aria over a tooltip for these components MenuItem, SpinButton | ✅ | | |

<!-- end auto-generated rules list -->
59 changes: 59 additions & 0 deletions docs/rules/dialogbody-needs-title-content-and-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# A DialogBody should have a header(DialogTitle), content(DialogContent), and footer(DialogActions) (`@microsoft/fluentui-jsx-a11y/dialogbody-needs-title-content-and-actions`)

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

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

Accessibility: A DialogBody should have a header(DialogTitle), content(DialogContent), and footer(DialogActions).

<https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/>

## Ways to fix

- Add DialogTitle, DialogContent and DialogActions inside DialogBody component.

## Rule Details

This rule aims to make Dialogs accessible

Examples of **incorrect** code for this rule:

```jsx
<DialogBody>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
```

```jsx
<DialogBody>
<DialogTitle>Dialog title</DialogTitle>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
```

```jsx
<DialogBody>
<DialogTitle>Dialog title</DialogTitle>
<DialogContent>Test</DialogContent>
</DialogBody>
```

Examples of **correct** code for this rule:

```jsx
<DialogBody>
<DialogTitle>Dialog title</DialogTitle>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
```
102 changes: 102 additions & 0 deletions docs/rules/dialogsurface-needs-aria.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# DialogueSurface need accessible labelling: aria-describedby on DialogueSurface and aria-label or aria-labelledby(if DialogueTitle is missing) (`@microsoft/fluentui-jsx-a11y/dialogsurface-needs-aria`)

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

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

Accessibility: DialogueSurface must have a aria-describedby and aria-label or aria-labelledby(if DialogueTitle is missing).

<https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/>

## Ways to fix

- Add a label with id, add the aria-describedby having same value as id to DialogueSurface.
- Add a label with id, add the aria-labelledby having same value as id to DialogueSurface.
- Add a aria-label to DialogueSurface.
- Add DialogTitle inside DialogueSurface.

## Rule Details

This rule aims to make Dialogs accessible

Examples of **incorrect** code for this rule:

```jsx
<DialogSurface>
<DialogBody>
<DialogTitle>Dialog title</DialogTitle>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
</DialogSurface>
```

```jsx
<>
<Label id="dialoge-test-id">My Label</Label>
<DialogSurface aria-describedby="dialoge-test-id">
<DialogBody>
<DialogTitle></DialogTitle>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
</DialogSurface>
</>
```

Examples of **correct** code for this rule:

```jsx
<>
<span id="dialoge-test-id">My Label</span>
<DialogSurface aria-describedby="dialoge-test-id">
<DialogBody>
<DialogTitle>Dialog title</DialogTitle>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
</DialogSurface>
</>
```

```jsx
<>
<Label id="dialoge-test-id">My Label</Label>
<DialogSurface aria-describedby="dialoge-test-id" aria-label="test-label">
<DialogBody>
<DialogTitle></DialogTitle>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
</DialogSurface>
</>
```

```jsx
<>
<div id="dialoge-test-id-desc">My Label1</div>
<span id="dialoge-test-id-label">My Label2</span>
<DialogSurface aria-describedby="dialoge-test-id-desc" aria-labelledby="dialoge-test-id-label">
<DialogBody>
<DialogTitle></DialogTitle>
<DialogContent>Test</DialogContent>
<DialogActions>
<Button>Close</Button>
<Button>Do Something</Button>
</DialogActions>
</DialogBody>
</DialogSurface>
</>
```
Loading

0 comments on commit 5728487

Please sign in to comment.