@react-magma/charts 16.0.0-next.0 → 16.0.0-v6-next.2

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 (89) hide show
  1. package/dist/charts.js +1632 -221
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +1634 -224
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +49747 -28263
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +1 -1
  8. package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +310 -0
  9. package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +136 -0
  10. package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +232 -0
  11. package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +82 -0
  12. package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +234 -0
  13. package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +266 -0
  14. package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +53 -0
  15. package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +196 -0
  16. package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +35 -0
  17. package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +580 -0
  18. package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +120 -0
  19. package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +43 -0
  20. package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +89 -0
  21. package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +577 -0
  22. package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +55 -0
  23. package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +127 -0
  24. package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +101 -0
  25. package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +98 -0
  26. package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +173 -0
  27. package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +51 -0
  28. package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +38 -0
  29. package/dist/components/ChartTable/ChartTable.stories.d.ts +166 -0
  30. package/dist/components/LineChart/Chart.d.ts +27 -0
  31. package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
  32. package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
  33. package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
  34. package/dist/components/LineChart/DataTable.d.ts +5 -0
  35. package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
  36. package/dist/components/LineChart/LegendButton.d.ts +6 -0
  37. package/dist/components/LineChart/LineChart.d.ts +67 -0
  38. package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
  39. package/dist/components/LineChart/index.d.ts +1 -0
  40. package/dist/components/LineChart/magma-charts.d.ts +1 -0
  41. package/dist/index.d.ts +1 -0
  42. package/package.json +21 -24
  43. package/src/components/CarbonChart/CarbonChart.test.js +316 -188
  44. package/src/components/CarbonChart/CarbonChart.tsx +94 -84
  45. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +5 -3
  46. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +5 -3
  47. package/src/components/CarbonChart/CarbonChartBar.stories.tsx +5 -3
  48. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +5 -3
  49. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +5 -3
  50. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +5 -3
  51. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +5 -3
  52. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +5 -3
  53. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +5 -3
  54. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +5 -3
  55. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +5 -3
  56. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +5 -3
  57. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +5 -3
  58. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +5 -3
  59. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +5 -3
  60. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +5 -3
  61. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +5 -3
  62. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +5 -3
  63. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +5 -3
  64. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +5 -3
  65. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +5 -3
  66. package/src/components/ChartTable/ChartDataTable.tsx +0 -3
  67. package/src/components/ChartTable/ChartFullscreenButton.tsx +7 -1
  68. package/src/components/ChartTable/ChartMoreOptionsButton.tsx +2 -1
  69. package/src/components/ChartTable/ChartTable.test.js +3 -9
  70. package/src/components/ChartTable/ChartTableButton.tsx +7 -2
  71. package/src/components/ChartTable/ChartTableModal.tsx +1 -1
  72. package/src/components/ChartTable/ChartToolbar.tsx +0 -1
  73. package/src/components/ChartTable/chartToolbarI18n.ts +1 -1
  74. package/src/components/LineChart/Chart.tsx +241 -0
  75. package/src/components/LineChart/ChartDataTable.test.js +165 -0
  76. package/src/components/LineChart/ChartDataTable.tsx +135 -0
  77. package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
  78. package/src/components/LineChart/CustomPointComponent.tsx +93 -0
  79. package/src/components/LineChart/DataTable.tsx +57 -0
  80. package/src/components/LineChart/GraphTooltip.tsx +100 -0
  81. package/src/components/LineChart/LegendButton.tsx +77 -0
  82. package/src/components/LineChart/LineChart.stories.tsx +399 -0
  83. package/src/components/LineChart/LineChart.test.js +501 -0
  84. package/src/components/LineChart/LineChart.tsx +669 -0
  85. package/src/components/LineChart/index.ts +1 -0
  86. package/src/components/LineChart/magma-charts.ts +279 -0
  87. package/src/components/LineChart/test/exampleChartData.js +289 -0
  88. package/src/hooks/useCarbonModalFocusManagement.ts +0 -12
  89. package/src/index.ts +1 -0
@@ -2,6 +2,7 @@ import React from 'react';
2
2
 
3
3
  import { SimpleBarChart } from '@carbon/charts-react';
4
4
  import { act, render, screen, fireEvent } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
5
6
  import { axe } from 'jest-axe';
6
7
  import {
7
8
  ThemeContext,
@@ -99,7 +100,7 @@ describe('CarbonChart', () => {
99
100
  });
100
101
 
101
102
  describe('Magma Theme Values Applied to Styles', () => {
102
- it('should apply theme.colors.neutral700 to data table cells', () => {
103
+ it('should apply theme.colors.brand.navy to data table cells', () => {
103
104
  const testId = 'table-color-test';
104
105
  const { getByTestId } = render(
105
106
  <ThemeContext.Provider value={magma}>
@@ -114,12 +115,56 @@ describe('CarbonChart', () => {
114
115
 
115
116
  const wrapper = getByTestId(testId);
116
117
 
117
- // CarbonChartWrapper applies theme.colors.neutral700 to .cds--data-table td
118
- expect(wrapper).toHaveStyleRule('color', magma.colors.neutral700, {
118
+ expect(wrapper).toHaveStyleRule('color', magma.colors.brand.navy, {
119
119
  target: '.cds--data-table td',
120
120
  });
121
121
  });
122
122
 
123
+ it('should apply theme.colors.brand.navy to chart text', () => {
124
+ const testId = 'chart-text-color-test';
125
+ const { getByTestId } = render(
126
+ <ThemeContext.Provider value={magma}>
127
+ <CarbonChart
128
+ testId={testId}
129
+ dataSet={dataSet}
130
+ options={chartOptions}
131
+ type={CarbonChartType.bar}
132
+ />
133
+ </ThemeContext.Provider>
134
+ );
135
+
136
+ const wrapper = getByTestId(testId);
137
+
138
+ expect(wrapper).toHaveStyleRule('color', magma.colors.brand.navy, {
139
+ target: 'p',
140
+ });
141
+ expect(wrapper).toHaveStyleRule(
142
+ 'fill',
143
+ `${magma.colors.brand.navy}!important`,
144
+ { target: '.chart-holder text' }
145
+ );
146
+ });
147
+
148
+ it('should apply theme.colors.brand.navy to the chart title', () => {
149
+ const testId = 'title-color-test';
150
+ const { getByTestId } = render(
151
+ <ThemeContext.Provider value={magma}>
152
+ <CarbonChart
153
+ testId={testId}
154
+ dataSet={dataSet}
155
+ options={chartOptions}
156
+ type={CarbonChartType.bar}
157
+ />
158
+ </ThemeContext.Provider>
159
+ );
160
+
161
+ expect(getByTestId(testId)).toHaveStyleRule(
162
+ 'color',
163
+ `${magma.colors.brand.navy}!important`,
164
+ { target: '.cds--cc--title p.title' }
165
+ );
166
+ });
167
+
123
168
  it('should apply theme.colors.primary for button background in non-inverse mode', () => {
124
169
  const testId = 'button-color-test';
125
170
  const { getByTestId } = render(
@@ -142,7 +187,7 @@ describe('CarbonChart', () => {
142
187
  });
143
188
  });
144
189
 
145
- it('should apply theme.colors.tertiary500 for button background when isInverse is true', () => {
190
+ it('should apply theme.colors.cyan500 for button background when isInverse is true', () => {
146
191
  const testId = 'button-inverse-test';
147
192
  const { getByTestId } = render(
148
193
  <ThemeContext.Provider value={magma}>
@@ -158,13 +203,13 @@ describe('CarbonChart', () => {
158
203
 
159
204
  const wrapper = getByTestId(testId);
160
205
 
161
- // CarbonChartWrapper applies theme.colors.tertiary500 to .cds--btn--primary when inverse
162
- expect(wrapper).toHaveStyleRule('background', magma.colors.tertiary500, {
206
+ // CarbonChartWrapper applies theme.colors.cyan500 to .cds--btn--primary when inverse
207
+ expect(wrapper).toHaveStyleRule('background', magma.colors.cyan500, {
163
208
  target: '.chart-holder .cds--btn--primary',
164
209
  });
165
210
  });
166
211
 
167
- it('should apply theme.colors.primary700 for inverse table header background', () => {
212
+ it('should apply theme.colors.indigo700 for inverse table header background', () => {
168
213
  const testId = 'table-inverse-test';
169
214
  const { getByTestId } = render(
170
215
  <ThemeContext.Provider value={magma}>
@@ -180,10 +225,10 @@ describe('CarbonChart', () => {
180
225
 
181
226
  const wrapper = getByTestId(testId);
182
227
 
183
- // CarbonChartWrapper applies theme.colors.primary700 to table header when inverse
228
+ // CarbonChartWrapper applies theme.colors.indigo700 to table header when inverse
184
229
  expect(wrapper).toHaveStyleRule(
185
230
  'background',
186
- `${magma.colors.primary700}!important`,
231
+ `${magma.colors.indigo700}!important`,
187
232
  {
188
233
  target: '.cds--data-table thead tr th',
189
234
  }
@@ -206,7 +251,7 @@ describe('CarbonChart', () => {
206
251
 
207
252
  expect(getByTestId(testId)).toHaveStyleRule(
208
253
  'background-color',
209
- magma.colors.primary600,
254
+ magma.colors.indigo600,
210
255
  { target: '.cds--chart-holder.filled' }
211
256
  );
212
257
  });
@@ -476,7 +521,7 @@ describe('CarbonChart', () => {
476
521
  });
477
522
  });
478
523
 
479
- it('should apply theme.colors.primary600 to modal header background when isInverse', () => {
524
+ it('should apply theme.colors.indigo600 to modal header background when isInverse', () => {
480
525
  const testId = 'modal-header-inverse-test';
481
526
  const { getByTestId } = render(
482
527
  <ThemeContext.Provider value={magma}>
@@ -492,8 +537,8 @@ describe('CarbonChart', () => {
492
537
 
493
538
  const wrapper = getByTestId(testId);
494
539
 
495
- // CarbonChartWrapper applies theme.colors.primary600 to modal header when inverse
496
- expect(wrapper).toHaveStyleRule('background', magma.colors.primary600, {
540
+ // CarbonChartWrapper applies theme.colors.indigo600 to modal header when inverse
541
+ expect(wrapper).toHaveStyleRule('background', magma.colors.indigo600, {
497
542
  target: '.chart-holder .cds--modal-header',
498
543
  });
499
544
  });
@@ -545,7 +590,7 @@ describe('CarbonChart', () => {
545
590
  );
546
591
  });
547
592
 
548
- it('should apply theme.colors.primary600 to modal footer background when isInverse', () => {
593
+ it('should apply theme.colors.indigo600 to modal footer background when isInverse', () => {
549
594
  const testId = 'modal-footer-inverse-test';
550
595
  const { getByTestId } = render(
551
596
  <ThemeContext.Provider value={magma}>
@@ -561,10 +606,10 @@ describe('CarbonChart', () => {
561
606
 
562
607
  const wrapper = getByTestId(testId);
563
608
 
564
- // CarbonChartWrapper applies theme.colors.primary600 to modal footer when inverse
609
+ // CarbonChartWrapper applies theme.colors.indigo600 to modal footer when inverse
565
610
  expect(wrapper).toHaveStyleRule(
566
611
  'background',
567
- `${magma.colors.primary600}!important`,
612
+ `${magma.colors.indigo600}!important`,
568
613
  {
569
614
  target: '.cds--modal-footer.cds--modal-footer',
570
615
  }
@@ -622,6 +667,32 @@ describe('CarbonChart', () => {
622
667
  }
623
668
  );
624
669
  });
670
+
671
+ it('should move focus back after closing the More options dropdown and chart toolbar', () => {
672
+ const testId = 'modal-footer-border-test';
673
+ const { getByTestId, getByText } = render(
674
+ <ThemeContext.Provider value={magma}>
675
+ <CarbonChart
676
+ testId={testId}
677
+ dataSet={dataSet}
678
+ options={chartOptions}
679
+ type={CarbonChartType.bar}
680
+ isInverse={false}
681
+ chartToolbar={{}}
682
+ />
683
+ </ThemeContext.Provider>
684
+ );
685
+
686
+ const moreOptionsButton = getByTestId('chart-more-options-button');
687
+ userEvent.click(moreOptionsButton);
688
+
689
+ expect(getByText('Download as CSV')).toBeVisible();
690
+ expect(getByText('Download as PNG')).toBeVisible();
691
+ expect(getByText('Download as JPG')).toBeVisible();
692
+
693
+ userEvent.keyboard('{esc}');
694
+ expect(moreOptionsButton).toHaveFocus();
695
+ });
625
696
  });
626
697
 
627
698
  describe('Modal Focus Management', () => {
@@ -952,6 +1023,77 @@ describe('CarbonChart', () => {
952
1023
  });
953
1024
  });
954
1025
 
1026
+ describe('fullscreen', () => {
1027
+ const toolbarProps = {
1028
+ dataSet,
1029
+ options: chartOptions,
1030
+ type: CarbonChartType.bar,
1031
+ chartToolbar: {},
1032
+ };
1033
+
1034
+ let setOptions;
1035
+ let createChartSpy;
1036
+
1037
+ const setFullscreenElement = element => {
1038
+ Object.defineProperty(document, 'fullscreenElement', {
1039
+ configurable: true,
1040
+ value: element,
1041
+ });
1042
+ act(() => {
1043
+ document.dispatchEvent(new Event('fullscreenchange'));
1044
+ });
1045
+ };
1046
+
1047
+ beforeEach(() => {
1048
+ setOptions = jest.fn();
1049
+ createChartSpy = jest
1050
+ .spyOn(SimpleBarChart.prototype, 'createChart')
1051
+ .mockImplementation(holder => {
1052
+ holder.classList.add('cds--chart-holder');
1053
+ holder.style.height = chartOptions.height;
1054
+
1055
+ return { model: { setOptions, setData: jest.fn() } };
1056
+ });
1057
+ });
1058
+
1059
+ afterEach(() => {
1060
+ createChartSpy.mockRestore();
1061
+ delete document.fullscreenElement;
1062
+ });
1063
+
1064
+ it('does not update chart options when entering and exiting fullscreen', () => {
1065
+ const { container } = render(<CarbonChart {...toolbarProps} />);
1066
+ const holder = container.querySelector('.cds--chart-holder');
1067
+
1068
+ setFullscreenElement(container.firstChild);
1069
+
1070
+ expect(
1071
+ screen.getByRole('button', {
1072
+ name: `Exit ${chartOptions.title} full screen`,
1073
+ })
1074
+ ).toBeInTheDocument();
1075
+ expect(holder.style.height).toBe('100vh');
1076
+
1077
+ setFullscreenElement(null);
1078
+
1079
+ expect(
1080
+ screen.getByRole('button', {
1081
+ name: `View ${chartOptions.title} full screen`,
1082
+ })
1083
+ ).toBeInTheDocument();
1084
+ expect(holder.style.height).toBe(chartOptions.height);
1085
+ expect(setOptions).not.toHaveBeenCalled();
1086
+ });
1087
+
1088
+ it('does not update chart options on re-render with the same props', () => {
1089
+ const { rerender } = render(<CarbonChart {...toolbarProps} />);
1090
+
1091
+ rerender(<CarbonChart {...toolbarProps} chartToolbar={{}} />);
1092
+
1093
+ expect(setOptions).not.toHaveBeenCalled();
1094
+ });
1095
+ });
1096
+
955
1097
  describe('image export', () => {
956
1098
  const toolbarProps = {
957
1099
  dataSet,
@@ -1054,6 +1196,151 @@ describe('CarbonChart', () => {
1054
1196
  });
1055
1197
  });
1056
1198
 
1199
+ describe('dot keyboard accessibility', () => {
1200
+ let rafCallbacks;
1201
+
1202
+ beforeEach(() => {
1203
+ rafCallbacks = [];
1204
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1205
+ rafCallbacks.push(cb);
1206
+ return rafCallbacks.length - 1;
1207
+ });
1208
+ });
1209
+
1210
+ afterEach(() => {
1211
+ window.requestAnimationFrame.mockRestore();
1212
+ rafCallbacks = [];
1213
+ });
1214
+
1215
+ function renderChart() {
1216
+ const { getByTestId } = render(
1217
+ <CarbonChart
1218
+ testId="dot-tab-test"
1219
+ dataSet={dataSet}
1220
+ options={chartOptions}
1221
+ type={CarbonChartType.scatter}
1222
+ />
1223
+ );
1224
+ return getByTestId('dot-tab-test');
1225
+ }
1226
+
1227
+ function addDot(wrapper) {
1228
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1229
+ const dot = document.createElementNS(
1230
+ 'http://www.w3.org/2000/svg',
1231
+ 'circle'
1232
+ );
1233
+ dot.classList.add('dot');
1234
+ svg.appendChild(dot);
1235
+ wrapper.appendChild(svg);
1236
+ return dot;
1237
+ }
1238
+
1239
+ describe('tabbing', () => {
1240
+ it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1241
+ const wrapper = renderChart();
1242
+ const dot = addDot(wrapper);
1243
+
1244
+ // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1245
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1246
+
1247
+ expect(dot).toHaveAttribute('tabindex', '0');
1248
+ });
1249
+
1250
+ it('should not overwrite an existing tabindex on circle.dot', () => {
1251
+ const wrapper = renderChart();
1252
+ const dot = addDot(wrapper);
1253
+ dot.setAttribute('tabindex', '-1');
1254
+
1255
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1256
+
1257
+ expect(dot).toHaveAttribute('tabindex', '-1');
1258
+ });
1259
+ });
1260
+
1261
+ describe('focus on dot content', () => {
1262
+ it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1263
+ const wrapper = renderChart();
1264
+ const dot = addDot(wrapper);
1265
+
1266
+ const mouseoverSpy = jest.fn();
1267
+ dot.addEventListener('mouseover', mouseoverSpy);
1268
+
1269
+ fireEvent.focusIn(dot);
1270
+
1271
+ expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1272
+ });
1273
+
1274
+ it('should dispatch mousemove on dot focusin', () => {
1275
+ const wrapper = renderChart();
1276
+ const dot = addDot(wrapper);
1277
+
1278
+ const mousemoveSpy = jest.fn();
1279
+ dot.addEventListener('mousemove', mousemoveSpy);
1280
+
1281
+ fireEvent.focusIn(dot);
1282
+
1283
+ expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1284
+ });
1285
+
1286
+ it('should not change opacity for non-dot circle elements on focusin', () => {
1287
+ const wrapper = renderChart();
1288
+ const nonDot = document.createElementNS(
1289
+ 'http://www.w3.org/2000/svg',
1290
+ 'circle'
1291
+ );
1292
+ wrapper.appendChild(nonDot);
1293
+
1294
+ fireEvent.focusIn(nonDot);
1295
+
1296
+ expect(nonDot.style.opacity).toBe('');
1297
+ });
1298
+ });
1299
+
1300
+ describe('data visibility', () => {
1301
+ it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1302
+ const wrapper = renderChart();
1303
+ const dot = addDot(wrapper);
1304
+
1305
+ const mouseoutSpy = jest.fn();
1306
+ dot.addEventListener('mouseout', mouseoutSpy);
1307
+
1308
+ fireEvent.focusIn(dot);
1309
+ fireEvent.focusOut(dot);
1310
+
1311
+ expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1312
+ });
1313
+
1314
+ it('should not dispatch mouseout when focus moves from one dot to another', () => {
1315
+ const wrapper = renderChart();
1316
+ const firstDot = addDot(wrapper);
1317
+ const secondDot = addDot(wrapper);
1318
+
1319
+ const mouseoutSpy = jest.fn();
1320
+ firstDot.addEventListener('mouseout', mouseoutSpy);
1321
+
1322
+ fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
1323
+
1324
+ expect(mouseoutSpy).not.toHaveBeenCalled();
1325
+ });
1326
+ });
1327
+
1328
+ describe('dynamic dot rendering', () => {
1329
+ it('should stamp tabindex="0" on dots added after initial raf pass', () => {
1330
+ const wrapper = renderChart();
1331
+
1332
+ // Run initial pass before adding a dot so the observer must handle it.
1333
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1334
+
1335
+ const lateDot = addDot(wrapper);
1336
+
1337
+ act(() => mutationObserverCallback([]));
1338
+
1339
+ expect(lateDot).toHaveAttribute('tabindex', '0');
1340
+ });
1341
+ });
1342
+ });
1343
+
1057
1344
  describe('custom content slots', () => {
1058
1345
  const toolbarProps = {
1059
1346
  dataSet,
@@ -1181,32 +1468,14 @@ describe('CarbonChart', () => {
1181
1468
  />
1182
1469
  );
1183
1470
 
1184
- // aria-prohibited-attr and aria-tooltip-name come from Carbon's own SVG
1185
- // output and are present on a chart with no slots at all, so they are
1186
- // excluded here rather than being attributed to the slots.
1471
+ // aria-tooltip-name, aria-allowed-attr, and aria-roles come from
1472
+ // Carbon's own SVG output and are present on a chart with no slots at all,
1473
+ // so they are excluded here rather than being attributed to the slots.
1187
1474
  const results = await axe(container, {
1188
1475
  rules: {
1189
- 'aria-prohibited-attr': { enabled: false },
1190
- 'aria-tooltip-name': { enabled: false },
1191
- },
1192
- });
1193
-
1194
- expect(results).toHaveNoViolations();
1195
- });
1196
-
1197
- it('keeps a single semantic heading and no a11y violations in the flow layout', async () => {
1198
- const { container } = render(
1199
- <CarbonChart {...toolbarProps} additionalContent={<div>Filter</div>} />
1200
- );
1201
-
1202
- expect(
1203
- screen.getAllByRole('heading', { name: chartOptions.title })
1204
- ).toHaveLength(1);
1205
-
1206
- const results = await axe(container, {
1207
- rules: {
1208
- 'aria-prohibited-attr': { enabled: false },
1209
1476
  'aria-tooltip-name': { enabled: false },
1477
+ 'aria-allowed-attr': { enabled: false },
1478
+ 'aria-roles': { enabled: false },
1210
1479
  },
1211
1480
  });
1212
1481
 
@@ -1217,6 +1486,10 @@ describe('CarbonChart', () => {
1217
1486
  describe('Legend accessibility wrap', () => {
1218
1487
  const testId = 'legend-a11y';
1219
1488
 
1489
+ beforeEach(() => {
1490
+ mutationObserverCallbacks = [];
1491
+ });
1492
+
1220
1493
  it('wraps the Carbon legend in a fieldset with a legend caption derived from the chart title', () => {
1221
1494
  const { getByTestId } = render(
1222
1495
  <CarbonChart
@@ -1337,10 +1610,10 @@ describe('CarbonChart', () => {
1337
1610
  expect(itemsHost.getAttribute('aria-label')).toBeNull();
1338
1611
  expect(itemsHost.getAttribute('role')).toBe('list');
1339
1612
 
1340
- if (itemsHost !== legend) {
1341
- expect(legend.getAttribute('role')).toBeNull();
1342
- expect(legend.getAttribute('aria-label')).toBeNull();
1343
- }
1613
+ expect(legend.getAttribute('role')).toBe(
1614
+ itemsHost === legend ? 'list' : null
1615
+ );
1616
+ expect(legend.getAttribute('aria-label')).toBeNull();
1344
1617
 
1345
1618
  const items = itemsHost.querySelectorAll('.legend-item');
1346
1619
  expect(items.length).toBeGreaterThan(0);
@@ -1408,149 +1681,4 @@ describe('CarbonChart', () => {
1408
1681
  );
1409
1682
  });
1410
1683
  });
1411
-
1412
- describe('dot keyboard accessibility', () => {
1413
- let rafCallbacks;
1414
-
1415
- beforeEach(() => {
1416
- rafCallbacks = [];
1417
- jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1418
- rafCallbacks.push(cb);
1419
- return rafCallbacks.length - 1;
1420
- });
1421
- });
1422
-
1423
- afterEach(() => {
1424
- window.requestAnimationFrame.mockRestore();
1425
- rafCallbacks = [];
1426
- });
1427
-
1428
- function renderChart() {
1429
- const { getByTestId } = render(
1430
- <CarbonChart
1431
- testId="dot-tab-test"
1432
- dataSet={dataSet}
1433
- options={chartOptions}
1434
- type={CarbonChartType.scatter}
1435
- />
1436
- );
1437
- return getByTestId('dot-tab-test');
1438
- }
1439
-
1440
- function addDot(wrapper) {
1441
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1442
- const dot = document.createElementNS(
1443
- 'http://www.w3.org/2000/svg',
1444
- 'circle'
1445
- );
1446
- dot.classList.add('dot');
1447
- svg.appendChild(dot);
1448
- wrapper.appendChild(svg);
1449
- return dot;
1450
- }
1451
-
1452
- describe('tabbing', () => {
1453
- it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1454
- const wrapper = renderChart();
1455
- const dot = addDot(wrapper);
1456
-
1457
- // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1458
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1459
-
1460
- expect(dot).toHaveAttribute('tabindex', '0');
1461
- });
1462
-
1463
- it('should not overwrite an existing tabindex on circle.dot', () => {
1464
- const wrapper = renderChart();
1465
- const dot = addDot(wrapper);
1466
- dot.setAttribute('tabindex', '-1');
1467
-
1468
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1469
-
1470
- expect(dot).toHaveAttribute('tabindex', '-1');
1471
- });
1472
- });
1473
-
1474
- describe('focus on dot content', () => {
1475
- it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1476
- const wrapper = renderChart();
1477
- const dot = addDot(wrapper);
1478
-
1479
- const mouseoverSpy = jest.fn();
1480
- dot.addEventListener('mouseover', mouseoverSpy);
1481
-
1482
- fireEvent.focusIn(dot);
1483
-
1484
- expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1485
- });
1486
-
1487
- it('should dispatch mousemove on dot focusin', () => {
1488
- const wrapper = renderChart();
1489
- const dot = addDot(wrapper);
1490
-
1491
- const mousemoveSpy = jest.fn();
1492
- dot.addEventListener('mousemove', mousemoveSpy);
1493
-
1494
- fireEvent.focusIn(dot);
1495
-
1496
- expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1497
- });
1498
-
1499
- it('should not change opacity for non-dot circle elements on focusin', () => {
1500
- const wrapper = renderChart();
1501
- const nonDot = document.createElementNS(
1502
- 'http://www.w3.org/2000/svg',
1503
- 'circle'
1504
- );
1505
- wrapper.appendChild(nonDot);
1506
-
1507
- fireEvent.focusIn(nonDot);
1508
-
1509
- expect(nonDot.style.opacity).toBe('');
1510
- });
1511
- });
1512
-
1513
- describe('data visibility', () => {
1514
- it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1515
- const wrapper = renderChart();
1516
- const dot = addDot(wrapper);
1517
-
1518
- const mouseoutSpy = jest.fn();
1519
- dot.addEventListener('mouseout', mouseoutSpy);
1520
-
1521
- fireEvent.focusIn(dot);
1522
- fireEvent.focusOut(dot);
1523
-
1524
- expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1525
- });
1526
-
1527
- it('should not dispatch mouseout when focus moves from one dot to another', () => {
1528
- const wrapper = renderChart();
1529
- const firstDot = addDot(wrapper);
1530
- const secondDot = addDot(wrapper);
1531
-
1532
- const mouseoutSpy = jest.fn();
1533
- firstDot.addEventListener('mouseout', mouseoutSpy);
1534
-
1535
- fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
1536
-
1537
- expect(mouseoutSpy).not.toHaveBeenCalled();
1538
- });
1539
- });
1540
-
1541
- describe('dynamic dot rendering', () => {
1542
- it('should stamp tabindex="0" on dots added after initial raf pass', () => {
1543
- const wrapper = renderChart();
1544
-
1545
- // Run initial pass before adding a dot so the observer must handle it.
1546
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1547
-
1548
- const lateDot = addDot(wrapper);
1549
-
1550
- act(() => mutationObserverCallback([]));
1551
-
1552
- expect(lateDot).toHaveAttribute('tabindex', '0');
1553
- });
1554
- });
1555
- });
1556
1684
  });