@workday/canvas-kit-docs 11.0.0-alpha.766-next.0 → 11.0.0-alpha.769-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ any questions.
26
26
  - [Count Badge](#count-badge)
27
27
  - [Form Field Preview](#form-field-preview)
28
28
  - [Icons](#icons)
29
+ - [Loading Dots](#loading-dots)
29
30
  - [Radio (Preview)](#radio-preview)
30
31
  - [Select](#select)
31
32
  - [Switch](#switch)
@@ -680,6 +681,15 @@ const MyComponent = StyledRadioButton('div')({
680
681
  </MyComponent>;
681
682
  ```
682
683
 
684
+ ### Loading Dots
685
+
686
+ `LoadingDots` now uses
687
+ [Canvas Tokens](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) and
688
+ our
689
+ [new styling utilities](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-modifiers#createstyles-api).
690
+ The component now supports the `cs` prop, but otherwise the API has not changed. It should behave
691
+ identically as it did in previous versions.
692
+
683
693
  ### Radio (Preview)
684
694
 
685
695
  **PR:** [#2546](https://github.com/Workday/canvas-kit/pull/2546)
@@ -0,0 +1,75 @@
1
+ import {AriaLiveRegion} from '@workday/canvas-kit-react/common';
2
+ import FilterListWithLiveStatus from './examples/common/FilterListWithLiveStatus';
3
+ import VisibleLiveRegion from './examples/common/VisibleLiveRegion';
4
+ import HiddenLiveRegion from './examples/common/HiddenLiveRegion';
5
+ import TextInputWithLiveError from './examples/common/TextInputWithLiveError';
6
+ import IconButtonsWithLiveBadges from './examples/common/IconButtonsWithLiveBadges';
7
+
8
+
9
+ # ARIA Live Regions
10
+
11
+ These examples are provided to demonstrate a variety of different use cases for the `AriaLiveRegion`
12
+ component. For the full experience, get started by first turning on your favorite screen reading
13
+ software. On Windows, we recommend the open source
14
+ [NVDA (Non-Visual Desktop Access)](https://www.nvaccess.org/download/) software, or
15
+ [JAWS (Job Access With Speech)](https://support.freedomscientific.com/Downloads/JAWS) if you have
16
+ purchased a license. MacOS and iOS include VoiceOver, which can be turned on in your settings.
17
+
18
+ Live regions work by designating specific DOM nodes for screen readers to monitor for any content
19
+ updates inside the node. When an update occurs, screen readers will announce the update to users in
20
+ real time, based on a few rules:
21
+
22
+ 1. `polite` will “politely” wait for users to finish what they are doing before announcing an update
23
+ 2. `assertive` will interrupt what users are doing (or reading) by immediately announcing an update
24
+
25
+ ### CAUTION: Don't get carried away
26
+
27
+ Key things to understand about live regions:
28
+
29
+ 1. A live region update will only be announced once. Users are unable to repeat them or re-examine
30
+ them if the announcement was not understood.
31
+ 2. Users may be able to pause a live region announcement, but they cannot prevent a live region
32
+ announcement from occurring. Sending frequent, repetitive, or simply too much information to a
33
+ live region can be very disruptive to users.
34
+ 3. Users cannot act on, or navigate to, a live region. Live regions must only contain plain text.
35
+ (No images, links, buttons, or other input.)
36
+ 4. Support for live regions is limited across platforms, browsers, and screen reader software. Real
37
+ time announcements may not be perfectly reliable.
38
+
39
+ ## Visible Live Regions
40
+
41
+ Live regions can be applied to dynamic text on the UI. When the dynamic text is updated, screen
42
+ readers can describe the text update in live time as it occurs. In the example below, type text into
43
+ the input field and activate the "Send Message" button. Listen and observe the screen reader
44
+ automatically announce the text update.
45
+
46
+ <ExampleCodeBlock code={VisibleLiveRegion} />
47
+
48
+ ## Hidden Live Regions
49
+
50
+ Live regions don't need to be visible UI text, they can be used to assist the non-visual listening
51
+ experience when moving the keyboard focus to a new element on screen isn't feasible.
52
+
53
+ <ExampleCodeBlock code={HiddenLiveRegion} />
54
+
55
+ ## Filtering lists with a live status
56
+
57
+ In this example, a live region is applied to a short UI text describing the number of items shown in
58
+ the list. As you type characters into the input, listen for the screen reader to automatically
59
+ describe how many items in the list or shown.
60
+
61
+ <ExampleCodeBlock code={FilterListWithLiveStatus} />
62
+
63
+ ## Text input with live inline error
64
+
65
+ In this example, a live region is applied to the inline error message that will appear below the
66
+ text input. Listen for the screen reader to automatically describe the error message as you leave
67
+ the input field blank.
68
+
69
+ **Note:** Use this example with discretion. Using live regions for automatically announcing form
70
+ errors to screen reader users can be a nice experience for simple forms with a very limited number
71
+ of error conditions. As forms increase in complexity, live regions on each error message can become
72
+ increasingly distracting and disruptive to the experience, especially if users are trying to first
73
+ understand the information that is required of them to complete the task.
74
+
75
+ <ExampleCodeBlock code={TextInputWithLiveError} />
@@ -0,0 +1,65 @@
1
+ import React, {useState} from 'react';
2
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
+ import {BodyText, Heading} from '@workday/canvas-kit-react/text';
4
+ import {AriaLiveRegion} from '@workday/canvas-kit-react/common';
5
+ import {Flex} from '@workday/canvas-kit-react/layout';
6
+ import {system, base} from '@workday/canvas-tokens-web';
7
+ import {createStyles, px2rem} from '@workday/canvas-kit-styling';
8
+
9
+ const fruits = [
10
+ 'Apples',
11
+ 'Oranges',
12
+ 'Bananas',
13
+ 'Lemons',
14
+ 'Limes',
15
+ 'Strawberries',
16
+ 'Raspberries',
17
+ 'Blackberries',
18
+ ];
19
+
20
+ const liveRegionStyle = createStyles({
21
+ border: `${px2rem(1)} solid ${base.cantaloupe400}`,
22
+ backgroundColor: base.cantaloupe100,
23
+ padding: system.space.x2,
24
+ });
25
+
26
+ const listStyles = {paddingLeft: '0px'};
27
+
28
+ const listItemStyles = createStyles({
29
+ listStyle: 'none',
30
+ paddingLeft: system.space.zero,
31
+ });
32
+
33
+ let filteredFruits = fruits;
34
+
35
+ export default () => {
36
+ const [filter, setFilter] = useState('');
37
+ function handleFilter(e) {
38
+ filteredFruits = fruits.filter(i => i.toUpperCase().indexOf(e.target.value.toUpperCase()) >= 0);
39
+ setFilter(e.target.value);
40
+ }
41
+
42
+ return (
43
+ <>
44
+ <Flex gap="1rem">
45
+ <Heading size="small">Fruits</Heading>
46
+ <AriaLiveRegion>
47
+ <BodyText size="small" cs={liveRegionStyle}>
48
+ {`Showing ${filteredFruits.length} of ${fruits.length}`}
49
+ </BodyText>
50
+ </AriaLiveRegion>
51
+ </Flex>
52
+ <TextInput orientation="vertical">
53
+ <TextInput.Label>Filter Items:</TextInput.Label>
54
+ <TextInput.Field value={filter} onChange={handleFilter} />
55
+ </TextInput>
56
+ <ul style={listStyles}>
57
+ {filteredFruits.map(i => (
58
+ <BodyText size="small" as="li" cs={listItemStyles} key={i}>
59
+ {i}
60
+ </BodyText>
61
+ ))}
62
+ </ul>
63
+ </>
64
+ );
65
+ };
@@ -0,0 +1,30 @@
1
+ import React, {useState, useRef} from 'react';
2
+ import {AriaLiveRegion, AccessibleHide} from '@workday/canvas-kit-react/common';
3
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
4
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
5
+ import {Flex} from '@workday/canvas-kit-react/layout';
6
+ import {system} from '@workday/canvas-tokens-web';
7
+
8
+ export default () => {
9
+ const [message, setMessage] = useState('This is an ARIA Live Region!');
10
+ const inputRef = useRef();
11
+ function handleSendMessage() {
12
+ setMessage(inputRef.current.value);
13
+ inputRef.current.value = '';
14
+ }
15
+
16
+ return (
17
+ <>
18
+ <Flex gap={`var(${system.space.x4})`} alignItems="flex-end">
19
+ <TextInput orientation="vertical">
20
+ <TextInput.Label>Type your message:</TextInput.Label>
21
+ <TextInput.Field ref={inputRef} />
22
+ </TextInput>
23
+ <PrimaryButton onClick={handleSendMessage}>Send Message</PrimaryButton>
24
+ </Flex>
25
+ <AriaLiveRegion>
26
+ <AccessibleHide>{message}</AccessibleHide>
27
+ </AriaLiveRegion>
28
+ </>
29
+ );
30
+ };
@@ -0,0 +1,98 @@
1
+ import React, {useState} from 'react';
2
+ import {AccessibleHide, AriaLiveRegion, useUniqueId} from '@workday/canvas-kit-react/common';
3
+ import {notificationsIcon, inboxIcon, assistantIcon} from '@workday/canvas-system-icons-web';
4
+ import {space} from '@workday/canvas-kit-react/tokens';
5
+ import {SecondaryButton, TertiaryButton} from '@workday/canvas-kit-react/button';
6
+ import {Flex} from '@workday/canvas-kit-react/layout';
7
+ import {Tooltip} from '@workday/canvas-kit-react/tooltip';
8
+ import {CountBadge} from '@workday/canvas-kit-react/badge';
9
+
10
+ const MyTasksLiveBadge = ({cnt}) => {
11
+ // use tooltip to assign name,
12
+ // use AriaLiveRegion inside button,
13
+ // assign name to live region referencing the button,
14
+ // use BadgeCount inside live region,
15
+ // use AccessibleHide to create invisible word "new" after badge
16
+ // use aria-describedby on button, referencing live region container to set description
17
+ // Safari + VO => not working at all
18
+ // JAWS 2024 + Chrome / Edge => works as expected :)
19
+ // NVDA + Chrome / Edge => works as expected :)
20
+ // Firefox => isn't announcing description on focus, only announces "X New" live (missing button name)
21
+ const badgeID = useUniqueId();
22
+ const myTasksID = useUniqueId();
23
+
24
+ return (
25
+ <Tooltip title="My Tasks">
26
+ <TertiaryButton icon={inboxIcon} id={myTasksID} aria-describedby={badgeID}>
27
+ <AriaLiveRegion id={badgeID} aria-labelledby={myTasksID}>
28
+ <CountBadge count={cnt} />
29
+ <AccessibleHide>New</AccessibleHide>
30
+ </AriaLiveRegion>
31
+ </TertiaryButton>
32
+ </Tooltip>
33
+ );
34
+ };
35
+
36
+ // use AriaLiveRegion around the button,
37
+ // use Tooltip to assign the name of the button,
38
+ // make sure Tooltip title string includes count value
39
+ // Chrome + VO => Announces name "notifications X new" and innerText 'X'
40
+ // Safari + VO => Works as expected :)
41
+ // JAWS 2024 => Announces full button name twice (previous state, then new state)
42
+ // JAWS 2024 + Firefox => Works as expected :)
43
+ // NVDA (All Browsers) => Atomic property isn't working, only announcing number change, announces twice
44
+ const NotificationsLiveBadge = ({cnt}) => (
45
+ <AriaLiveRegion>
46
+ <Tooltip title={`Notifications ${cnt} new`}>
47
+ <TertiaryButton icon={notificationsIcon}>
48
+ <CountBadge count={cnt} />
49
+ </TertiaryButton>
50
+ </Tooltip>
51
+ </AriaLiveRegion>
52
+ );
53
+
54
+ const AssistantLiveBadge = ({cnt}) => {
55
+ // use AriaLiveRegion around the button
56
+ // use muted type Tooltip (avoid using aria-label to name button)
57
+ // use AccessibleHide inside of button to compose name
58
+ // Chrome + VO => announces twice
59
+ // Safari + VO => works as expected :)
60
+ const lbl = 'Workday Assistant';
61
+
62
+ return (
63
+ <AriaLiveRegion>
64
+ <Tooltip title={lbl} type="muted">
65
+ <TertiaryButton icon={assistantIcon}>
66
+ <AccessibleHide>{lbl}</AccessibleHide>
67
+ <CountBadge count={cnt} />
68
+ <AccessibleHide>New</AccessibleHide>
69
+ </TertiaryButton>
70
+ </Tooltip>
71
+ </AriaLiveRegion>
72
+ );
73
+ };
74
+
75
+ export default () => {
76
+ const [counter, setCounter] = useState(0);
77
+ const [notifications, setNotifications] = useState(0);
78
+ const [assistant, setAssistant] = useState(0);
79
+
80
+ const handleAddTask = () => setCounter(prev => prev + 1);
81
+ const handleAddNotification = () => setNotifications(prev => prev + 1);
82
+ const handleAssistant = () => setAssistant(prev => prev + 1);
83
+
84
+ return (
85
+ <>
86
+ <Flex padding={space.s} gap={space.s} as="header">
87
+ <AssistantLiveBadge cnt={assistant} />
88
+ <NotificationsLiveBadge cnt={notifications} />
89
+ <MyTasksLiveBadge cnt={counter} />
90
+ </Flex>
91
+ <Flex padding={space.s} gap={space.s} as="main">
92
+ <SecondaryButton onClick={handleAssistant}>Add a Message</SecondaryButton>
93
+ <SecondaryButton onClick={handleAddNotification}>Add a Notification</SecondaryButton>
94
+ <SecondaryButton onClick={handleAddTask}>Add an item to My Tasks</SecondaryButton>
95
+ </Flex>
96
+ </>
97
+ );
98
+ };
@@ -0,0 +1,25 @@
1
+ import React, {useState, useRef} from 'react';
2
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
+ import {AriaLiveRegion, changeFocus} from '@workday/canvas-kit-react/common';
4
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
5
+
6
+ export default () => {
7
+ const errMsg = 'Error: First name is required.';
8
+ const [hasError, setHasError] = useState(false);
9
+ const inputRef = useRef();
10
+ const handleBlur = e => setHasError(e.target.value.trim().length === 0);
11
+ const handleSubmit = () => hasError && changeFocus(inputRef.current);
12
+
13
+ return (
14
+ <>
15
+ <TextInput orientation="vertical" hasError={hasError} isRequired={true}>
16
+ <TextInput.Label>First Name:</TextInput.Label>
17
+ <TextInput.Field onBlur={handleBlur} ref={inputRef} />
18
+ <TextInput.Hint height={'16px'}>
19
+ <AriaLiveRegion>{hasError && errMsg}</AriaLiveRegion>
20
+ </TextInput.Hint>
21
+ </TextInput>
22
+ <PrimaryButton onClick={handleSubmit}>Continue</PrimaryButton>
23
+ </>
24
+ );
25
+ };
@@ -0,0 +1,40 @@
1
+ import React, {useState, useRef} from 'react';
2
+ import {AriaLiveRegion} from '@workday/canvas-kit-react/common';
3
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
4
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
5
+ import {Flex} from '@workday/canvas-kit-react/layout';
6
+ import {Text} from '@workday/canvas-kit-react/text';
7
+ import {system, base} from '@workday/canvas-tokens-web';
8
+ import {createStyles, px2rem} from '@workday/canvas-kit-styling';
9
+
10
+ const liveRegionStyle = createStyles({
11
+ border: `${px2rem(1)} solid ${base.cantaloupe400}`,
12
+ backgroundColor: base.cantaloupe100,
13
+ padding: system.space.x4,
14
+ display: 'block',
15
+ margin: system.space.x4 + ' 0',
16
+ });
17
+
18
+ export default () => {
19
+ const [message, setMessage] = useState('This is an ARIA Live Region!');
20
+ const inputRef = useRef();
21
+ function handleSendMessage() {
22
+ setMessage(inputRef.current.value);
23
+ inputRef.current.value = '';
24
+ }
25
+
26
+ return (
27
+ <>
28
+ <AriaLiveRegion>
29
+ <Text cs={liveRegionStyle}>{message}</Text>
30
+ </AriaLiveRegion>
31
+ <Flex gap={`var(${system.space.x4})`} alignItems="flex-end">
32
+ <TextInput orientation="vertical">
33
+ <TextInput.Label>Type your message:</TextInput.Label>
34
+ <TextInput.Field ref={inputRef} />
35
+ </TextInput>
36
+ <PrimaryButton onClick={handleSendMessage}>Send Message</PrimaryButton>
37
+ </Flex>
38
+ </>
39
+ );
40
+ };
@@ -28,7 +28,19 @@ yarn add @workday/canvas-kit-react
28
28
 
29
29
  <ExampleCodeBlock code={RTL} />
30
30
 
31
- ### Accessible Example
31
+ ### Adding screen reader support to loading animations
32
+
33
+ Sometimes, letting users know when content has finished loading is just as important as asking users
34
+ to "please wait" while content is loading. The disappearance of an animation is information that
35
+ might need description. In this example, we are using `AriaLiveRegion` and `AccessibleHide`
36
+ components included in Canvas to describe both the appearance and disappearance of `LoadingDots`.
37
+
38
+ - When idle, render an empty live region
39
+ - When loading, render `LoadingDots` inside the live region,
40
+ - When complete, render `AccessibleHide` inside the live region expressing "Complete!"
41
+ - We can assign a name to `AriaLiveRegion` component by passing in `aria-label="Loading"`
42
+ - We can declare `LoadingDots` a labeled graphic by passing `role="img"` and
43
+ `aria-label="Please wait..."` into the component
32
44
 
33
45
  <ExampleCodeBlock code={Accessible} />
34
46
 
@@ -1,6 +1,44 @@
1
1
  import React from 'react';
2
2
  import {LoadingDots} from '@workday/canvas-kit-react/loading-dots';
3
+ import {base, system} from '@workday/canvas-tokens-web';
4
+ import {Flex} from '@workday/canvas-kit-react/layout';
5
+ import {SecondaryButton} from '@workday/canvas-kit-react/button';
6
+ import {createStyles, cssVar} from '@workday/canvas-kit-styling';
7
+ import {AccessibleHide, AriaLiveRegion} from '@workday/canvas-kit-react/common';
8
+
9
+ const loadingStyles = createStyles({
10
+ backgroundColor: base.licorice300,
11
+ padding: system.space.x3,
12
+ });
3
13
 
4
14
  export default () => {
5
- return <LoadingDots aria-live="polite" aria-label="Loading Users" />;
15
+ const [loadingState, setLoadingState] = React.useState('idle');
16
+
17
+ React.useEffect(() => {
18
+ const timer = setTimeout(() => {
19
+ if (loadingState === 'loading') {
20
+ setLoadingState('success');
21
+ }
22
+ }, 4000);
23
+
24
+ return () => {
25
+ clearTimeout(timer);
26
+ };
27
+ }, [loadingState]);
28
+
29
+ const handleLoad = () => {
30
+ setLoadingState('loading');
31
+ };
32
+
33
+ return (
34
+ <Flex gap={cssVar(system.space.x4)}>
35
+ <SecondaryButton onClick={handleLoad}>Start</SecondaryButton>
36
+ <AriaLiveRegion aria-label="Loading">
37
+ {loadingState === 'loading' && (
38
+ <LoadingDots className={loadingStyles} role="img" aria-label="Please wait..." />
39
+ )}
40
+ {loadingState === 'success' && <AccessibleHide>Complete.</AccessibleHide>}
41
+ </AriaLiveRegion>
42
+ </Flex>
43
+ );
6
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "11.0.0-alpha.766-next.0",
3
+ "version": "11.0.0-alpha.769-next.0",
4
4
  "description": "Documentation components of Canvas Kit components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -44,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@emotion/styled": "^11.6.0",
46
46
  "@storybook/csf": "0.0.1",
47
- "@workday/canvas-kit-labs-react": "^11.0.0-alpha.766-next.0",
48
- "@workday/canvas-kit-preview-react": "^11.0.0-alpha.766-next.0",
49
- "@workday/canvas-kit-react": "^11.0.0-alpha.766-next.0",
50
- "@workday/canvas-kit-styling": "^11.0.0-alpha.766-next.0",
47
+ "@workday/canvas-kit-labs-react": "^11.0.0-alpha.769-next.0",
48
+ "@workday/canvas-kit-preview-react": "^11.0.0-alpha.769-next.0",
49
+ "@workday/canvas-kit-react": "^11.0.0-alpha.769-next.0",
50
+ "@workday/canvas-kit-styling": "^11.0.0-alpha.769-next.0",
51
51
  "@workday/canvas-system-icons-web": "^3.0.0",
52
52
  "@workday/canvas-tokens-web": "^1.3.0",
53
53
  "markdown-to-jsx": "^6.10.3",
@@ -59,5 +59,5 @@
59
59
  "mkdirp": "^1.0.3",
60
60
  "typescript": "4.2"
61
61
  },
62
- "gitHead": "a0883a359bb6af9d380b1e562662713b99fad4cc"
62
+ "gitHead": "6ccdc31e5c364c7a8a6f29f7b797032a914ca2c5"
63
63
  }