@react-magma/charts 14.0.0-next.4 → 14.0.0-next.5
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 +104 -9
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +105 -10
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +104 -9
- package/dist/charts.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CarbonChart/CarbonChart.test.js +71 -3
- package/src/components/CarbonChart/CarbonChart.tsx +128 -9
package/dist/charts.umd.js
CHANGED
|
@@ -51286,8 +51286,11 @@
|
|
|
51286
51286
|
var _a = React__namespace.useState(false), isTableOpen = _a[0], setIsTableOpen = _a[1];
|
|
51287
51287
|
var _b = React__namespace.useState(false), isFullscreen = _b[0], setIsFullscreen = _b[1];
|
|
51288
51288
|
var _c = React__namespace.useState(''), legendAnnouncement = _c[0], setLegendAnnouncement = _c[1];
|
|
51289
|
+
var legendGroupAnnounceRef = React__namespace.useRef(null);
|
|
51289
51290
|
var lastTableTriggerRef = React__namespace.useRef(null);
|
|
51290
51291
|
var legendAnnouncedRef = React__namespace.useRef(false);
|
|
51292
|
+
var selectionSignatureRef = React__namespace.useRef(undefined);
|
|
51293
|
+
var _d = useDeviceDetect(), isMacOS = _d.isMacOS, isChrome = _d.isChrome;
|
|
51291
51294
|
var mergedRef = React__namespace.useCallback(function (node) {
|
|
51292
51295
|
internalRef.current = node;
|
|
51293
51296
|
if (typeof ref === 'function') {
|
|
@@ -51360,20 +51363,49 @@
|
|
|
51360
51363
|
if (!container)
|
|
51361
51364
|
return;
|
|
51362
51365
|
var applyListSemantics = function (legend) {
|
|
51363
|
-
legend.
|
|
51364
|
-
|
|
51365
|
-
|
|
51366
|
-
|
|
51367
|
-
|
|
51366
|
+
var itemsHost = legend.matches('[data-name="legend-items"]')
|
|
51367
|
+
? legend
|
|
51368
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
51369
|
+
itemsHost.removeAttribute('aria-label');
|
|
51370
|
+
if (itemsHost.getAttribute('role') !== 'list') {
|
|
51371
|
+
itemsHost.setAttribute('role', 'list');
|
|
51372
|
+
}
|
|
51373
|
+
legend.querySelectorAll('.legend-item').forEach(function (item) {
|
|
51374
|
+
if (item.getAttribute('role') !== 'listitem') {
|
|
51375
|
+
item.setAttribute('role', 'listitem');
|
|
51376
|
+
}
|
|
51377
|
+
});
|
|
51378
|
+
container.querySelectorAll('[role="list"]').forEach(function (el) {
|
|
51379
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
51380
|
+
el.removeAttribute('role');
|
|
51381
|
+
}
|
|
51382
|
+
});
|
|
51383
|
+
container.querySelectorAll('[aria-label="Data groups"]').forEach(function (el) {
|
|
51384
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
51385
|
+
el.removeAttribute('aria-label');
|
|
51386
|
+
}
|
|
51387
|
+
});
|
|
51388
|
+
};
|
|
51389
|
+
var unwrapFieldset = function (fieldset) {
|
|
51390
|
+
var _a;
|
|
51391
|
+
(_a = fieldset.querySelector(':scope > legend')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
51392
|
+
fieldset.replaceWith.apply(fieldset, Array.from(fieldset.childNodes));
|
|
51368
51393
|
};
|
|
51369
51394
|
var wrapLegend = function () {
|
|
51370
51395
|
var legend = container.querySelector('.cds--cc--legend');
|
|
51371
51396
|
if (!legend)
|
|
51372
51397
|
return;
|
|
51373
51398
|
applyListSemantics(legend);
|
|
51374
|
-
var
|
|
51375
|
-
|
|
51376
|
-
|
|
51399
|
+
var closestFieldset = legend.closest('fieldset.cds--cc--legend-fieldset');
|
|
51400
|
+
container
|
|
51401
|
+
.querySelectorAll('fieldset.cds--cc--legend-fieldset')
|
|
51402
|
+
.forEach(function (fieldset) {
|
|
51403
|
+
if (fieldset !== closestFieldset) {
|
|
51404
|
+
unwrapFieldset(fieldset);
|
|
51405
|
+
}
|
|
51406
|
+
});
|
|
51407
|
+
if (closestFieldset) {
|
|
51408
|
+
var existingCaption = closestFieldset.querySelector(':scope > legend');
|
|
51377
51409
|
if (existingCaption && existingCaption.textContent !== legendLabel) {
|
|
51378
51410
|
existingCaption.textContent = legendLabel;
|
|
51379
51411
|
}
|
|
@@ -51388,9 +51420,58 @@
|
|
|
51388
51420
|
};
|
|
51389
51421
|
wrapLegend();
|
|
51390
51422
|
var observer = new MutationObserver(wrapLegend);
|
|
51391
|
-
observer.observe(container, {
|
|
51423
|
+
observer.observe(container, {
|
|
51424
|
+
childList: true,
|
|
51425
|
+
subtree: true,
|
|
51426
|
+
attributes: true,
|
|
51427
|
+
attributeFilter: ['role', 'aria-label'],
|
|
51428
|
+
});
|
|
51392
51429
|
return function () { return observer.disconnect(); };
|
|
51393
51430
|
}, [legendLabel]);
|
|
51431
|
+
React__namespace.useEffect(function () {
|
|
51432
|
+
var container = internalRef.current;
|
|
51433
|
+
if (!container || !isMacOS || !isChrome)
|
|
51434
|
+
return;
|
|
51435
|
+
var announceTimer;
|
|
51436
|
+
var alternateSuffix = false;
|
|
51437
|
+
var closestLegend = function (node) {
|
|
51438
|
+
return node instanceof Element ? node.closest('.cds--cc--legend') : null;
|
|
51439
|
+
};
|
|
51440
|
+
var handleFocusIn = function (event) {
|
|
51441
|
+
var enteredLegend = closestLegend(event.target);
|
|
51442
|
+
var cameFromLegend = closestLegend(event.relatedTarget);
|
|
51443
|
+
if (enteredLegend && !cameFromLegend) {
|
|
51444
|
+
if (legendGroupAnnounceRef.current) {
|
|
51445
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
51446
|
+
}
|
|
51447
|
+
clearTimeout(announceTimer);
|
|
51448
|
+
announceTimer = setTimeout(function () {
|
|
51449
|
+
if (legendGroupAnnounceRef.current) {
|
|
51450
|
+
alternateSuffix = !alternateSuffix;
|
|
51451
|
+
legendGroupAnnounceRef.current.textContent =
|
|
51452
|
+
legendLabel + (alternateSuffix ? ' ' : '');
|
|
51453
|
+
}
|
|
51454
|
+
}, 250);
|
|
51455
|
+
}
|
|
51456
|
+
};
|
|
51457
|
+
var handleFocusOut = function (event) {
|
|
51458
|
+
var leftLegend = closestLegend(event.target) && !closestLegend(event.relatedTarget);
|
|
51459
|
+
// Reset once focus leaves the legend so re-entering announces again.
|
|
51460
|
+
if (leftLegend) {
|
|
51461
|
+
clearTimeout(announceTimer);
|
|
51462
|
+
if (legendGroupAnnounceRef.current) {
|
|
51463
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
51464
|
+
}
|
|
51465
|
+
}
|
|
51466
|
+
};
|
|
51467
|
+
container.addEventListener('focusin', handleFocusIn);
|
|
51468
|
+
container.addEventListener('focusout', handleFocusOut);
|
|
51469
|
+
return function () {
|
|
51470
|
+
clearTimeout(announceTimer);
|
|
51471
|
+
container.removeEventListener('focusin', handleFocusIn);
|
|
51472
|
+
container.removeEventListener('focusout', handleFocusOut);
|
|
51473
|
+
};
|
|
51474
|
+
}, [isMacOS, isChrome, legendLabel]);
|
|
51394
51475
|
var handleModalDownloadCsv = React__namespace.useCallback(function () {
|
|
51395
51476
|
downloadCsv(dataSet, chartTitle);
|
|
51396
51477
|
}, [dataSet, chartTitle]);
|
|
@@ -51548,6 +51629,17 @@
|
|
|
51548
51629
|
activeLabels.push(((_a = label.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
51549
51630
|
}
|
|
51550
51631
|
});
|
|
51632
|
+
// Carbon re-applies aria-checked (with the same values) on every
|
|
51633
|
+
// render, which still triggers this observer. Only announce when the
|
|
51634
|
+
// selection actually changed, otherwise unrelated re-renders (e.g.
|
|
51635
|
+
// the legend group announcement) cause phantom announcements.
|
|
51636
|
+
var selectionSignature = activeLabels.join('|') + "::" + allItems.length;
|
|
51637
|
+
if (selectionSignatureRef.current === selectionSignature)
|
|
51638
|
+
return;
|
|
51639
|
+
var isFirstRun = selectionSignatureRef.current === undefined;
|
|
51640
|
+
selectionSignatureRef.current = selectionSignature;
|
|
51641
|
+
if (isFirstRun)
|
|
51642
|
+
return;
|
|
51551
51643
|
if (activeLabels.length === 1) {
|
|
51552
51644
|
if (!legendAnnouncedRef.current) {
|
|
51553
51645
|
legendAnnouncedRef.current = true;
|
|
@@ -51564,6 +51656,7 @@
|
|
|
51564
51656
|
}
|
|
51565
51657
|
});
|
|
51566
51658
|
observer.observe(wrapper, {
|
|
51659
|
+
childList: true,
|
|
51567
51660
|
subtree: true,
|
|
51568
51661
|
attributes: true,
|
|
51569
51662
|
attributeFilter: ['aria-checked'],
|
|
@@ -51577,6 +51670,8 @@
|
|
|
51577
51670
|
return (React__namespace.createElement(FullscreenRoot, { ref: mergedRef, isInverse: isInverse, theme: theme },
|
|
51578
51671
|
React__namespace.createElement(VisuallyHidden, null,
|
|
51579
51672
|
React__namespace.createElement(Announce, null, legendAnnouncement)),
|
|
51673
|
+
React__namespace.createElement(VisuallyHidden, null,
|
|
51674
|
+
React__namespace.createElement("div", { "aria-live": "polite", ref: legendGroupAnnounceRef })),
|
|
51580
51675
|
React__namespace.createElement(CarbonChartWrapper, __assign({ "data-testid": testId, isInverse: isInverse, theme: theme, className: "carbon-chart-wrapper" + (chartToolbar ? ' has-magma-toolbar' : ''), groupsLength: groupsLength < 6 ? groupsLength : 14, role: "region", "aria-label": ariaLabel || chartTitle, "aria-roledescription": "chart" }, rest),
|
|
51581
51676
|
React__namespace.createElement(ChartContentWrapper, null,
|
|
51582
51677
|
chartToolbar && (React__namespace.createElement(CarbonChartToolbar, { config: chartToolbar, dataSet: dataSet, isInverse: isInverse, isTableOpen: isTableOpen, isFullscreen: isFullscreen, onOpenTable: openTableModal, onToggleFullscreen: toggleFullscreen, theme: theme, title: chartTitle, wrapperRef: internalRef })),
|