@atlaskit/table 0.2.2 → 0.2.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/table
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8fb961ffa76`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8fb961ffa76) - [ux] Fixed some accessibility bugs. Now checkboxes in selectable cells are labelled for assistive technology users, sortable columns have their sorting state programmatically associated through the `aria-sort` attribute, and the sort button has an `aria-roledescription` to ensure that assistive technology users are informed that the column headers are sortable in nature.
8
+
3
9
  ## 0.2.2
4
10
 
5
11
  ### Patch Changes
@@ -10,6 +10,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
10
10
  var _react = require("react");
11
11
  var _react2 = require("@emotion/react");
12
12
  var _checkbox = _interopRequireDefault(require("@atlaskit/checkbox"));
13
+ var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
13
14
  var _selectionProvider = require("./hooks/selection-provider");
14
15
  var _useRowId = require("./hooks/use-row-id");
15
16
  var Primitives = _interopRequireWildcard(require("./ui"));
@@ -35,7 +36,8 @@ var SelectableCell = function SelectableCell() {
35
36
  as: "td"
36
37
  }, (0, _react2.jsx)(_checkbox.default, {
37
38
  isChecked: isChecked,
38
- onChange: onChange
39
+ onChange: onChange,
40
+ label: (0, _react2.jsx)(_visuallyHidden.default, null, "Select row ", idx + 1)
39
41
  }));
40
42
  };
41
43
  var _default = /*#__PURE__*/(0, _react.memo)(SelectableCell);
@@ -66,26 +66,29 @@ var SortableColumn = function SortableColumn(_ref) {
66
66
  function () {
67
67
  return setSortState(name);
68
68
  }, [setSortState, name]);
69
- return (
69
+ return (0, _react2.jsx)(_ui.TH, (0, _extends2.default)({
70
+ testId: testId,
71
+ sortDirection: sortKey === name ? sortDirection : 'none'
70
72
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
71
- (0, _react2.jsx)(_ui.TH, (0, _extends2.default)({
72
- testId: testId
73
- }, other), (0, _react2.jsx)(_tooltip.default, {
74
- content: getSortMessage(),
75
- position: "top"
76
- }, function (tooltipProps) {
77
- return (0, _react2.jsx)(_button.default, (0, _extends2.default)({
78
- spacing: "compact",
79
- appearance: "subtle",
80
- iconAfter: (0, _react2.jsx)(_ui.SortIcon, {
81
- name: name
82
- })
83
- }, tooltipProps, {
84
- onClick: updateSortState,
85
- css: overrideStyles
86
- }), children);
87
- }))
88
- );
73
+ }, other), (0, _react2.jsx)(_tooltip.default, {
74
+ content: getSortMessage(),
75
+ position: "top"
76
+ }, function (tooltipProps) {
77
+ return (0, _react2.jsx)(_button.default, (0, _extends2.default)({
78
+ testId: "".concat(testId, "--button"),
79
+ spacing: "compact",
80
+ appearance: "subtle",
81
+ iconAfter: (0, _react2.jsx)(_ui.SortIcon, {
82
+ name: name
83
+ })
84
+ }, tooltipProps, {
85
+ onClick: updateSortState,
86
+ css: overrideStyles
87
+ // TODO: i18n support for this attr
88
+ ,
89
+ "aria-roledescription": "Column sort button"
90
+ }), children);
91
+ }));
89
92
  };
90
93
  var _default = SortableColumn;
91
94
  exports.default = _default;
package/dist/cjs/thead.js CHANGED
@@ -40,13 +40,13 @@ var THead = function THead(_ref) {
40
40
  }, (0, _react.jsx)(Primitives.SelectableCell, {
41
41
  as: "th"
42
42
  }, (0, _react.jsx)(_checkbox.default, {
43
- "aria-labelledby": "select-all",
43
+ label: (0, _react.jsx)(_visuallyHidden.default, {
44
+ id: "select-all"
45
+ }, "Select all rows"),
44
46
  onChange: isChecked ? removeAll : setAll,
45
47
  isChecked: isChecked,
46
48
  isIndeterminate: state.anyChecked && !state.allChecked
47
- }), (0, _react.jsx)(_visuallyHidden.default, {
48
- id: "select-all"
49
- }, "Select all rows")), children, isChecked && (0, _react.jsx)(Primitives.BulkActionOverlay, null, (0, _react.jsx)(_dsExplorations.UNSAFE_Text, {
49
+ })), children, isChecked && (0, _react.jsx)(Primitives.BulkActionOverlay, null, (0, _react.jsx)(_dsExplorations.UNSAFE_Text, {
50
50
  color: "color.text",
51
51
  fontWeight: "medium"
52
52
  }, state.checked.length, " selected"), actions && (0, _react.jsx)(_dsExplorations.UNSAFE_Inline, {
@@ -48,7 +48,8 @@ var BaseCell = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
48
48
  backgroundColor = _ref.backgroundColor,
49
49
  scope = _ref.scope,
50
50
  width = _ref.width,
51
- className = _ref.className;
51
+ className = _ref.className,
52
+ sortDirection = _ref.sortDirection;
52
53
  return (0, _react2.jsx)(_box.default, {
53
54
  css: baseResetStyles,
54
55
  ref: ref,
@@ -61,7 +62,8 @@ var BaseCell = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
61
62
  className: className,
62
63
  UNSAFE_style: width ? {
63
64
  width: width
64
- } : undefined
65
+ } : undefined,
66
+ "aria-sort": sortDirection
65
67
  }, (0, _react2.jsx)(_inline.default, {
66
68
  justifyContent: alignMap[align],
67
69
  gap: "space.0"
package/dist/cjs/ui/th.js CHANGED
@@ -20,7 +20,8 @@ var TH = function TH(_ref) {
20
20
  align = _ref.align,
21
21
  scope = _ref.scope,
22
22
  backgroundColor = _ref.backgroundColor,
23
- width = _ref.width;
23
+ width = _ref.width,
24
+ sortDirection = _ref.sortDirection;
24
25
  return (
25
26
  /*#__PURE__*/
26
27
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
@@ -30,7 +31,8 @@ var TH = function TH(_ref) {
30
31
  align: align,
31
32
  scope: scope,
32
33
  width: width,
33
- backgroundColor: backgroundColor
34
+ backgroundColor: backgroundColor,
35
+ sortDirection: sortDirection
34
36
  }, children)
35
37
  );
36
38
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/table",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -2,6 +2,7 @@
2
2
  import { memo, useCallback, useMemo } from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import Checkbox from '@atlaskit/checkbox';
5
+ import VisuallyHidden from '@atlaskit/visually-hidden';
5
6
  import { useSelection } from './hooks/selection-provider';
6
7
  import { useRowId } from './hooks/use-row-id';
7
8
  import * as Primitives from './ui';
@@ -19,7 +20,8 @@ const SelectableCell = () => {
19
20
  as: "td"
20
21
  }, jsx(Checkbox, {
21
22
  isChecked: isChecked,
22
- onChange: onChange
23
+ onChange: onChange,
24
+ label: jsx(VisuallyHidden, null, "Select row ", idx + 1)
23
25
  }));
24
26
  };
25
27
  export default /*#__PURE__*/memo(SelectableCell);
@@ -59,23 +59,26 @@ const SortableColumn = ({
59
59
  const updateSortState = useCallback(
60
60
  // @ts-expect-error: TODO: Our `name` typing is off; refer to `SortKey`
61
61
  () => setSortState(name), [setSortState, name]);
62
- return (
62
+ return jsx(TH, _extends({
63
+ testId: testId,
64
+ sortDirection: sortKey === name ? sortDirection : 'none'
63
65
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
64
- jsx(TH, _extends({
65
- testId: testId
66
- }, other), jsx(Tooltip, {
67
- content: getSortMessage(),
68
- position: "top"
69
- }, tooltipProps => jsx(Button, _extends({
70
- spacing: "compact",
71
- appearance: "subtle",
72
- iconAfter: jsx(SortIcon, {
73
- name: name
74
- })
75
- }, tooltipProps, {
76
- onClick: updateSortState,
77
- css: overrideStyles
78
- }), children)))
79
- );
66
+ }, other), jsx(Tooltip, {
67
+ content: getSortMessage(),
68
+ position: "top"
69
+ }, tooltipProps => jsx(Button, _extends({
70
+ testId: `${testId}--button`,
71
+ spacing: "compact",
72
+ appearance: "subtle",
73
+ iconAfter: jsx(SortIcon, {
74
+ name: name
75
+ })
76
+ }, tooltipProps, {
77
+ onClick: updateSortState,
78
+ css: overrideStyles
79
+ // TODO: i18n support for this attr
80
+ ,
81
+ "aria-roledescription": "Column sort button"
82
+ }), children)));
80
83
  };
81
84
  export default SortableColumn;
@@ -29,13 +29,13 @@ const THead = ({
29
29
  }, jsx(Primitives.SelectableCell, {
30
30
  as: "th"
31
31
  }, jsx(Checkbox, {
32
- "aria-labelledby": "select-all",
32
+ label: jsx(VisuallyHidden, {
33
+ id: "select-all"
34
+ }, "Select all rows"),
33
35
  onChange: isChecked ? removeAll : setAll,
34
36
  isChecked: isChecked,
35
37
  isIndeterminate: state.anyChecked && !state.allChecked
36
- }), jsx(VisuallyHidden, {
37
- id: "select-all"
38
- }, "Select all rows")), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
38
+ })), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
39
39
  color: "color.text",
40
40
  fontWeight: "medium"
41
41
  }, state.checked.length, " selected"), actions && jsx(Inline, {
@@ -37,7 +37,8 @@ export const BaseCell = /*#__PURE__*/forwardRef(({
37
37
  backgroundColor,
38
38
  scope,
39
39
  width,
40
- className
40
+ className,
41
+ sortDirection
41
42
  }, ref) => jsx(Box, {
42
43
  css: baseResetStyles,
43
44
  ref: ref,
@@ -50,7 +51,8 @@ export const BaseCell = /*#__PURE__*/forwardRef(({
50
51
  className: className,
51
52
  UNSAFE_style: width ? {
52
53
  width
53
- } : undefined
54
+ } : undefined,
55
+ "aria-sort": sortDirection
54
56
  }, jsx(Inline, {
55
57
  justifyContent: alignMap[align],
56
58
  gap: "space.0"
@@ -13,7 +13,8 @@ export const TH = ({
13
13
  align,
14
14
  scope,
15
15
  backgroundColor,
16
- width
16
+ width,
17
+ sortDirection
17
18
  }) =>
18
19
  /*#__PURE__*/
19
20
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
@@ -23,5 +24,6 @@ React.createElement(BaseCell, {
23
24
  align: align,
24
25
  scope: scope,
25
26
  width: width,
26
- backgroundColor: backgroundColor
27
+ backgroundColor: backgroundColor,
28
+ sortDirection: sortDirection
27
29
  }, children);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/table",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -3,6 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import { memo, useCallback, useMemo } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
5
  import Checkbox from '@atlaskit/checkbox';
6
+ import VisuallyHidden from '@atlaskit/visually-hidden';
6
7
  import { useSelection } from './hooks/selection-provider';
7
8
  import { useRowId } from './hooks/use-row-id';
8
9
  import * as Primitives from './ui';
@@ -24,7 +25,8 @@ var SelectableCell = function SelectableCell() {
24
25
  as: "td"
25
26
  }, jsx(Checkbox, {
26
27
  isChecked: isChecked,
27
- onChange: onChange
28
+ onChange: onChange,
29
+ label: jsx(VisuallyHidden, null, "Select row ", idx + 1)
28
30
  }));
29
31
  };
30
32
  export default /*#__PURE__*/memo(SelectableCell);
@@ -61,25 +61,28 @@ var SortableColumn = function SortableColumn(_ref) {
61
61
  function () {
62
62
  return setSortState(name);
63
63
  }, [setSortState, name]);
64
- return (
64
+ return jsx(TH, _extends({
65
+ testId: testId,
66
+ sortDirection: sortKey === name ? sortDirection : 'none'
65
67
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
66
- jsx(TH, _extends({
67
- testId: testId
68
- }, other), jsx(Tooltip, {
69
- content: getSortMessage(),
70
- position: "top"
71
- }, function (tooltipProps) {
72
- return jsx(Button, _extends({
73
- spacing: "compact",
74
- appearance: "subtle",
75
- iconAfter: jsx(SortIcon, {
76
- name: name
77
- })
78
- }, tooltipProps, {
79
- onClick: updateSortState,
80
- css: overrideStyles
81
- }), children);
82
- }))
83
- );
68
+ }, other), jsx(Tooltip, {
69
+ content: getSortMessage(),
70
+ position: "top"
71
+ }, function (tooltipProps) {
72
+ return jsx(Button, _extends({
73
+ testId: "".concat(testId, "--button"),
74
+ spacing: "compact",
75
+ appearance: "subtle",
76
+ iconAfter: jsx(SortIcon, {
77
+ name: name
78
+ })
79
+ }, tooltipProps, {
80
+ onClick: updateSortState,
81
+ css: overrideStyles
82
+ // TODO: i18n support for this attr
83
+ ,
84
+ "aria-roledescription": "Column sort button"
85
+ }), children);
86
+ }));
84
87
  };
85
88
  export default SortableColumn;
package/dist/esm/thead.js CHANGED
@@ -30,13 +30,13 @@ var THead = function THead(_ref) {
30
30
  }, jsx(Primitives.SelectableCell, {
31
31
  as: "th"
32
32
  }, jsx(Checkbox, {
33
- "aria-labelledby": "select-all",
33
+ label: jsx(VisuallyHidden, {
34
+ id: "select-all"
35
+ }, "Select all rows"),
34
36
  onChange: isChecked ? removeAll : setAll,
35
37
  isChecked: isChecked,
36
38
  isIndeterminate: state.anyChecked && !state.allChecked
37
- }), jsx(VisuallyHidden, {
38
- id: "select-all"
39
- }, "Select all rows")), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
39
+ })), children, isChecked && jsx(Primitives.BulkActionOverlay, null, jsx(Text, {
40
40
  color: "color.text",
41
41
  fontWeight: "medium"
42
42
  }, state.checked.length, " selected"), actions && jsx(Inline, {
@@ -40,7 +40,8 @@ export var BaseCell = /*#__PURE__*/forwardRef(function (_ref, ref) {
40
40
  backgroundColor = _ref.backgroundColor,
41
41
  scope = _ref.scope,
42
42
  width = _ref.width,
43
- className = _ref.className;
43
+ className = _ref.className,
44
+ sortDirection = _ref.sortDirection;
44
45
  return jsx(Box, {
45
46
  css: baseResetStyles,
46
47
  ref: ref,
@@ -53,7 +54,8 @@ export var BaseCell = /*#__PURE__*/forwardRef(function (_ref, ref) {
53
54
  className: className,
54
55
  UNSAFE_style: width ? {
55
56
  width: width
56
- } : undefined
57
+ } : undefined,
58
+ "aria-sort": sortDirection
57
59
  }, jsx(Inline, {
58
60
  justifyContent: alignMap[align],
59
61
  gap: "space.0"
package/dist/esm/ui/th.js CHANGED
@@ -13,7 +13,8 @@ export var TH = function TH(_ref) {
13
13
  align = _ref.align,
14
14
  scope = _ref.scope,
15
15
  backgroundColor = _ref.backgroundColor,
16
- width = _ref.width;
16
+ width = _ref.width,
17
+ sortDirection = _ref.sortDirection;
17
18
  return (
18
19
  /*#__PURE__*/
19
20
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
@@ -23,7 +24,8 @@ export var TH = function TH(_ref) {
23
24
  align: align,
24
25
  scope: scope,
25
26
  width: width,
26
- backgroundColor: backgroundColor
27
+ backgroundColor: backgroundColor,
28
+ sortDirection: sortDirection
27
29
  }, children)
28
30
  );
29
31
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/table",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -30,6 +30,10 @@ export declare type BaseCellProps = {
30
30
  */
31
31
  children?: ReactNode;
32
32
  } & Pick<BoxProps, 'paddingBlock' | 'paddingInline' | 'backgroundColor' | 'className'>;
33
+ /**
34
+ * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-sort
35
+ */
36
+ export declare type SortDirection = 'ascending' | 'descending' | 'none' | 'other';
33
37
  declare const alignMap: {
34
38
  readonly text: "flexStart";
35
39
  readonly number: "flexEnd";
@@ -70,5 +74,7 @@ export declare const BaseCell: import("react").ForwardRefExoticComponent<{
70
74
  * Content of the cell.
71
75
  */
72
76
  children?: ReactNode;
73
- } & Pick<BoxProps<"div">, "className" | "backgroundColor" | "paddingBlock" | "paddingInline"> & import("react").RefAttributes<HTMLTableCellElement>>;
77
+ } & Pick<BoxProps<"div">, "className" | "backgroundColor" | "paddingBlock" | "paddingInline"> & {
78
+ sortDirection?: SortDirection | undefined;
79
+ } & import("react").RefAttributes<HTMLTableCellElement>>;
74
80
  export {};
@@ -1,6 +1,9 @@
1
1
  import { FC } from 'react';
2
- import { BaseCellProps } from './base-cell';
2
+ import { BaseCellProps, SortDirection } from './base-cell';
3
3
  export declare type THProps = Omit<BaseCellProps, 'as'>;
4
+ declare type InternalTHProps = THProps & {
5
+ sortDirection?: SortDirection;
6
+ };
4
7
  /**
5
8
  * __Head cell__
6
9
  *
@@ -8,4 +11,5 @@ export declare type THProps = Omit<BaseCellProps, 'as'>;
8
11
  *
9
12
  * @primitive
10
13
  */
11
- export declare const TH: FC<THProps>;
14
+ export declare const TH: FC<InternalTHProps>;
15
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/table",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "A table is used to display data.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,8 +38,8 @@
38
38
  "@atlaskit/ds-lib": "^2.1.2",
39
39
  "@atlaskit/focus-ring": "^1.2.1",
40
40
  "@atlaskit/icon": "^21.11.2",
41
- "@atlaskit/tokens": "^1.0.0",
42
- "@atlaskit/tooltip": "^17.5.16",
41
+ "@atlaskit/tokens": "^1.2.0",
42
+ "@atlaskit/tooltip": "^17.7.0",
43
43
  "@atlaskit/visually-hidden": "^1.0.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@emotion/react": "^11.7.1",
@@ -62,6 +62,7 @@
62
62
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
63
63
  "@testing-library/react": "^12.1.5",
64
64
  "@testing-library/react-hooks": "^8.0.1",
65
+ "jest-axe": "^4.0.0",
65
66
  "react-dom": "^16.8.0",
66
67
  "storybook-addon-designs": "^6.3.1",
67
68
  "typescript": "4.5.5",
@@ -81,15 +82,17 @@
81
82
  "analytics": [
82
83
  "analytics-next"
83
84
  ],
85
+ "design-tokens": [
86
+ "color",
87
+ "spacing"
88
+ ],
84
89
  "theming": [
85
- "react-context",
86
- "tokens"
90
+ "react-context"
87
91
  ],
88
92
  "ui-components": [
89
93
  "lite-mode"
90
94
  ],
91
95
  "design-system": "v1",
92
- "design-tokens": "spacing",
93
96
  "deprecation": [
94
97
  "no-deprecated-imports"
95
98
  ],
@@ -1,19 +0,0 @@
1
- ---
2
- order: 0
3
- ---
4
-
5
- import BasicAKTableExample from '../../examples/composed';
6
- import AKTableExample from '../../examples/basic';
7
-
8
- ## Basic
9
-
10
- A table is composed of simple composable elements. In its base form these UI elements are purely presentational.
11
-
12
- <Example Component={BasicAKTableExample} packageName="@atlaskit/table" />
13
-
14
- ## Basic data table
15
-
16
- A data table is used to display dynamic data.
17
-
18
- <Example Component={AKTableExample} packageName="@atlaskit/table" />
19
-
@@ -1,17 +0,0 @@
1
- import TableProps from '!!extract-react-types-loader!../../extract-react-types/table.tsx';
2
- import RowProps from '!!extract-react-types-loader!../../extract-react-types/row.tsx';
3
- import CellProps from '!!extract-react-types-loader!../../extract-react-types/cell.tsx';
4
-
5
- ## Props
6
-
7
- ### Table props
8
-
9
- <PropsTable heading="" props={TableProps} />
10
-
11
- ### Row props
12
-
13
- <PropsTable heading="Row props" props={RowProps} />
14
-
15
- ### Cell props
16
-
17
- <PropsTable heading="Cell props" props={CellProps} />