-
Notifications
You must be signed in to change notification settings - Fork 375
a11y: announce dialog text in package manager #6593
Changes from 1 commit
afb4ae6
10150f2
610c34b
b96b74f
57add6b
43eb81a
f28ca22
ce9c001
b59370f
2a963f0
54b91fe
ece59ac
4dd97b4
e6d672d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,14 +5,25 @@ | |||
| import { jsx } from '@emotion/core'; | ||||
| import { Dialog, DialogType } from 'office-ui-fabric-react'; | ||||
| import { LoadingSpinner } from '@bfc/ui-shared'; | ||||
| import { useApplicationApi } from '@bfc/extension-client'; | ||||
|
|
||||
| import { modalControlGroup } from './styles'; | ||||
| import { useEffect } from 'react'; | ||||
|
|
||||
| export interface WorkingModalProps { | ||||
| hidden: boolean; | ||||
| title: string; | ||||
| } | ||||
| export const WorkingModal: React.FC<WorkingModalProps> = (props) => { | ||||
| const { announce } = useApplicationApi(); | ||||
|
|
||||
| useEffect(() => { | ||||
| async function doAnnouncement() { | ||||
| announce(props.title); | ||||
| } | ||||
| doAnnouncement(); | ||||
| }, [props.title]); | ||||
|
Comment on lines
+20
to
+22
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this does look strange, but it's the correct way to use an async function inside useEffect.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely seems incorrect though. What's wrong with this? useEffect(() => {
announce(props.title);
}, [props.title]);If you wanted to await something, that would be the way to do it, but just invoking an async function shouldn't require doing this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it shouldn't, but useEffect has a restriction where it doesn't like something that returns a promise. This is a workaround documented in places like https://www.robinwieruch.de/react-hooks-fetch-data and react/react#14326 (where Dan Abramov himself weighs in).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't await a promise within a useEffect block, but you can just call it (like Andy says above) (use callbacks to handle results if required OR use IIFE to await it like: (async () => {
await yourAsyncFunction(args);
})();
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the type definition,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it isn't, but trying to do this the obvious way makes the app crash with the same error that blog post mentions:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a misunderstanding here @beyackle
@hatpick and I are just saying that in this case, the IIFE is unnecessary because we do not need to await the function. |
||||
|
|
||||
| return ( | ||||
| <Dialog | ||||
| dialogContentProps={{ | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.