@workday/canvas-kit-docs 11.0.0-alpha.682-next.0 → 11.0.0-alpha.693-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.
- package/dist/es6/lib/docs.js +186 -12
- package/dist/es6/lib/specs.js +24 -0
- package/dist/es6/mdx/versionsTable.d.ts +2 -0
- package/dist/es6/mdx/versionsTable.d.ts.map +1 -0
- package/dist/es6/mdx/versionsTable.js +76 -0
- package/dist/mdx/Versions.mdx +8 -0
- package/dist/mdx/preview-react/_examples/TablesAdvanced.mdx +84 -0
- package/dist/mdx/preview-react/_examples/examples/Table/WithExpandableRows.tsx +219 -0
- package/dist/mdx/preview-react/_examples/examples/Table/WithSelectableRows.tsx +156 -0
- package/dist/mdx/preview-react/_examples/examples/Table/WithSortableColumnHeaders.tsx +213 -0
- package/dist/mdx/preview-react/table/Table.mdx +16 -1
- package/dist/mdx/preview-react/table/examples/RightToLeft.tsx +38 -0
- package/dist/mdx/react/select/Select.mdx +82 -7
- package/dist/mdx/react/select/examples/Basic.tsx +1 -1
- package/dist/mdx/react/select/examples/Complex.tsx +11 -16
- package/dist/mdx/react/select/examples/FetchingDynamicItems.tsx +103 -0
- package/dist/mdx/react/select/examples/Grow.tsx +1 -5
- package/dist/mdx/react/select/examples/HoistedModel.tsx +8 -15
- package/dist/mdx/react/select/examples/InitialSelectedItem.tsx +60 -0
- package/dist/mdx/react/select/examples/LabelPosition.tsx +1 -3
- package/dist/mdx/react/select/examples/Placeholder.tsx +41 -0
- package/dist/mdx/react/select/examples/RefForwarding.tsx +1 -0
- package/package.json +6 -6
package/dist/es6/lib/docs.js
CHANGED
|
@@ -80191,6 +80191,30 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
80191
80191
|
}
|
|
80192
80192
|
],
|
|
80193
80193
|
"tags": {}
|
|
80194
|
+
},
|
|
80195
|
+
{
|
|
80196
|
+
"kind": "property",
|
|
80197
|
+
"name": "item",
|
|
80198
|
+
"required": false,
|
|
80199
|
+
"type": {
|
|
80200
|
+
"kind": "symbol",
|
|
80201
|
+
"name": "Item",
|
|
80202
|
+
"typeParameters": [
|
|
80203
|
+
{
|
|
80204
|
+
"kind": "primitive",
|
|
80205
|
+
"value": "any"
|
|
80206
|
+
}
|
|
80207
|
+
],
|
|
80208
|
+
"value": "Item<T>"
|
|
80209
|
+
},
|
|
80210
|
+
"description": "",
|
|
80211
|
+
"declarations": [
|
|
80212
|
+
{
|
|
80213
|
+
"name": "item",
|
|
80214
|
+
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/collection/lib/useListItemAllowChildStrings.ts"
|
|
80215
|
+
}
|
|
80216
|
+
],
|
|
80217
|
+
"tags": {}
|
|
80194
80218
|
}
|
|
80195
80219
|
]
|
|
80196
80220
|
},
|
|
@@ -102843,6 +102867,27 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
102843
102867
|
"tags": {},
|
|
102844
102868
|
"declarations": []
|
|
102845
102869
|
},
|
|
102870
|
+
{
|
|
102871
|
+
"kind": "property",
|
|
102872
|
+
"name": "aria-activedescendant",
|
|
102873
|
+
"required": true,
|
|
102874
|
+
"type": {
|
|
102875
|
+
"kind": "union",
|
|
102876
|
+
"value": [
|
|
102877
|
+
{
|
|
102878
|
+
"kind": "primitive",
|
|
102879
|
+
"value": "null"
|
|
102880
|
+
},
|
|
102881
|
+
{
|
|
102882
|
+
"kind": "primitive",
|
|
102883
|
+
"value": "undefined"
|
|
102884
|
+
}
|
|
102885
|
+
]
|
|
102886
|
+
},
|
|
102887
|
+
"description": "",
|
|
102888
|
+
"tags": {},
|
|
102889
|
+
"declarations": []
|
|
102890
|
+
},
|
|
102846
102891
|
{
|
|
102847
102892
|
"kind": "property",
|
|
102848
102893
|
"name": "id",
|
|
@@ -193138,6 +193183,23 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
193138
193183
|
}
|
|
193139
193184
|
],
|
|
193140
193185
|
"tags": {}
|
|
193186
|
+
},
|
|
193187
|
+
{
|
|
193188
|
+
"kind": "property",
|
|
193189
|
+
"name": "placeholder",
|
|
193190
|
+
"required": false,
|
|
193191
|
+
"type": {
|
|
193192
|
+
"kind": "primitive",
|
|
193193
|
+
"value": "string"
|
|
193194
|
+
},
|
|
193195
|
+
"description": "",
|
|
193196
|
+
"declarations": [
|
|
193197
|
+
{
|
|
193198
|
+
"name": "placeholder",
|
|
193199
|
+
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/select/lib/hooks/useSelectInput.ts"
|
|
193200
|
+
}
|
|
193201
|
+
],
|
|
193202
|
+
"tags": {}
|
|
193141
193203
|
}
|
|
193142
193204
|
]
|
|
193143
193205
|
},
|
|
@@ -193197,6 +193259,112 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
193197
193259
|
"tags": {},
|
|
193198
193260
|
"declarations": []
|
|
193199
193261
|
},
|
|
193262
|
+
{
|
|
193263
|
+
"kind": "property",
|
|
193264
|
+
"name": "onChange",
|
|
193265
|
+
"required": true,
|
|
193266
|
+
"type": {
|
|
193267
|
+
"kind": "function",
|
|
193268
|
+
"parameters": [
|
|
193269
|
+
{
|
|
193270
|
+
"kind": "parameter",
|
|
193271
|
+
"name": "event",
|
|
193272
|
+
"type": {
|
|
193273
|
+
"kind": "symbol",
|
|
193274
|
+
"name": "React.ChangeEvent",
|
|
193275
|
+
"typeParameters": [
|
|
193276
|
+
{
|
|
193277
|
+
"kind": "symbol",
|
|
193278
|
+
"name": "HTMLInputElement",
|
|
193279
|
+
"value": "HTMLInputElement"
|
|
193280
|
+
}
|
|
193281
|
+
],
|
|
193282
|
+
"value": "ChangeEvent<T>"
|
|
193283
|
+
},
|
|
193284
|
+
"required": true,
|
|
193285
|
+
"rest": false,
|
|
193286
|
+
"description": "",
|
|
193287
|
+
"declarations": [
|
|
193288
|
+
{
|
|
193289
|
+
"name": "event",
|
|
193290
|
+
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/react/select/lib/hooks/useSelectInput.ts"
|
|
193291
|
+
}
|
|
193292
|
+
],
|
|
193293
|
+
"tags": {}
|
|
193294
|
+
}
|
|
193295
|
+
],
|
|
193296
|
+
"members": [],
|
|
193297
|
+
"returnType": {
|
|
193298
|
+
"kind": "primitive",
|
|
193299
|
+
"value": "void"
|
|
193300
|
+
}
|
|
193301
|
+
},
|
|
193302
|
+
"description": "",
|
|
193303
|
+
"tags": {},
|
|
193304
|
+
"declarations": []
|
|
193305
|
+
},
|
|
193306
|
+
{
|
|
193307
|
+
"kind": "property",
|
|
193308
|
+
"name": "autoComplete",
|
|
193309
|
+
"required": true,
|
|
193310
|
+
"type": {
|
|
193311
|
+
"kind": "string",
|
|
193312
|
+
"value": "off"
|
|
193313
|
+
},
|
|
193314
|
+
"description": "",
|
|
193315
|
+
"tags": {},
|
|
193316
|
+
"declarations": []
|
|
193317
|
+
},
|
|
193318
|
+
{
|
|
193319
|
+
"kind": "property",
|
|
193320
|
+
"name": "onFocus",
|
|
193321
|
+
"required": true,
|
|
193322
|
+
"type": {
|
|
193323
|
+
"kind": "function",
|
|
193324
|
+
"parameters": [],
|
|
193325
|
+
"members": [],
|
|
193326
|
+
"returnType": {
|
|
193327
|
+
"kind": "primitive",
|
|
193328
|
+
"value": "void"
|
|
193329
|
+
}
|
|
193330
|
+
},
|
|
193331
|
+
"description": "",
|
|
193332
|
+
"tags": {},
|
|
193333
|
+
"declarations": []
|
|
193334
|
+
},
|
|
193335
|
+
{
|
|
193336
|
+
"kind": "property",
|
|
193337
|
+
"name": "textInputProps",
|
|
193338
|
+
"required": true,
|
|
193339
|
+
"type": {
|
|
193340
|
+
"kind": "object",
|
|
193341
|
+
"properties": [
|
|
193342
|
+
{
|
|
193343
|
+
"kind": "property",
|
|
193344
|
+
"name": "ref",
|
|
193345
|
+
"required": true,
|
|
193346
|
+
"type": {
|
|
193347
|
+
"kind": "symbol",
|
|
193348
|
+
"name": "RefObject",
|
|
193349
|
+
"typeParameters": [
|
|
193350
|
+
{
|
|
193351
|
+
"kind": "symbol",
|
|
193352
|
+
"name": "HTMLInputElement",
|
|
193353
|
+
"value": "any"
|
|
193354
|
+
}
|
|
193355
|
+
],
|
|
193356
|
+
"value": "any"
|
|
193357
|
+
},
|
|
193358
|
+
"description": "",
|
|
193359
|
+
"tags": {},
|
|
193360
|
+
"declarations": []
|
|
193361
|
+
}
|
|
193362
|
+
]
|
|
193363
|
+
},
|
|
193364
|
+
"description": "",
|
|
193365
|
+
"tags": {},
|
|
193366
|
+
"declarations": []
|
|
193367
|
+
},
|
|
193200
193368
|
{
|
|
193201
193369
|
"kind": "property",
|
|
193202
193370
|
"name": "ref",
|
|
@@ -193243,18 +193411,6 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
193243
193411
|
"tags": {},
|
|
193244
193412
|
"declarations": []
|
|
193245
193413
|
},
|
|
193246
|
-
{
|
|
193247
|
-
"kind": "property",
|
|
193248
|
-
"name": "autoComplete",
|
|
193249
|
-
"required": true,
|
|
193250
|
-
"type": {
|
|
193251
|
-
"kind": "string",
|
|
193252
|
-
"value": "off"
|
|
193253
|
-
},
|
|
193254
|
-
"description": "",
|
|
193255
|
-
"tags": {},
|
|
193256
|
-
"declarations": []
|
|
193257
|
-
},
|
|
193258
193414
|
{
|
|
193259
193415
|
"kind": "property",
|
|
193260
193416
|
"name": "defaultValue",
|
|
@@ -200094,6 +200250,24 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
|
|
|
200094
200250
|
],
|
|
200095
200251
|
"tags": {}
|
|
200096
200252
|
},
|
|
200253
|
+
{
|
|
200254
|
+
"kind": "property",
|
|
200255
|
+
"name": "cs",
|
|
200256
|
+
"required": false,
|
|
200257
|
+
"type": {
|
|
200258
|
+
"kind": "symbol",
|
|
200259
|
+
"name": "CSToPropsInput",
|
|
200260
|
+
"value": "CSToPropsInput"
|
|
200261
|
+
},
|
|
200262
|
+
"description": "The `cs` prop takes in a single value or an array of values. You can pass the CSS class name\nreturned by {@link createStyles}, or the result of {@link createVars} and\n{@link createModifiers}. If you're extending a component already using `cs`, you can merge that\nprop in as well. Any style that is passed to the `cs` prop will override style props. If you\nwish to have styles that are overridden by the `css` prop, or styles added via the `styled`\nAPI, use {@link handleCsProp} wherever `elemProps` is used. If your component needs to also\nhandle style props, use {@link mergeStyles} instead.\n\n\n```tsx\nimport {handleCsProp} from '@workday/canvas-kit-styling';\nimport {mergeStyles} from '@workday/canvas-kit-react/layout';\n\n// ...\n\n// `handleCsProp` handles compat mode with Emotion's runtime APIs. `mergeStyles` has the same\n// function signature, but adds support for style props.\n\nreturn (\n <Element\n {...handleCsProp(elemProps, [\n myStyles,\n myModifiers({ size: 'medium' }),\n myVars({ backgroundColor: 'red' })\n ])}\n >\n {children}\n </Element>\n)\n```",
|
|
200263
|
+
"declarations": [
|
|
200264
|
+
{
|
|
200265
|
+
"name": "cs",
|
|
200266
|
+
"filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/styling/dist/es6/lib/cs.d.ts"
|
|
200267
|
+
}
|
|
200268
|
+
],
|
|
200269
|
+
"tags": {}
|
|
200270
|
+
},
|
|
200097
200271
|
{
|
|
200098
200272
|
"kind": "property",
|
|
200099
200273
|
"name": "children",
|
package/dist/es6/lib/specs.js
CHANGED
|
@@ -4345,6 +4345,10 @@ module.exports = {specifications: [
|
|
|
4345
4345
|
"type": "it",
|
|
4346
4346
|
"name": "should not have any axe errors"
|
|
4347
4347
|
},
|
|
4348
|
+
{
|
|
4349
|
+
"type": "it",
|
|
4350
|
+
"name": "should not have an aria-activedescendant attribute"
|
|
4351
|
+
},
|
|
4348
4352
|
{
|
|
4349
4353
|
"type": "describe",
|
|
4350
4354
|
"name": "when the select button is clicked",
|
|
@@ -4587,6 +4591,10 @@ module.exports = {specifications: [
|
|
|
4587
4591
|
"type": "describe",
|
|
4588
4592
|
"name": "when the menu is closed WITHOUT selecting the newly focused option (\"Phone\")",
|
|
4589
4593
|
"children": [
|
|
4594
|
+
{
|
|
4595
|
+
"type": "it",
|
|
4596
|
+
"name": "should not have an aria-activedescendant attribute"
|
|
4597
|
+
},
|
|
4590
4598
|
{
|
|
4591
4599
|
"type": "describe",
|
|
4592
4600
|
"name": "when the menu is re-opened AFTER it has fully closed",
|
|
@@ -4946,6 +4954,22 @@ module.exports = {specifications: [
|
|
|
4946
4954
|
]
|
|
4947
4955
|
}
|
|
4948
4956
|
]
|
|
4957
|
+
},
|
|
4958
|
+
{
|
|
4959
|
+
"type": "describe",
|
|
4960
|
+
"name": "given the \"FetchingDynamicItems\" story is rendered",
|
|
4961
|
+
"children": [
|
|
4962
|
+
{
|
|
4963
|
+
"type": "describe",
|
|
4964
|
+
"name": "when Get Items is clicked",
|
|
4965
|
+
"children": [
|
|
4966
|
+
{
|
|
4967
|
+
"type": "it",
|
|
4968
|
+
"name": "should change the value of the select to 456 (the id) after 1.5 seconds"
|
|
4969
|
+
}
|
|
4970
|
+
]
|
|
4971
|
+
}
|
|
4972
|
+
]
|
|
4949
4973
|
}
|
|
4950
4974
|
]
|
|
4951
4975
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versionsTable.d.ts","sourceRoot":"","sources":["../../../mdx/versionsTable.tsx"],"names":[],"mappings":"AA6DA,eAAO,MAAM,YAAY,mBAgCxB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Table, StatusIndicator } from '@workday/canvas-kit-preview-react';
|
|
3
|
+
// @ts-ignore: Cannot find module error
|
|
4
|
+
import { version } from '../../../lerna.json';
|
|
5
|
+
// When we release a new version, add the support version before the first item.
|
|
6
|
+
const allVersions = [
|
|
7
|
+
{
|
|
8
|
+
versionNumber: version,
|
|
9
|
+
documentation: 'https://github.com/Workday/canvas-kit',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
versionNumber: 9,
|
|
13
|
+
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v9/?path=/docs/welcome--page',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
versionNumber: 8,
|
|
17
|
+
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/welcome--page',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
versionNumber: 7,
|
|
21
|
+
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v7/?path=/story/welcome-getting-started--page',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
versionNumber: 6,
|
|
25
|
+
documentation: 'https://d2krrudi3mmzzw.cloudfront.net/v7/?path=/story/welcome-getting-started--page',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
const statusIndicators = {
|
|
29
|
+
stable: {
|
|
30
|
+
variant: 'blue',
|
|
31
|
+
label: 'Stable',
|
|
32
|
+
},
|
|
33
|
+
support: {
|
|
34
|
+
variant: 'green',
|
|
35
|
+
label: 'Support',
|
|
36
|
+
},
|
|
37
|
+
deprecated: {
|
|
38
|
+
variant: 'red',
|
|
39
|
+
label: 'No Longer Supported',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
function getVersionStatusIndicator(versionNumber) {
|
|
43
|
+
// version from lerna is a string, so we need to do modify into a number
|
|
44
|
+
const currentMajorVersion = Number(version.split('.')[0]);
|
|
45
|
+
const modifiedVersionNumber = typeof versionNumber === 'string' ? Number(versionNumber.split('.')[0]) : versionNumber;
|
|
46
|
+
// if this is the current version
|
|
47
|
+
if (modifiedVersionNumber === currentMajorVersion) {
|
|
48
|
+
return statusIndicators.stable;
|
|
49
|
+
}
|
|
50
|
+
else if (modifiedVersionNumber === currentMajorVersion - 1) {
|
|
51
|
+
return statusIndicators.support;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return statusIndicators.deprecated;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const VersionTable = () => {
|
|
58
|
+
return (React.createElement(Table, null,
|
|
59
|
+
React.createElement(Table.Head, null,
|
|
60
|
+
React.createElement(Table.Row, null,
|
|
61
|
+
React.createElement(Table.Header, { scope: "col" }, "Version"),
|
|
62
|
+
React.createElement(Table.Header, { scope: "col" }, "Documentation"),
|
|
63
|
+
React.createElement(Table.Header, { scope: "col" }, "Status"))),
|
|
64
|
+
React.createElement(Table.Body, null, allVersions.map(item => {
|
|
65
|
+
const { label, variant } = getVersionStatusIndicator(item.versionNumber);
|
|
66
|
+
return (React.createElement(Table.Row, null,
|
|
67
|
+
React.createElement(Table.Cell, null,
|
|
68
|
+
"v",
|
|
69
|
+
item.versionNumber),
|
|
70
|
+
React.createElement(Table.Cell, null,
|
|
71
|
+
React.createElement("a", { href: item.documentation, target: "_blank", rel: "noreferrer" }, "Documentation")),
|
|
72
|
+
React.createElement(Table.Cell, null,
|
|
73
|
+
React.createElement(StatusIndicator, { variant: variant },
|
|
74
|
+
React.createElement(StatusIndicator.Label, null, label)))));
|
|
75
|
+
}))));
|
|
76
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {Table} from '@workday/canvas-kit-preview-react/table';
|
|
2
|
+
|
|
3
|
+
import SelectableRows from './examples/Table/WithSelectableRows';
|
|
4
|
+
import ExpandableRows from './examples/Table/WithExpandableRows';
|
|
5
|
+
import SortableColumnHeaders from './examples/Table/WithSortableColumnHeaders';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Advanced Table Examples
|
|
9
|
+
|
|
10
|
+
Out of the box, `Table` is a lightweight component with a high degree of flexibility, but not much
|
|
11
|
+
functionality outside of providing a basic table layout. This leaves a gap for developers to
|
|
12
|
+
implement common features, such as selecting rows and sorting columns, on top of `Table` to meet
|
|
13
|
+
their specific application needs. During the development process, it's often unclear how to
|
|
14
|
+
implement these features in an accessible way. In an effort to reduce that gap and increase clarity,
|
|
15
|
+
we've documented several advanced examples below to communicate the accessibility nuances alongside
|
|
16
|
+
tangible code snippets.
|
|
17
|
+
|
|
18
|
+
### Expandable Rows
|
|
19
|
+
|
|
20
|
+
Expandable Rows combines the likes of an accordion with tabular data tables. Column 1 renders icon
|
|
21
|
+
buttons with 2 states, a collapsed and expanded state. A new row that spans the entire width of the
|
|
22
|
+
table is added to the table just after the expanded row.
|
|
23
|
+
|
|
24
|
+
- The `aria-expanded` property is added to the button to communicate this state to screen reader
|
|
25
|
+
users.
|
|
26
|
+
- A Canvas accessible `Tooltip` component is used to assign names to each icon button based on the
|
|
27
|
+
most useful value in the row. In this example, we combined the car make and model together. This
|
|
28
|
+
allows everyone to view the name of the checkboxes by hovering the mouse or focusing with the
|
|
29
|
+
keyboard.
|
|
30
|
+
- The expanded row uses `colspan` to span the entire width of the table and support screen readers.
|
|
31
|
+
This space provides flexibility to show headings, lists, and other structured content for the
|
|
32
|
+
table row above.
|
|
33
|
+
- There is no explicit relationship between a row of cells, and the spanned content below it. The
|
|
34
|
+
spanned content is assumed to belong to the row of cells above it, based on established accordion
|
|
35
|
+
patterns and logical reading order of content rendered to the screen.
|
|
36
|
+
- Outlining hierarchy in a data table is not supported for screen readers in this example.
|
|
37
|
+
|
|
38
|
+
<ExampleCodeBlock code={ExpandableRows} />
|
|
39
|
+
|
|
40
|
+
### Selectable Rows
|
|
41
|
+
|
|
42
|
+
Developed by the Workday accessibility team, using a `Checkbox` labeled "Select All" inside of a table
|
|
43
|
+
column header can be a confusing experience for screen reader users. Screen readers will
|
|
44
|
+
automatically announce the "Select All" column header each time users are reading any cell in
|
|
45
|
+
column 1. For instance, the `Checkbox` in row 4 is decidedly not going to select all of the rows. Here
|
|
46
|
+
is what we did about it:
|
|
47
|
+
|
|
48
|
+
- We intentionally rendered row 1, column 1 as a standard `<td>` element so screen readers won't
|
|
49
|
+
automatically announce "Select All" while reading cells in column 1.
|
|
50
|
+
- Our research found that VoiceOver (MacOS v12.7, Safari v17.1) persistently announce "Select All"
|
|
51
|
+
despite using the `<td>` element because of the optional `<thead>` element in the table. We
|
|
52
|
+
omitted the optional `<thead>` and `<tbody>` elements from this example for that reason.
|
|
53
|
+
- We used Canvas' accessible `Tooltip` component to assign names to each Checkbox based on the most
|
|
54
|
+
useful value in the row, the topping name. This allows everyone to view the name of the checkboxes
|
|
55
|
+
by hovering the mouse or focusing with the keyboard.
|
|
56
|
+
- We rendered the cells in column 2 as the row headers for the table, enabling screen readers to
|
|
57
|
+
automatically announce the topping name even while reading down the Amounts in column 3. When we
|
|
58
|
+
rendered column 1 as row headers, then reading down column 2 (Topping Name) sounded redundant
|
|
59
|
+
because the `Checkbox` names in column 1 are identical to the Topping Name in column 2.
|
|
60
|
+
|
|
61
|
+
<ExampleCodeBlock code={SelectableRows} />
|
|
62
|
+
|
|
63
|
+
### Sortable Column Headers
|
|
64
|
+
|
|
65
|
+
The challenge in this example is, how will we clearly communicate the complexity of the column
|
|
66
|
+
headers to screen readers and keep the tabular data easy to understand? The column headers must
|
|
67
|
+
describe the column name, the current sort state of the column, they are interactive (a button), and
|
|
68
|
+
instructions about how the column will be sorted next. When screen reader users are focused on the
|
|
69
|
+
tabular data cells, instructions about how the column will be sorted next is probably not relevant,
|
|
70
|
+
distracting, and makes it harder to understand the data.
|
|
71
|
+
|
|
72
|
+
- The `aria-sort` property has been initialized to `none` on each of the `<th>` elements; this value
|
|
73
|
+
is updated to `ascending` or `descending` to reflect the current state.
|
|
74
|
+
- A `<button>` element describing the column name is used inside of the `<th>` column header.
|
|
75
|
+
- The `describe` variant of the Canvas `Tooltip` component is applied to the button in the column
|
|
76
|
+
header. This is used to describe how the column will be sorted after interaction and applied to
|
|
77
|
+
the accessible description of the button with the `aria-describedby` property. This way screen
|
|
78
|
+
readers won't read the longer description of the column headers automatically while focusing on
|
|
79
|
+
the tabular data below.
|
|
80
|
+
- The `aria-sort` property may not reliably provide the current sort state of the column to users
|
|
81
|
+
focused on the tabular data in the table. It may be more reliable to use an `aria-label` string on
|
|
82
|
+
the button that describes the column name and sort state together.
|
|
83
|
+
|
|
84
|
+
<ExampleCodeBlock code={SortableColumnHeaders} />
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {StatusIndicator} from '@workday/canvas-kit-preview-react/status-indicator';
|
|
4
|
+
import {Table} from '@workday/canvas-kit-preview-react/table';
|
|
5
|
+
import {TertiaryButton} from '@workday/canvas-kit-react/button';
|
|
6
|
+
import {createComponent, generateUniqueId} from '@workday/canvas-kit-react/common';
|
|
7
|
+
import {Heading, Subtext} from '@workday/canvas-kit-react/text';
|
|
8
|
+
import {Tooltip} from '@workday/canvas-kit-react/tooltip';
|
|
9
|
+
import {createStyles} from '@workday/canvas-kit-styling';
|
|
10
|
+
|
|
11
|
+
import {chevronDownSmallIcon, chevronRightSmallIcon} from '@workday/canvas-system-icons-web';
|
|
12
|
+
import {system} from '@workday/canvas-tokens-web';
|
|
13
|
+
|
|
14
|
+
interface AutoData {
|
|
15
|
+
id: string;
|
|
16
|
+
brand: string;
|
|
17
|
+
model: string;
|
|
18
|
+
year: string;
|
|
19
|
+
price: string;
|
|
20
|
+
engine: string;
|
|
21
|
+
transmission: string;
|
|
22
|
+
horsepower: string;
|
|
23
|
+
torque: string;
|
|
24
|
+
curbWeight: string;
|
|
25
|
+
orderStatus: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const headingID = generateUniqueId();
|
|
29
|
+
const autoData: AutoData[] = [
|
|
30
|
+
{
|
|
31
|
+
id: generateUniqueId(),
|
|
32
|
+
brand: 'Porsche',
|
|
33
|
+
model: '992 911 GT3',
|
|
34
|
+
year: '2022',
|
|
35
|
+
price: 'Starts at $160,000',
|
|
36
|
+
engine: '4.0L Flat 6',
|
|
37
|
+
transmission: 'PDK or 7-Speed Manual',
|
|
38
|
+
horsepower: '502hp',
|
|
39
|
+
torque: '346 lb-ft',
|
|
40
|
+
curbWeight: '3,164 lbs',
|
|
41
|
+
orderStatus: 'Order Placed',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: generateUniqueId(),
|
|
45
|
+
brand: 'BMW',
|
|
46
|
+
model: 'M5 Competition',
|
|
47
|
+
year: '2018',
|
|
48
|
+
price: 'Starts at $105,000',
|
|
49
|
+
engine: 'Twin-Turbo 4.4L V8',
|
|
50
|
+
transmission: 'Automatic',
|
|
51
|
+
horsepower: '627hp',
|
|
52
|
+
torque: '553 lb-ft',
|
|
53
|
+
curbWeight: '4,345 lbs',
|
|
54
|
+
orderStatus: 'Order Fulfilled',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: generateUniqueId(),
|
|
58
|
+
brand: 'Audi',
|
|
59
|
+
model: 'R8',
|
|
60
|
+
year: '2022',
|
|
61
|
+
price: 'Starts at $148,000',
|
|
62
|
+
engine: '5.2L V10',
|
|
63
|
+
transmission: 'Automatic',
|
|
64
|
+
horsepower: '562hp',
|
|
65
|
+
torque: '408 lb-ft',
|
|
66
|
+
curbWeight: '3,594 lbs',
|
|
67
|
+
orderStatus: 'Order Fulfilled',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: generateUniqueId(),
|
|
71
|
+
brand: 'Lotus',
|
|
72
|
+
model: 'Emira',
|
|
73
|
+
year: '2023',
|
|
74
|
+
price: 'Starts at $78,000',
|
|
75
|
+
engine: 'Supercharged 3.5L V6',
|
|
76
|
+
transmission: 'Automatic or 6-Speed Manual',
|
|
77
|
+
horsepower: '400hp',
|
|
78
|
+
torque: '317 lb-ft',
|
|
79
|
+
curbWeight: '3520 lbs',
|
|
80
|
+
orderStatus: 'Shipped: In Transit',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: generateUniqueId(),
|
|
84
|
+
brand: 'Toyota',
|
|
85
|
+
model: 'Supra',
|
|
86
|
+
year: '1998',
|
|
87
|
+
price: '$40,000 - $80,000',
|
|
88
|
+
engine: '3.0L Inline 6',
|
|
89
|
+
transmission: 'Automatic or 6-Speed Manual',
|
|
90
|
+
horsepower: '320hp',
|
|
91
|
+
torque: '315 lb-ft',
|
|
92
|
+
curbWeight: '3,599 lbs',
|
|
93
|
+
orderStatus: 'Delivered',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: generateUniqueId(),
|
|
97
|
+
brand: 'Nissan',
|
|
98
|
+
model: 'Skyline GT-R',
|
|
99
|
+
year: '1994',
|
|
100
|
+
price: '$45,000 - $90,000',
|
|
101
|
+
engine: '2.6L Twin-Turbo Inline 6',
|
|
102
|
+
transmission: '5-Speed Manual',
|
|
103
|
+
horsepower: '276hp',
|
|
104
|
+
torque: '260 lb-ft',
|
|
105
|
+
curbWeight: '3,153 lbs',
|
|
106
|
+
orderStatus: 'Delivered',
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
interface RowProps {
|
|
111
|
+
data: AutoData;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const expandableSectionStyles = createStyles({
|
|
115
|
+
alignItems: 'flex-start',
|
|
116
|
+
display: 'flex',
|
|
117
|
+
gap: system.space.x4,
|
|
118
|
+
padding: system.space.x8,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const expandableHeadingStyles = createStyles({
|
|
122
|
+
margin: 0,
|
|
123
|
+
fontWeight: system.fontWeight.bold,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const expandableListStyles = createStyles({
|
|
127
|
+
listStyle: 'none',
|
|
128
|
+
margin: 0,
|
|
129
|
+
padding: 0,
|
|
130
|
+
gap: system.space.x2,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
function ExpandableRow({data}: RowProps) {
|
|
134
|
+
const [rowExpanded, setRowExpanded] = React.useState(false);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<>
|
|
138
|
+
<Table.Row gridTemplateColumns="4rem repeat(4, 1fr)">
|
|
139
|
+
<Table.Cell>
|
|
140
|
+
<Tooltip title={`${data.brand} ${data.model}`}>
|
|
141
|
+
<TertiaryButton
|
|
142
|
+
size="small"
|
|
143
|
+
icon={rowExpanded ? chevronDownSmallIcon : chevronRightSmallIcon}
|
|
144
|
+
aria-expanded={rowExpanded}
|
|
145
|
+
onClick={() => setRowExpanded(!rowExpanded)}
|
|
146
|
+
/>
|
|
147
|
+
</Tooltip>
|
|
148
|
+
</Table.Cell>
|
|
149
|
+
<Table.Header scope="row">{data.brand}</Table.Header>
|
|
150
|
+
<Table.Cell>{data.model}</Table.Cell>
|
|
151
|
+
<Table.Cell>{data.year}</Table.Cell>
|
|
152
|
+
<Table.Cell>{data.price}</Table.Cell>
|
|
153
|
+
</Table.Row>
|
|
154
|
+
{rowExpanded && (
|
|
155
|
+
<Table.Row>
|
|
156
|
+
<Table.Cell colSpan={5} cs={expandableSectionStyles}>
|
|
157
|
+
<div>
|
|
158
|
+
<Subtext as="h4" size="large" cs={expandableHeadingStyles}>
|
|
159
|
+
Status
|
|
160
|
+
</Subtext>
|
|
161
|
+
<StatusIndicator variant="blue">{data.orderStatus}</StatusIndicator>
|
|
162
|
+
</div>
|
|
163
|
+
<div>
|
|
164
|
+
<Subtext as="h4" size="large" cs={expandableHeadingStyles}>
|
|
165
|
+
Specifications
|
|
166
|
+
</Subtext>
|
|
167
|
+
<ul className={expandableListStyles}>
|
|
168
|
+
<Subtext as="li" size="large">
|
|
169
|
+
Engine: {data.engine}
|
|
170
|
+
</Subtext>
|
|
171
|
+
<Subtext as="li" size="large">
|
|
172
|
+
Transmission: {data.transmission}
|
|
173
|
+
</Subtext>
|
|
174
|
+
<Subtext as="li" size="large">
|
|
175
|
+
Horsepower: {data.horsepower}
|
|
176
|
+
</Subtext>
|
|
177
|
+
<Subtext as="li" size="large">
|
|
178
|
+
Torque: {data.torque}
|
|
179
|
+
</Subtext>
|
|
180
|
+
<Subtext as="li" size="large">
|
|
181
|
+
Curb Weight: {data.curbWeight}
|
|
182
|
+
</Subtext>
|
|
183
|
+
</ul>
|
|
184
|
+
</div>
|
|
185
|
+
</Table.Cell>
|
|
186
|
+
</Table.Row>
|
|
187
|
+
)}
|
|
188
|
+
</>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export default createComponent()({
|
|
193
|
+
displayName: 'ExpandableRows',
|
|
194
|
+
Component: () => {
|
|
195
|
+
return (
|
|
196
|
+
<>
|
|
197
|
+
<Heading as="h3" id={headingID} size="small">
|
|
198
|
+
Showroom Inventory
|
|
199
|
+
</Heading>
|
|
200
|
+
<Table aria-labelledby={headingID}>
|
|
201
|
+
<Table.Head>
|
|
202
|
+
<Table.Row gridTemplateColumns="4rem repeat(4, 1fr)">
|
|
203
|
+
<Table.Cell></Table.Cell>
|
|
204
|
+
<Table.Header scope="col">Make</Table.Header>
|
|
205
|
+
<Table.Header scope="col">Model</Table.Header>
|
|
206
|
+
<Table.Header scope="col">Year</Table.Header>
|
|
207
|
+
<Table.Header scope="col">Price</Table.Header>
|
|
208
|
+
</Table.Row>
|
|
209
|
+
</Table.Head>
|
|
210
|
+
<Table.Body>
|
|
211
|
+
{autoData.map(item => (
|
|
212
|
+
<ExpandableRow key={item.id} data={item} />
|
|
213
|
+
))}
|
|
214
|
+
</Table.Body>
|
|
215
|
+
</Table>
|
|
216
|
+
</>
|
|
217
|
+
);
|
|
218
|
+
},
|
|
219
|
+
});
|