@react-magma/charts 15.0.0-rc.4 → 16.0.0-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/charts.js +363 -197
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +364 -198
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +962 -422
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +25 -0
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +502 -3
- package/src/components/CarbonChart/CarbonChart.tsx +559 -256
- package/src/components/CarbonChart/CarbonChartArea.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +3 -1
- package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartLine.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartPie.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartStep.stories.tsx +1 -1
- package/src/components/CarbonChart/carbon-charts.css +89 -87
- package/src/components/ChartTable/ChartMoreOptionsButton.tsx +1 -0
- package/src/components/ChartTable/ChartTable.stories.tsx +140 -1
- package/dist/components/ChartTable/ChartTable.test.d.ts +0 -1
- /package/src/components/ChartTable/{ChartTable.test.tsx → ChartTable.test.js} +0 -0
|
@@ -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": "
|
|
3
|
+
"version": "16.0.0-next.0",
|
|
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": "^
|
|
53
|
+
"react-magma-dom": "^7.0.0-next.0",
|
|
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": "^
|
|
63
|
+
"react-magma-dom": "^7.0.0",
|
|
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 '.';
|
|
@@ -187,6 +190,27 @@ describe('CarbonChart', () => {
|
|
|
187
190
|
);
|
|
188
191
|
});
|
|
189
192
|
|
|
193
|
+
it("pins Carbon's export `.filled` background to the inverse surface color", () => {
|
|
194
|
+
const testId = 'filled-bg-inverse';
|
|
195
|
+
const { getByTestId } = render(
|
|
196
|
+
<ThemeContext.Provider value={magma}>
|
|
197
|
+
<CarbonChart
|
|
198
|
+
testId={testId}
|
|
199
|
+
dataSet={dataSet}
|
|
200
|
+
options={chartOptions}
|
|
201
|
+
type={CarbonChartType.bar}
|
|
202
|
+
isInverse
|
|
203
|
+
/>
|
|
204
|
+
</ThemeContext.Provider>
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
expect(getByTestId(testId)).toHaveStyleRule(
|
|
208
|
+
'background-color',
|
|
209
|
+
magma.colors.primary600,
|
|
210
|
+
{ target: '.cds--chart-holder.filled' }
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
|
|
190
214
|
it('should apply theme.colors.neutral100 for inverse text color', () => {
|
|
191
215
|
const testId = 'text-inverse-test';
|
|
192
216
|
const { getByTestId } = render(
|
|
@@ -928,6 +952,268 @@ describe('CarbonChart', () => {
|
|
|
928
952
|
});
|
|
929
953
|
});
|
|
930
954
|
|
|
955
|
+
describe('image export', () => {
|
|
956
|
+
const toolbarProps = {
|
|
957
|
+
dataSet,
|
|
958
|
+
options: chartOptions,
|
|
959
|
+
type: CarbonChartType.bar,
|
|
960
|
+
chartToolbar: {},
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
let exportToPNG;
|
|
964
|
+
let exportToJPG;
|
|
965
|
+
let createChartSpy;
|
|
966
|
+
|
|
967
|
+
beforeEach(() => {
|
|
968
|
+
exportToPNG = jest.fn();
|
|
969
|
+
exportToJPG = jest.fn();
|
|
970
|
+
createChartSpy = jest
|
|
971
|
+
.spyOn(SimpleBarChart.prototype, 'createChart')
|
|
972
|
+
.mockImplementation(() => ({
|
|
973
|
+
services: { domUtils: { exportToPNG, exportToJPG } },
|
|
974
|
+
}));
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
afterEach(() => {
|
|
978
|
+
createChartSpy.mockRestore();
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
it("runs Carbon's own PNG export from the More options menu", () => {
|
|
982
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
983
|
+
|
|
984
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
985
|
+
fireEvent.click(screen.getByText('Download as PNG'));
|
|
986
|
+
|
|
987
|
+
expect(exportToPNG).toHaveBeenCalledTimes(1);
|
|
988
|
+
expect(exportToJPG).not.toHaveBeenCalled();
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
it("runs Carbon's own JPG export from the More options menu", () => {
|
|
992
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
993
|
+
|
|
994
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
995
|
+
fireEvent.click(screen.getByText('Download as JPG'));
|
|
996
|
+
|
|
997
|
+
expect(exportToJPG).toHaveBeenCalledTimes(1);
|
|
998
|
+
expect(exportToPNG).not.toHaveBeenCalled();
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
it("keeps Carbon's own title alive and uses it as the export file name", () => {
|
|
1002
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1003
|
+
|
|
1004
|
+
const options = createChartSpy.mock.calls[0][2];
|
|
1005
|
+
expect(options.title).toBe(chartOptions.title);
|
|
1006
|
+
expect(options.fileDownload.fileName).toBe(chartOptions.title);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
it("reveals Carbon's hidden title for the capture and restores it afterwards", () => {
|
|
1010
|
+
jest.useFakeTimers();
|
|
1011
|
+
try {
|
|
1012
|
+
const { container } = render(<CarbonChart {...toolbarProps} />);
|
|
1013
|
+
const wrapper = container.querySelector('.carbon-chart-wrapper');
|
|
1014
|
+
|
|
1015
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1016
|
+
|
|
1017
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1018
|
+
fireEvent.click(screen.getByText('Download as PNG'));
|
|
1019
|
+
|
|
1020
|
+
expect(wrapper).not.toHaveClass('has-magma-toolbar');
|
|
1021
|
+
|
|
1022
|
+
jest.runOnlyPendingTimers();
|
|
1023
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1024
|
+
} finally {
|
|
1025
|
+
jest.useRealTimers();
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
it('reveals the title for the flow layout (additionalContent) export too', () => {
|
|
1030
|
+
jest.useFakeTimers();
|
|
1031
|
+
try {
|
|
1032
|
+
const { container } = render(
|
|
1033
|
+
<CarbonChart
|
|
1034
|
+
{...toolbarProps}
|
|
1035
|
+
additionalContent={<div>Filter</div>}
|
|
1036
|
+
/>
|
|
1037
|
+
);
|
|
1038
|
+
const wrapper = container.querySelector('.carbon-chart-wrapper');
|
|
1039
|
+
|
|
1040
|
+
expect(createChartSpy.mock.calls[0][2].title).toBe(chartOptions.title);
|
|
1041
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1042
|
+
|
|
1043
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1044
|
+
fireEvent.click(screen.getByText('Download as JPG'));
|
|
1045
|
+
|
|
1046
|
+
expect(exportToJPG).toHaveBeenCalledTimes(1);
|
|
1047
|
+
expect(wrapper).not.toHaveClass('has-magma-toolbar');
|
|
1048
|
+
|
|
1049
|
+
jest.runOnlyPendingTimers();
|
|
1050
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1051
|
+
} finally {
|
|
1052
|
+
jest.useRealTimers();
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
describe('custom content slots', () => {
|
|
1058
|
+
const toolbarProps = {
|
|
1059
|
+
dataSet,
|
|
1060
|
+
options: chartOptions,
|
|
1061
|
+
type: CarbonChartType.bar,
|
|
1062
|
+
chartToolbar: {},
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
it('should render titlePrefix and titleSuffix around the title', () => {
|
|
1066
|
+
render(
|
|
1067
|
+
<CarbonChart
|
|
1068
|
+
{...toolbarProps}
|
|
1069
|
+
chartToolbar={{
|
|
1070
|
+
titlePrefix: <span data-testid="before">Badge</span>,
|
|
1071
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
1072
|
+
}}
|
|
1073
|
+
/>
|
|
1074
|
+
);
|
|
1075
|
+
|
|
1076
|
+
const before = screen.getByTestId('before');
|
|
1077
|
+
const heading = screen.getByRole('heading', {
|
|
1078
|
+
level: 2,
|
|
1079
|
+
name: chartOptions.title,
|
|
1080
|
+
});
|
|
1081
|
+
const after = screen.getByRole('button', { name: 'About this chart' });
|
|
1082
|
+
|
|
1083
|
+
expect(
|
|
1084
|
+
before.compareDocumentPosition(heading) &
|
|
1085
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
1086
|
+
).toBeTruthy();
|
|
1087
|
+
expect(
|
|
1088
|
+
heading.compareDocumentPosition(after) &
|
|
1089
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
1090
|
+
).toBeTruthy();
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
it('should place title slots before the toolbar actions in focus order', () => {
|
|
1094
|
+
render(
|
|
1095
|
+
<CarbonChart
|
|
1096
|
+
{...toolbarProps}
|
|
1097
|
+
chartToolbar={{
|
|
1098
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
1099
|
+
}}
|
|
1100
|
+
/>
|
|
1101
|
+
);
|
|
1102
|
+
|
|
1103
|
+
const after = screen.getByRole('button', { name: 'About this chart' });
|
|
1104
|
+
const tableButton = screen.getByRole('button', {
|
|
1105
|
+
name: chartOptions.title,
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
expect(
|
|
1109
|
+
after.compareDocumentPosition(tableButton) &
|
|
1110
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
1111
|
+
).toBeTruthy();
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
it('should keep the title as the accessible name when titleSuffix is used', () => {
|
|
1115
|
+
render(
|
|
1116
|
+
<CarbonChart
|
|
1117
|
+
{...toolbarProps}
|
|
1118
|
+
chartToolbar={{
|
|
1119
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
1120
|
+
}}
|
|
1121
|
+
/>
|
|
1122
|
+
);
|
|
1123
|
+
|
|
1124
|
+
// The heading, the chart region and the table modal must all stay
|
|
1125
|
+
// anchored to options.title, which is also the exported file name.
|
|
1126
|
+
expect(
|
|
1127
|
+
screen.getByRole('heading', { level: 2, name: chartOptions.title })
|
|
1128
|
+
).toBeInTheDocument();
|
|
1129
|
+
expect(
|
|
1130
|
+
screen.getByRole('region', { name: chartOptions.title })
|
|
1131
|
+
).toBeInTheDocument();
|
|
1132
|
+
|
|
1133
|
+
fireEvent.click(screen.getByRole('button', { name: chartOptions.title }));
|
|
1134
|
+
|
|
1135
|
+
expect(
|
|
1136
|
+
screen.getByRole('heading', {
|
|
1137
|
+
level: 2,
|
|
1138
|
+
name: `Tabular representation ${chartOptions.title}`,
|
|
1139
|
+
})
|
|
1140
|
+
).toBeInTheDocument();
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
it('should render no slot markup by default', () => {
|
|
1144
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1145
|
+
|
|
1146
|
+
expect(screen.queryByTestId('before')).not.toBeInTheDocument();
|
|
1147
|
+
expect(
|
|
1148
|
+
screen.getByRole('heading', { level: 2, name: chartOptions.title })
|
|
1149
|
+
).toBeInTheDocument();
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
it('should expose the resolved inverse value to slot content', () => {
|
|
1153
|
+
// Slot content is the adopter's, so it reads isInverse from context
|
|
1154
|
+
// rather than from our prop.
|
|
1155
|
+
function InverseProbe() {
|
|
1156
|
+
return <span>{useIsInverse() ? 'inverse' : 'default'}</span>;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
render(
|
|
1160
|
+
<CarbonChart
|
|
1161
|
+
{...toolbarProps}
|
|
1162
|
+
isInverse
|
|
1163
|
+
chartToolbar={{
|
|
1164
|
+
titlePrefix: <InverseProbe />,
|
|
1165
|
+
titleSuffix: <InverseProbe />,
|
|
1166
|
+
}}
|
|
1167
|
+
/>
|
|
1168
|
+
);
|
|
1169
|
+
|
|
1170
|
+
expect(screen.getAllByText('inverse')).toHaveLength(2);
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
it('should not introduce accessibility violations with both slots', async () => {
|
|
1174
|
+
const { container } = render(
|
|
1175
|
+
<CarbonChart
|
|
1176
|
+
{...toolbarProps}
|
|
1177
|
+
chartToolbar={{
|
|
1178
|
+
titlePrefix: <span>Badge</span>,
|
|
1179
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
1180
|
+
}}
|
|
1181
|
+
/>
|
|
1182
|
+
);
|
|
1183
|
+
|
|
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.
|
|
1187
|
+
const results = await axe(container, {
|
|
1188
|
+
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
|
+
'aria-tooltip-name': { enabled: false },
|
|
1210
|
+
},
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
expect(results).toHaveNoViolations();
|
|
1214
|
+
});
|
|
1215
|
+
});
|
|
1216
|
+
|
|
931
1217
|
describe('Legend accessibility wrap', () => {
|
|
932
1218
|
const testId = 'legend-a11y';
|
|
933
1219
|
|
|
@@ -1000,6 +1286,37 @@ describe('CarbonChart', () => {
|
|
|
1000
1286
|
expect(after[0]).toBe(before[0]);
|
|
1001
1287
|
});
|
|
1002
1288
|
|
|
1289
|
+
it('unwraps the stale fieldset when Carbon re-renders the legend deeper inside it', () => {
|
|
1290
|
+
const { getByTestId } = render(
|
|
1291
|
+
<CarbonChart
|
|
1292
|
+
testId={testId}
|
|
1293
|
+
dataSet={dataSet}
|
|
1294
|
+
options={chartOptions}
|
|
1295
|
+
type={CarbonChartType.bar}
|
|
1296
|
+
/>
|
|
1297
|
+
);
|
|
1298
|
+
const wrapper = getByTestId(testId);
|
|
1299
|
+
|
|
1300
|
+
const staleFieldset = wrapper.querySelector('.cds--cc--legend-fieldset');
|
|
1301
|
+
const legend = staleFieldset.querySelector('.cds--cc--legend');
|
|
1302
|
+
|
|
1303
|
+
act(() => {
|
|
1304
|
+
const layoutChild = document.createElement('div');
|
|
1305
|
+
layoutChild.className = 'layout-child legend';
|
|
1306
|
+
staleFieldset.append(layoutChild);
|
|
1307
|
+
layoutChild.append(legend);
|
|
1308
|
+
mutationObserverCallback?.();
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
const fieldsets = wrapper.querySelectorAll('.cds--cc--legend-fieldset');
|
|
1312
|
+
expect(fieldsets).toHaveLength(1);
|
|
1313
|
+
expect(
|
|
1314
|
+
fieldsets[0].querySelector('.cds--cc--legend-fieldset')
|
|
1315
|
+
).toBeNull();
|
|
1316
|
+
expect(fieldsets[0].contains(legend)).toBe(true);
|
|
1317
|
+
expect(fieldsets[0].querySelectorAll(':scope > legend')).toHaveLength(1);
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1003
1320
|
it('replaces Carbon\'s generic "Data groups" aria-label with semantic list roles on the legend and its items', () => {
|
|
1004
1321
|
const { getByTestId } = render(
|
|
1005
1322
|
<CarbonChart
|
|
@@ -1013,16 +1330,53 @@ describe('CarbonChart', () => {
|
|
|
1013
1330
|
|
|
1014
1331
|
const legend = wrapper.querySelector('.cds--cc--legend');
|
|
1015
1332
|
expect(legend).not.toBeNull();
|
|
1016
|
-
expect(legend.getAttribute('aria-label')).toBeNull();
|
|
1017
|
-
expect(legend.getAttribute('role')).toBe('list');
|
|
1018
1333
|
|
|
1019
|
-
const
|
|
1334
|
+
const itemsHost = legend.matches('[data-name="legend-items"]')
|
|
1335
|
+
? legend
|
|
1336
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
1337
|
+
expect(itemsHost.getAttribute('aria-label')).toBeNull();
|
|
1338
|
+
expect(itemsHost.getAttribute('role')).toBe('list');
|
|
1339
|
+
|
|
1340
|
+
if (itemsHost !== legend) {
|
|
1341
|
+
expect(legend.getAttribute('role')).toBeNull();
|
|
1342
|
+
expect(legend.getAttribute('aria-label')).toBeNull();
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
const items = itemsHost.querySelectorAll('.legend-item');
|
|
1020
1346
|
expect(items.length).toBeGreaterThan(0);
|
|
1021
1347
|
items.forEach(item => {
|
|
1022
1348
|
expect(item.getAttribute('role')).toBe('listitem');
|
|
1023
1349
|
});
|
|
1024
1350
|
});
|
|
1025
1351
|
|
|
1352
|
+
it('restores list semantics when Carbon re-applies role="group" and aria-label on the items container', () => {
|
|
1353
|
+
const { getByTestId } = render(
|
|
1354
|
+
<CarbonChart
|
|
1355
|
+
testId={testId}
|
|
1356
|
+
dataSet={dataSet}
|
|
1357
|
+
options={chartOptions}
|
|
1358
|
+
type={CarbonChartType.bar}
|
|
1359
|
+
/>
|
|
1360
|
+
);
|
|
1361
|
+
const wrapper = getByTestId(testId);
|
|
1362
|
+
|
|
1363
|
+
const itemsHost = wrapper.querySelector('[data-name="legend-items"]');
|
|
1364
|
+
expect(itemsHost).not.toBeNull();
|
|
1365
|
+
expect(itemsHost.getAttribute('role')).toBe('list');
|
|
1366
|
+
|
|
1367
|
+
act(() => {
|
|
1368
|
+
itemsHost.setAttribute('role', 'group');
|
|
1369
|
+
itemsHost.setAttribute('aria-label', 'Data groups');
|
|
1370
|
+
mutationObserverCallback();
|
|
1371
|
+
});
|
|
1372
|
+
act(() => {
|
|
1373
|
+
mutationObserverCallback();
|
|
1374
|
+
});
|
|
1375
|
+
|
|
1376
|
+
expect(itemsHost.getAttribute('role')).toBe('list');
|
|
1377
|
+
expect(itemsHost.getAttribute('aria-label')).toBeNull();
|
|
1378
|
+
});
|
|
1379
|
+
|
|
1026
1380
|
it('uses translated legend instructions from I18nContext', () => {
|
|
1027
1381
|
const translatedInstructions =
|
|
1028
1382
|
'Marquer ces cases mettra à jour le graphique.';
|
|
@@ -1054,4 +1408,149 @@ describe('CarbonChart', () => {
|
|
|
1054
1408
|
);
|
|
1055
1409
|
});
|
|
1056
1410
|
});
|
|
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
|
+
});
|
|
1057
1556
|
});
|