forked from Workday/canvas-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Improve the "accessible" example of loading dots (Workday#2673)
The Soap400 color for the `LoadingDots` component does not meet WCAG guidelines for non-text contrast while used on light background colors. For this example, I used a darker background color that allows Soap400 to meet the minimum 3:1 contrast ratio. I also added better screen reader support with the `AriaLiveRegion` component that both lets users know about the loading status, and when loading has completed. [category:Documentation] Release Note: Accessible `LoadingDots` example has been updated, by changing background to a darker color that allows `soap400` to meet the minimum 3:1 contrast ratio and adding better screen reader support with the `AriaLiveRegion` component. Co-authored-by: @RayRedGoose <[email protected]> Co-authored-by: @NicholasBoll <[email protected]>
- Loading branch information
1 parent
6bedb8b
commit c987a34
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,44 @@ | ||
import React from 'react'; | ||
import {LoadingDots} from '@workday/canvas-kit-react/loading-dots'; | ||
import {base, system} from '@workday/canvas-tokens-web'; | ||
import {Flex} from '@workday/canvas-kit-react/layout'; | ||
import {SecondaryButton} from '@workday/canvas-kit-react/button'; | ||
import {createStyles, cssVar} from '@workday/canvas-kit-styling'; | ||
import {AccessibleHide, AriaLiveRegion} from '@workday/canvas-kit-react/common'; | ||
|
||
const loadingStyles = createStyles({ | ||
backgroundColor: base.licorice300, | ||
padding: system.space.x3, | ||
}); | ||
|
||
export const Accessible = () => { | ||
return <LoadingDots aria-live="polite" aria-label="Loading Users" />; | ||
const [loadingState, setLoadingState] = React.useState('idle'); | ||
|
||
React.useEffect(() => { | ||
const timer = setTimeout(() => { | ||
if (loadingState === 'loading') { | ||
setLoadingState('success'); | ||
} | ||
}, 4000); | ||
|
||
return () => { | ||
clearTimeout(timer); | ||
}; | ||
}, [loadingState]); | ||
|
||
const handleLoad = () => { | ||
setLoadingState('loading'); | ||
}; | ||
|
||
return ( | ||
<Flex gap={cssVar(system.space.x4)}> | ||
<SecondaryButton onClick={handleLoad}>Start</SecondaryButton> | ||
<AriaLiveRegion aria-label="Loading"> | ||
{loadingState === 'loading' && ( | ||
<LoadingDots className={loadingStyles} role="img" aria-label="Please wait..." /> | ||
)} | ||
{loadingState === 'success' && <AccessibleHide>Complete.</AccessibleHide>} | ||
</AriaLiveRegion> | ||
</Flex> | ||
); | ||
}; |