@react-magma/charts 15.0.0-rc.5 → 16.0.0-next.1

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.
Files changed (38) hide show
  1. package/dist/charts.js +303 -224
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +304 -225
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +2701 -1592
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +25 -0
  8. package/package.json +3 -3
  9. package/src/components/CarbonChart/CarbonChart.test.js +490 -15
  10. package/src/components/CarbonChart/CarbonChart.tsx +479 -290
  11. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +1 -1
  12. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +1 -1
  13. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +1 -1
  14. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +1 -1
  15. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +1 -1
  16. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +1 -1
  17. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +1 -1
  18. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +1 -1
  19. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +1 -1
  20. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +3 -1
  21. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +1 -1
  22. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +1 -1
  23. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +1 -1
  24. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +1 -1
  25. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +1 -1
  26. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +1 -1
  27. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +1 -1
  28. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +1 -1
  29. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +1 -1
  30. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +1 -1
  31. package/src/components/CarbonChart/carbon-charts.css +89 -87
  32. package/src/components/ChartTable/ChartFullscreenButton.tsx +7 -1
  33. package/src/components/ChartTable/ChartMoreOptionsButton.tsx +3 -0
  34. package/src/components/ChartTable/ChartTable.stories.tsx +140 -1
  35. package/src/components/ChartTable/{ChartTable.test.tsx → ChartTable.test.js} +3 -1
  36. package/src/components/ChartTable/ChartTableButton.tsx +7 -1
  37. package/src/components/ChartTable/ChartTableModal.tsx +1 -1
  38. package/dist/components/ChartTable/ChartTable.test.d.ts +0 -1
@@ -61,6 +61,21 @@ export interface ChartToolbarConfig {
61
61
  * @default 2
62
62
  */
63
63
  titleLevel?: 1 | 2 | 3 | 4 | 5 | 6;
64
+ /**
65
+ * Custom content rendered before the chart title.
66
+ *
67
+ * The content is placed inline in the title row and follows the same
68
+ * accessibility rules as `titleSuffix`.
69
+ */
70
+ titlePrefix?: React.ReactNode;
71
+ /**
72
+ * Custom content rendered after the chart title and before toolbar actions.
73
+ *
74
+ * The content is placed inline in the title row and renders outside the
75
+ * heading element to preserve `options.title` as the heading's accessible name.
76
+ * Useful for patterns like Tooltip + IconButton.
77
+ */
78
+ titleSuffix?: React.ReactNode;
64
79
  }
65
80
  export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
66
81
  dataSet: Array<object>;
@@ -88,5 +103,15 @@ export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
88
103
  * toolbar is automatically disabled.
89
104
  */
90
105
  chartToolbar?: ChartToolbarConfig;
106
+ /**
107
+ * Custom content rendered below the toolbar row and above the chart itself,
108
+ * for example a filter. Requires `chartToolbar`; ignored without it.
109
+ *
110
+ * Providing this lays the toolbar out in normal flow instead of overlaying
111
+ * the single row Carbon reserves for its title, so the rendered height
112
+ * becomes toolbar + content + chart rather than the chart box alone. Set
113
+ * `options.height` so the chart still has a definite height of its own.
114
+ */
115
+ additionalContent?: React.ReactNode;
91
116
  }
92
117
  export declare const CarbonChart: React.ForwardRefExoticComponent<CarbonChartProps & React.RefAttributes<HTMLDivElement>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-magma/charts",
3
- "version": "15.0.0-rc.5",
3
+ "version": "16.0.0-next.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,7 +50,7 @@
50
50
  "identity-obj-proxy": "3.0.0",
51
51
  "react": "18.3.1",
52
52
  "react-dom": "18.3.1",
53
- "react-magma-dom": "^5.1.0-rc.4",
53
+ "react-magma-dom": "^7.0.0-next.1",
54
54
  "react-magma-icons": "^3.2.5",
55
55
  "rollup": "^4.52.4",
56
56
  "rollup-plugin-postcss": "^4.0.2"
@@ -60,7 +60,7 @@
60
60
  "@emotion/styled": "^11.14.0",
61
61
  "react": "^18.3.1",
62
62
  "react-dom": "^18.3.1",
63
- "react-magma-dom": "^5.1.0-rc.4",
63
+ "react-magma-dom": "^7.0.0-next.1",
64
64
  "react-magma-icons": "^3.2.5"
65
65
  },
66
66
  "engines": {
@@ -1,12 +1,15 @@
1
1
  import React from 'react';
2
2
 
3
+ import { SimpleBarChart } from '@carbon/charts-react';
3
4
  import { act, render, screen, fireEvent } from '@testing-library/react';
5
+ import { axe } from 'jest-axe';
4
6
  import {
5
7
  ThemeContext,
6
8
  magma,
7
9
  DropdownMenuItem,
8
10
  I18nContext,
9
11
  defaultI18n,
12
+ useIsInverse,
10
13
  } from 'react-magma-dom';
11
14
 
12
15
  import { CarbonChart, CarbonChartType } from '.';
@@ -96,7 +99,7 @@ describe('CarbonChart', () => {
96
99
  });
97
100
 
98
101
  describe('Magma Theme Values Applied to Styles', () => {
99
- it('should apply theme.colors.neutral700 to data table cells', () => {
102
+ it('should apply theme.colors.brand.navy to data table cells', () => {
100
103
  const testId = 'table-color-test';
101
104
  const { getByTestId } = render(
102
105
  <ThemeContext.Provider value={magma}>
@@ -111,12 +114,56 @@ describe('CarbonChart', () => {
111
114
 
112
115
  const wrapper = getByTestId(testId);
113
116
 
114
- // CarbonChartWrapper applies theme.colors.neutral700 to .cds--data-table td
115
- expect(wrapper).toHaveStyleRule('color', magma.colors.neutral700, {
117
+ expect(wrapper).toHaveStyleRule('color', magma.colors.brand.navy, {
116
118
  target: '.cds--data-table td',
117
119
  });
118
120
  });
119
121
 
122
+ it('should apply theme.colors.brand.navy to chart text', () => {
123
+ const testId = 'chart-text-color-test';
124
+ const { getByTestId } = render(
125
+ <ThemeContext.Provider value={magma}>
126
+ <CarbonChart
127
+ testId={testId}
128
+ dataSet={dataSet}
129
+ options={chartOptions}
130
+ type={CarbonChartType.bar}
131
+ />
132
+ </ThemeContext.Provider>
133
+ );
134
+
135
+ const wrapper = getByTestId(testId);
136
+
137
+ expect(wrapper).toHaveStyleRule('color', magma.colors.brand.navy, {
138
+ target: 'p',
139
+ });
140
+ expect(wrapper).toHaveStyleRule(
141
+ 'fill',
142
+ `${magma.colors.brand.navy}!important`,
143
+ { target: '.chart-holder text' }
144
+ );
145
+ });
146
+
147
+ it('should apply theme.colors.brand.navy to the chart title', () => {
148
+ const testId = 'title-color-test';
149
+ const { getByTestId } = render(
150
+ <ThemeContext.Provider value={magma}>
151
+ <CarbonChart
152
+ testId={testId}
153
+ dataSet={dataSet}
154
+ options={chartOptions}
155
+ type={CarbonChartType.bar}
156
+ />
157
+ </ThemeContext.Provider>
158
+ );
159
+
160
+ expect(getByTestId(testId)).toHaveStyleRule(
161
+ 'color',
162
+ `${magma.colors.brand.navy}!important`,
163
+ { target: '.cds--cc--title p.title' }
164
+ );
165
+ });
166
+
120
167
  it('should apply theme.colors.primary for button background in non-inverse mode', () => {
121
168
  const testId = 'button-color-test';
122
169
  const { getByTestId } = render(
@@ -139,7 +186,7 @@ describe('CarbonChart', () => {
139
186
  });
140
187
  });
141
188
 
142
- it('should apply theme.colors.tertiary500 for button background when isInverse is true', () => {
189
+ it('should apply theme.colors.cyan500 for button background when isInverse is true', () => {
143
190
  const testId = 'button-inverse-test';
144
191
  const { getByTestId } = render(
145
192
  <ThemeContext.Provider value={magma}>
@@ -155,13 +202,13 @@ describe('CarbonChart', () => {
155
202
 
156
203
  const wrapper = getByTestId(testId);
157
204
 
158
- // CarbonChartWrapper applies theme.colors.tertiary500 to .cds--btn--primary when inverse
159
- expect(wrapper).toHaveStyleRule('background', magma.colors.tertiary500, {
205
+ // CarbonChartWrapper applies theme.colors.cyan500 to .cds--btn--primary when inverse
206
+ expect(wrapper).toHaveStyleRule('background', magma.colors.cyan500, {
160
207
  target: '.chart-holder .cds--btn--primary',
161
208
  });
162
209
  });
163
210
 
164
- it('should apply theme.colors.primary700 for inverse table header background', () => {
211
+ it('should apply theme.colors.indigo700 for inverse table header background', () => {
165
212
  const testId = 'table-inverse-test';
166
213
  const { getByTestId } = render(
167
214
  <ThemeContext.Provider value={magma}>
@@ -177,16 +224,37 @@ describe('CarbonChart', () => {
177
224
 
178
225
  const wrapper = getByTestId(testId);
179
226
 
180
- // CarbonChartWrapper applies theme.colors.primary700 to table header when inverse
227
+ // CarbonChartWrapper applies theme.colors.indigo700 to table header when inverse
181
228
  expect(wrapper).toHaveStyleRule(
182
229
  'background',
183
- `${magma.colors.primary700}!important`,
230
+ `${magma.colors.indigo700}!important`,
184
231
  {
185
232
  target: '.cds--data-table thead tr th',
186
233
  }
187
234
  );
188
235
  });
189
236
 
237
+ it("pins Carbon's export `.filled` background to the inverse surface color", () => {
238
+ const testId = 'filled-bg-inverse';
239
+ const { getByTestId } = render(
240
+ <ThemeContext.Provider value={magma}>
241
+ <CarbonChart
242
+ testId={testId}
243
+ dataSet={dataSet}
244
+ options={chartOptions}
245
+ type={CarbonChartType.bar}
246
+ isInverse
247
+ />
248
+ </ThemeContext.Provider>
249
+ );
250
+
251
+ expect(getByTestId(testId)).toHaveStyleRule(
252
+ 'background-color',
253
+ magma.colors.indigo600,
254
+ { target: '.cds--chart-holder.filled' }
255
+ );
256
+ });
257
+
190
258
  it('should apply theme.colors.neutral100 for inverse text color', () => {
191
259
  const testId = 'text-inverse-test';
192
260
  const { getByTestId } = render(
@@ -452,7 +520,7 @@ describe('CarbonChart', () => {
452
520
  });
453
521
  });
454
522
 
455
- it('should apply theme.colors.primary600 to modal header background when isInverse', () => {
523
+ it('should apply theme.colors.indigo600 to modal header background when isInverse', () => {
456
524
  const testId = 'modal-header-inverse-test';
457
525
  const { getByTestId } = render(
458
526
  <ThemeContext.Provider value={magma}>
@@ -468,8 +536,8 @@ describe('CarbonChart', () => {
468
536
 
469
537
  const wrapper = getByTestId(testId);
470
538
 
471
- // CarbonChartWrapper applies theme.colors.primary600 to modal header when inverse
472
- expect(wrapper).toHaveStyleRule('background', magma.colors.primary600, {
539
+ // CarbonChartWrapper applies theme.colors.indigo600 to modal header when inverse
540
+ expect(wrapper).toHaveStyleRule('background', magma.colors.indigo600, {
473
541
  target: '.chart-holder .cds--modal-header',
474
542
  });
475
543
  });
@@ -521,7 +589,7 @@ describe('CarbonChart', () => {
521
589
  );
522
590
  });
523
591
 
524
- it('should apply theme.colors.primary600 to modal footer background when isInverse', () => {
592
+ it('should apply theme.colors.indigo600 to modal footer background when isInverse', () => {
525
593
  const testId = 'modal-footer-inverse-test';
526
594
  const { getByTestId } = render(
527
595
  <ThemeContext.Provider value={magma}>
@@ -537,10 +605,10 @@ describe('CarbonChart', () => {
537
605
 
538
606
  const wrapper = getByTestId(testId);
539
607
 
540
- // CarbonChartWrapper applies theme.colors.primary600 to modal footer when inverse
608
+ // CarbonChartWrapper applies theme.colors.indigo600 to modal footer when inverse
541
609
  expect(wrapper).toHaveStyleRule(
542
610
  'background',
543
- `${magma.colors.primary600}!important`,
611
+ `${magma.colors.indigo600}!important`,
544
612
  {
545
613
  target: '.cds--modal-footer.cds--modal-footer',
546
614
  }
@@ -928,6 +996,268 @@ describe('CarbonChart', () => {
928
996
  });
929
997
  });
930
998
 
999
+ describe('image export', () => {
1000
+ const toolbarProps = {
1001
+ dataSet,
1002
+ options: chartOptions,
1003
+ type: CarbonChartType.bar,
1004
+ chartToolbar: {},
1005
+ };
1006
+
1007
+ let exportToPNG;
1008
+ let exportToJPG;
1009
+ let createChartSpy;
1010
+
1011
+ beforeEach(() => {
1012
+ exportToPNG = jest.fn();
1013
+ exportToJPG = jest.fn();
1014
+ createChartSpy = jest
1015
+ .spyOn(SimpleBarChart.prototype, 'createChart')
1016
+ .mockImplementation(() => ({
1017
+ services: { domUtils: { exportToPNG, exportToJPG } },
1018
+ }));
1019
+ });
1020
+
1021
+ afterEach(() => {
1022
+ createChartSpy.mockRestore();
1023
+ });
1024
+
1025
+ it("runs Carbon's own PNG export from the More options menu", () => {
1026
+ render(<CarbonChart {...toolbarProps} />);
1027
+
1028
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1029
+ fireEvent.click(screen.getByText('Download as PNG'));
1030
+
1031
+ expect(exportToPNG).toHaveBeenCalledTimes(1);
1032
+ expect(exportToJPG).not.toHaveBeenCalled();
1033
+ });
1034
+
1035
+ it("runs Carbon's own JPG export from the More options menu", () => {
1036
+ render(<CarbonChart {...toolbarProps} />);
1037
+
1038
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1039
+ fireEvent.click(screen.getByText('Download as JPG'));
1040
+
1041
+ expect(exportToJPG).toHaveBeenCalledTimes(1);
1042
+ expect(exportToPNG).not.toHaveBeenCalled();
1043
+ });
1044
+
1045
+ it("keeps Carbon's own title alive and uses it as the export file name", () => {
1046
+ render(<CarbonChart {...toolbarProps} />);
1047
+
1048
+ const options = createChartSpy.mock.calls[0][2];
1049
+ expect(options.title).toBe(chartOptions.title);
1050
+ expect(options.fileDownload.fileName).toBe(chartOptions.title);
1051
+ });
1052
+
1053
+ it("reveals Carbon's hidden title for the capture and restores it afterwards", () => {
1054
+ jest.useFakeTimers();
1055
+ try {
1056
+ const { container } = render(<CarbonChart {...toolbarProps} />);
1057
+ const wrapper = container.querySelector('.carbon-chart-wrapper');
1058
+
1059
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1060
+
1061
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1062
+ fireEvent.click(screen.getByText('Download as PNG'));
1063
+
1064
+ expect(wrapper).not.toHaveClass('has-magma-toolbar');
1065
+
1066
+ jest.runOnlyPendingTimers();
1067
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1068
+ } finally {
1069
+ jest.useRealTimers();
1070
+ }
1071
+ });
1072
+
1073
+ it('reveals the title for the flow layout (additionalContent) export too', () => {
1074
+ jest.useFakeTimers();
1075
+ try {
1076
+ const { container } = render(
1077
+ <CarbonChart
1078
+ {...toolbarProps}
1079
+ additionalContent={<div>Filter</div>}
1080
+ />
1081
+ );
1082
+ const wrapper = container.querySelector('.carbon-chart-wrapper');
1083
+
1084
+ expect(createChartSpy.mock.calls[0][2].title).toBe(chartOptions.title);
1085
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1086
+
1087
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1088
+ fireEvent.click(screen.getByText('Download as JPG'));
1089
+
1090
+ expect(exportToJPG).toHaveBeenCalledTimes(1);
1091
+ expect(wrapper).not.toHaveClass('has-magma-toolbar');
1092
+
1093
+ jest.runOnlyPendingTimers();
1094
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1095
+ } finally {
1096
+ jest.useRealTimers();
1097
+ }
1098
+ });
1099
+ });
1100
+
1101
+ describe('custom content slots', () => {
1102
+ const toolbarProps = {
1103
+ dataSet,
1104
+ options: chartOptions,
1105
+ type: CarbonChartType.bar,
1106
+ chartToolbar: {},
1107
+ };
1108
+
1109
+ it('should render titlePrefix and titleSuffix around the title', () => {
1110
+ render(
1111
+ <CarbonChart
1112
+ {...toolbarProps}
1113
+ chartToolbar={{
1114
+ titlePrefix: <span data-testid="before">Badge</span>,
1115
+ titleSuffix: <button type="button">About this chart</button>,
1116
+ }}
1117
+ />
1118
+ );
1119
+
1120
+ const before = screen.getByTestId('before');
1121
+ const heading = screen.getByRole('heading', {
1122
+ level: 2,
1123
+ name: chartOptions.title,
1124
+ });
1125
+ const after = screen.getByRole('button', { name: 'About this chart' });
1126
+
1127
+ expect(
1128
+ before.compareDocumentPosition(heading) &
1129
+ Node.DOCUMENT_POSITION_FOLLOWING
1130
+ ).toBeTruthy();
1131
+ expect(
1132
+ heading.compareDocumentPosition(after) &
1133
+ Node.DOCUMENT_POSITION_FOLLOWING
1134
+ ).toBeTruthy();
1135
+ });
1136
+
1137
+ it('should place title slots before the toolbar actions in focus order', () => {
1138
+ render(
1139
+ <CarbonChart
1140
+ {...toolbarProps}
1141
+ chartToolbar={{
1142
+ titleSuffix: <button type="button">About this chart</button>,
1143
+ }}
1144
+ />
1145
+ );
1146
+
1147
+ const after = screen.getByRole('button', { name: 'About this chart' });
1148
+ const tableButton = screen.getByRole('button', {
1149
+ name: chartOptions.title,
1150
+ });
1151
+
1152
+ expect(
1153
+ after.compareDocumentPosition(tableButton) &
1154
+ Node.DOCUMENT_POSITION_FOLLOWING
1155
+ ).toBeTruthy();
1156
+ });
1157
+
1158
+ it('should keep the title as the accessible name when titleSuffix is used', () => {
1159
+ render(
1160
+ <CarbonChart
1161
+ {...toolbarProps}
1162
+ chartToolbar={{
1163
+ titleSuffix: <button type="button">About this chart</button>,
1164
+ }}
1165
+ />
1166
+ );
1167
+
1168
+ // The heading, the chart region and the table modal must all stay
1169
+ // anchored to options.title, which is also the exported file name.
1170
+ expect(
1171
+ screen.getByRole('heading', { level: 2, name: chartOptions.title })
1172
+ ).toBeInTheDocument();
1173
+ expect(
1174
+ screen.getByRole('region', { name: chartOptions.title })
1175
+ ).toBeInTheDocument();
1176
+
1177
+ fireEvent.click(screen.getByRole('button', { name: chartOptions.title }));
1178
+
1179
+ expect(
1180
+ screen.getByRole('heading', {
1181
+ level: 2,
1182
+ name: `Tabular representation ${chartOptions.title}`,
1183
+ })
1184
+ ).toBeInTheDocument();
1185
+ });
1186
+
1187
+ it('should render no slot markup by default', () => {
1188
+ render(<CarbonChart {...toolbarProps} />);
1189
+
1190
+ expect(screen.queryByTestId('before')).not.toBeInTheDocument();
1191
+ expect(
1192
+ screen.getByRole('heading', { level: 2, name: chartOptions.title })
1193
+ ).toBeInTheDocument();
1194
+ });
1195
+
1196
+ it('should expose the resolved inverse value to slot content', () => {
1197
+ // Slot content is the adopter's, so it reads isInverse from context
1198
+ // rather than from our prop.
1199
+ function InverseProbe() {
1200
+ return <span>{useIsInverse() ? 'inverse' : 'default'}</span>;
1201
+ }
1202
+
1203
+ render(
1204
+ <CarbonChart
1205
+ {...toolbarProps}
1206
+ isInverse
1207
+ chartToolbar={{
1208
+ titlePrefix: <InverseProbe />,
1209
+ titleSuffix: <InverseProbe />,
1210
+ }}
1211
+ />
1212
+ );
1213
+
1214
+ expect(screen.getAllByText('inverse')).toHaveLength(2);
1215
+ });
1216
+
1217
+ it('should not introduce accessibility violations with both slots', async () => {
1218
+ const { container } = render(
1219
+ <CarbonChart
1220
+ {...toolbarProps}
1221
+ chartToolbar={{
1222
+ titlePrefix: <span>Badge</span>,
1223
+ titleSuffix: <button type="button">About this chart</button>,
1224
+ }}
1225
+ />
1226
+ );
1227
+
1228
+ // aria-prohibited-attr and aria-tooltip-name come from Carbon's own SVG
1229
+ // output and are present on a chart with no slots at all, so they are
1230
+ // excluded here rather than being attributed to the slots.
1231
+ const results = await axe(container, {
1232
+ rules: {
1233
+ 'aria-prohibited-attr': { enabled: false },
1234
+ 'aria-tooltip-name': { enabled: false },
1235
+ },
1236
+ });
1237
+
1238
+ expect(results).toHaveNoViolations();
1239
+ });
1240
+
1241
+ it('keeps a single semantic heading and no a11y violations in the flow layout', async () => {
1242
+ const { container } = render(
1243
+ <CarbonChart {...toolbarProps} additionalContent={<div>Filter</div>} />
1244
+ );
1245
+
1246
+ expect(
1247
+ screen.getAllByRole('heading', { name: chartOptions.title })
1248
+ ).toHaveLength(1);
1249
+
1250
+ const results = await axe(container, {
1251
+ rules: {
1252
+ 'aria-prohibited-attr': { enabled: false },
1253
+ 'aria-tooltip-name': { enabled: false },
1254
+ },
1255
+ });
1256
+
1257
+ expect(results).toHaveNoViolations();
1258
+ });
1259
+ });
1260
+
931
1261
  describe('Legend accessibility wrap', () => {
932
1262
  const testId = 'legend-a11y';
933
1263
 
@@ -1122,4 +1452,149 @@ describe('CarbonChart', () => {
1122
1452
  );
1123
1453
  });
1124
1454
  });
1455
+
1456
+ describe('dot keyboard accessibility', () => {
1457
+ let rafCallbacks;
1458
+
1459
+ beforeEach(() => {
1460
+ rafCallbacks = [];
1461
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1462
+ rafCallbacks.push(cb);
1463
+ return rafCallbacks.length - 1;
1464
+ });
1465
+ });
1466
+
1467
+ afterEach(() => {
1468
+ window.requestAnimationFrame.mockRestore();
1469
+ rafCallbacks = [];
1470
+ });
1471
+
1472
+ function renderChart() {
1473
+ const { getByTestId } = render(
1474
+ <CarbonChart
1475
+ testId="dot-tab-test"
1476
+ dataSet={dataSet}
1477
+ options={chartOptions}
1478
+ type={CarbonChartType.scatter}
1479
+ />
1480
+ );
1481
+ return getByTestId('dot-tab-test');
1482
+ }
1483
+
1484
+ function addDot(wrapper) {
1485
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1486
+ const dot = document.createElementNS(
1487
+ 'http://www.w3.org/2000/svg',
1488
+ 'circle'
1489
+ );
1490
+ dot.classList.add('dot');
1491
+ svg.appendChild(dot);
1492
+ wrapper.appendChild(svg);
1493
+ return dot;
1494
+ }
1495
+
1496
+ describe('tabbing', () => {
1497
+ it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1498
+ const wrapper = renderChart();
1499
+ const dot = addDot(wrapper);
1500
+
1501
+ // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1502
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1503
+
1504
+ expect(dot).toHaveAttribute('tabindex', '0');
1505
+ });
1506
+
1507
+ it('should not overwrite an existing tabindex on circle.dot', () => {
1508
+ const wrapper = renderChart();
1509
+ const dot = addDot(wrapper);
1510
+ dot.setAttribute('tabindex', '-1');
1511
+
1512
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1513
+
1514
+ expect(dot).toHaveAttribute('tabindex', '-1');
1515
+ });
1516
+ });
1517
+
1518
+ describe('focus on dot content', () => {
1519
+ it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1520
+ const wrapper = renderChart();
1521
+ const dot = addDot(wrapper);
1522
+
1523
+ const mouseoverSpy = jest.fn();
1524
+ dot.addEventListener('mouseover', mouseoverSpy);
1525
+
1526
+ fireEvent.focusIn(dot);
1527
+
1528
+ expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1529
+ });
1530
+
1531
+ it('should dispatch mousemove on dot focusin', () => {
1532
+ const wrapper = renderChart();
1533
+ const dot = addDot(wrapper);
1534
+
1535
+ const mousemoveSpy = jest.fn();
1536
+ dot.addEventListener('mousemove', mousemoveSpy);
1537
+
1538
+ fireEvent.focusIn(dot);
1539
+
1540
+ expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1541
+ });
1542
+
1543
+ it('should not change opacity for non-dot circle elements on focusin', () => {
1544
+ const wrapper = renderChart();
1545
+ const nonDot = document.createElementNS(
1546
+ 'http://www.w3.org/2000/svg',
1547
+ 'circle'
1548
+ );
1549
+ wrapper.appendChild(nonDot);
1550
+
1551
+ fireEvent.focusIn(nonDot);
1552
+
1553
+ expect(nonDot.style.opacity).toBe('');
1554
+ });
1555
+ });
1556
+
1557
+ describe('data visibility', () => {
1558
+ it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1559
+ const wrapper = renderChart();
1560
+ const dot = addDot(wrapper);
1561
+
1562
+ const mouseoutSpy = jest.fn();
1563
+ dot.addEventListener('mouseout', mouseoutSpy);
1564
+
1565
+ fireEvent.focusIn(dot);
1566
+ fireEvent.focusOut(dot);
1567
+
1568
+ expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1569
+ });
1570
+
1571
+ it('should not dispatch mouseout when focus moves from one dot to another', () => {
1572
+ const wrapper = renderChart();
1573
+ const firstDot = addDot(wrapper);
1574
+ const secondDot = addDot(wrapper);
1575
+
1576
+ const mouseoutSpy = jest.fn();
1577
+ firstDot.addEventListener('mouseout', mouseoutSpy);
1578
+
1579
+ fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
1580
+
1581
+ expect(mouseoutSpy).not.toHaveBeenCalled();
1582
+ });
1583
+ });
1584
+
1585
+ describe('dynamic dot rendering', () => {
1586
+ it('should stamp tabindex="0" on dots added after initial raf pass', () => {
1587
+ const wrapper = renderChart();
1588
+
1589
+ // Run initial pass before adding a dot so the observer must handle it.
1590
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1591
+
1592
+ const lateDot = addDot(wrapper);
1593
+
1594
+ act(() => mutationObserverCallback([]));
1595
+
1596
+ expect(lateDot).toHaveAttribute('tabindex', '0');
1597
+ });
1598
+ });
1599
+ });
1125
1600
  });