Skip to content

Commit

Permalink
fix(react-dialog): aria-* properties should be reassignable (#25092)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsunderhus authored Oct 6, 2022
1 parent 2484ba1 commit b48083b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "fix: aria-* properties should be reassignable",
"packageName": "@fluentui/react-dialog",
"email": "bernardo.sunderhus@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export const useDialogSurface_unstable = (
root: getNativeElementProps(as ?? 'div', {
'aria-modal': modalType !== 'non-modal',
role: modalType === 'alert' ? 'alertdialog' : 'dialog',
'aria-describedby': dialogContentId,
'aria-labelledby': props['aria-label'] ? undefined : dialogTitleID,
...props,
...modalAttributes,
onKeyDown: handleKeyDown,
'aria-describedby': dialogContentId,
'aria-labelledby': props['aria-label'] ? undefined : dialogTitleID,
ref: useMergedRefs(ref, dialogRef),
}),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { useModalAttributes } from '@fluentui/react-tabster';
import { applyTriggerPropsToChildren, getTriggerChild, useEventCallback } from '@fluentui/react-utilities';
import { DialogTriggerProps, DialogTriggerState } from './DialogTrigger.types';
import type { DialogTriggerProps, DialogTriggerState } from './DialogTrigger.types';
import { useDialogContext_unstable, useDialogSurfaceContext_unstable } from '../../contexts';
import { useARIAButtonProps } from '@fluentui/react-aria';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
- Dialog boxes consist of a header (`DialogTitle`), content (`DialogContent`), and footer (`DialogActions`), which should all be included inside a body (`DialogBody`).
- Validate that people’s entries are acceptable before closing the dialog. Show an inline validation error near the field they must correct.
- Modal dialogs should be used very sparingly—only when it’s critical that people make a choice or provide information before they can proceed. Thee dialogs are generally used for irreversible or potentially destructive tasks. They’re typically paired with an backdrop without a light dismiss.
- `DialogSurface` by default has `aria-describedby="dialog-content-id"`, which might not be ideal with complex `DialogContent`, on those scenarios, it is recommended to set `aria-describedby={null}`
- `DialogSurface` by default has `aria-describedby="dialog-content-id"`, which might not be ideal with complex `DialogContent`, on those scenarios (for example on [with form](#with-form)), it is recommended to set `aria-describedby={undefined}`

### Don't

- Don't use more than three buttons between `DialogActions`.
- Don't open a Dialog from a Dialog
- Don't use a Dialog with no focusable elements
- Don't open a `Dialog` from a `Dialog`
- Don't use a `Dialog` with no focusable elements

</details>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Having a formulary inside the `Dialog` its quite simple, you simply add a `<form>` element between `DialogSurface` and `DialogBody` to ensure all the content between them are properly wrapped inside the formulary. This allows a button inside `DialogActions` to be properly used as submission button.

Keep in mind that controlling the `open` state of the `Dialog` might be ideal in this scenario, since validation and submission are possibly synchronous activities. For example, closing the `Dialog` only after the submission is successful would require control of the `open` state, to properly set `open` to `false` only once the submission has succeeded.
> Keep in mind that controlling the `open` state of the `Dialog` might be ideal in this scenario, since validation and submission are possibly synchronous activities. For example, closing the `Dialog` only after the submission is successful would require control of the `open` state, to properly set `open` to `false` only once the submission has succeeded.
> ⚠️ Don't forget to set `aria-describedby={undefined}` for `DialogSurface` to ensure the formulary is not automatically narrated by screen readers.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const WithForm = () => {
<DialogTrigger>
<Button>Open formulary dialog</Button>
</DialogTrigger>
<DialogSurface>
<DialogSurface aria-describedby={undefined}>
<form onSubmit={handleSubmit}>
<DialogBody>
<DialogTitle>Dialog title</DialogTitle>
Expand Down

0 comments on commit b48083b

Please sign in to comment.