@react-magma/charts 15.0.0-rc.4 → 15.0.0-rc.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
|
@@ -30422,8 +30422,11 @@
|
|
|
30422
30422
|
var _a = React__default__namespace.useState(false), isTableOpen = _a[0], setIsTableOpen = _a[1];
|
|
30423
30423
|
var _b = React__default__namespace.useState(false), isFullscreen = _b[0], setIsFullscreen = _b[1];
|
|
30424
30424
|
var _c = React__default__namespace.useState(''), legendAnnouncement = _c[0], setLegendAnnouncement = _c[1];
|
|
30425
|
+
var legendGroupAnnounceRef = React__default__namespace.useRef(null);
|
|
30425
30426
|
var lastTableTriggerRef = React__default__namespace.useRef(null);
|
|
30426
30427
|
var legendAnnouncedRef = React__default__namespace.useRef(false);
|
|
30428
|
+
var selectionSignatureRef = React__default__namespace.useRef(undefined);
|
|
30429
|
+
var _d = useDeviceDetect(), isMacOS = _d.isMacOS, isChrome = _d.isChrome;
|
|
30427
30430
|
var mergedRef = React__default__namespace.useCallback(function (node) {
|
|
30428
30431
|
internalRef.current = node;
|
|
30429
30432
|
if (typeof ref === 'function') {
|
|
@@ -30490,20 +30493,49 @@
|
|
|
30490
30493
|
if (!container)
|
|
30491
30494
|
return;
|
|
30492
30495
|
var applyListSemantics = function (legend) {
|
|
30493
|
-
legend.
|
|
30494
|
-
|
|
30495
|
-
|
|
30496
|
-
|
|
30497
|
-
|
|
30496
|
+
var itemsHost = legend.matches('[data-name="legend-items"]')
|
|
30497
|
+
? legend
|
|
30498
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
30499
|
+
itemsHost.removeAttribute('aria-label');
|
|
30500
|
+
if (itemsHost.getAttribute('role') !== 'list') {
|
|
30501
|
+
itemsHost.setAttribute('role', 'list');
|
|
30502
|
+
}
|
|
30503
|
+
legend.querySelectorAll('.legend-item').forEach(function (item) {
|
|
30504
|
+
if (item.getAttribute('role') !== 'listitem') {
|
|
30505
|
+
item.setAttribute('role', 'listitem');
|
|
30506
|
+
}
|
|
30507
|
+
});
|
|
30508
|
+
container.querySelectorAll('[role="list"]').forEach(function (el) {
|
|
30509
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
30510
|
+
el.removeAttribute('role');
|
|
30511
|
+
}
|
|
30512
|
+
});
|
|
30513
|
+
container.querySelectorAll('[aria-label="Data groups"]').forEach(function (el) {
|
|
30514
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
30515
|
+
el.removeAttribute('aria-label');
|
|
30516
|
+
}
|
|
30517
|
+
});
|
|
30518
|
+
};
|
|
30519
|
+
var unwrapFieldset = function (fieldset) {
|
|
30520
|
+
var _a;
|
|
30521
|
+
(_a = fieldset.querySelector(':scope > legend')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
30522
|
+
fieldset.replaceWith.apply(fieldset, Array.from(fieldset.childNodes));
|
|
30498
30523
|
};
|
|
30499
30524
|
var wrapLegend = function () {
|
|
30500
30525
|
var legend = container.querySelector('.cds--cc--legend');
|
|
30501
30526
|
if (!legend)
|
|
30502
30527
|
return;
|
|
30503
30528
|
applyListSemantics(legend);
|
|
30504
|
-
var
|
|
30505
|
-
|
|
30506
|
-
|
|
30529
|
+
var closestFieldset = legend.closest('fieldset.cds--cc--legend-fieldset');
|
|
30530
|
+
container
|
|
30531
|
+
.querySelectorAll('fieldset.cds--cc--legend-fieldset')
|
|
30532
|
+
.forEach(function (fieldset) {
|
|
30533
|
+
if (fieldset !== closestFieldset) {
|
|
30534
|
+
unwrapFieldset(fieldset);
|
|
30535
|
+
}
|
|
30536
|
+
});
|
|
30537
|
+
if (closestFieldset) {
|
|
30538
|
+
var existingCaption = closestFieldset.querySelector(':scope > legend');
|
|
30507
30539
|
if (existingCaption && existingCaption.textContent !== legendLabel) {
|
|
30508
30540
|
existingCaption.textContent = legendLabel;
|
|
30509
30541
|
}
|
|
@@ -30518,9 +30550,58 @@
|
|
|
30518
30550
|
};
|
|
30519
30551
|
wrapLegend();
|
|
30520
30552
|
var observer = new MutationObserver(wrapLegend);
|
|
30521
|
-
observer.observe(container, {
|
|
30553
|
+
observer.observe(container, {
|
|
30554
|
+
childList: true,
|
|
30555
|
+
subtree: true,
|
|
30556
|
+
attributes: true,
|
|
30557
|
+
attributeFilter: ['role', 'aria-label'],
|
|
30558
|
+
});
|
|
30522
30559
|
return function () { return observer.disconnect(); };
|
|
30523
30560
|
}, [legendLabel]);
|
|
30561
|
+
React__default__namespace.useEffect(function () {
|
|
30562
|
+
var container = internalRef.current;
|
|
30563
|
+
if (!container || !isMacOS || !isChrome)
|
|
30564
|
+
return;
|
|
30565
|
+
var announceTimer;
|
|
30566
|
+
var alternateSuffix = false;
|
|
30567
|
+
var closestLegend = function (node) {
|
|
30568
|
+
return node instanceof Element ? node.closest('.cds--cc--legend') : null;
|
|
30569
|
+
};
|
|
30570
|
+
var handleFocusIn = function (event) {
|
|
30571
|
+
var enteredLegend = closestLegend(event.target);
|
|
30572
|
+
var cameFromLegend = closestLegend(event.relatedTarget);
|
|
30573
|
+
if (enteredLegend && !cameFromLegend) {
|
|
30574
|
+
if (legendGroupAnnounceRef.current) {
|
|
30575
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
30576
|
+
}
|
|
30577
|
+
clearTimeout(announceTimer);
|
|
30578
|
+
announceTimer = setTimeout(function () {
|
|
30579
|
+
if (legendGroupAnnounceRef.current) {
|
|
30580
|
+
alternateSuffix = !alternateSuffix;
|
|
30581
|
+
legendGroupAnnounceRef.current.textContent =
|
|
30582
|
+
legendLabel + (alternateSuffix ? ' ' : '');
|
|
30583
|
+
}
|
|
30584
|
+
}, 250);
|
|
30585
|
+
}
|
|
30586
|
+
};
|
|
30587
|
+
var handleFocusOut = function (event) {
|
|
30588
|
+
var leftLegend = closestLegend(event.target) && !closestLegend(event.relatedTarget);
|
|
30589
|
+
// Reset once focus leaves the legend so re-entering announces again.
|
|
30590
|
+
if (leftLegend) {
|
|
30591
|
+
clearTimeout(announceTimer);
|
|
30592
|
+
if (legendGroupAnnounceRef.current) {
|
|
30593
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
30594
|
+
}
|
|
30595
|
+
}
|
|
30596
|
+
};
|
|
30597
|
+
container.addEventListener('focusin', handleFocusIn);
|
|
30598
|
+
container.addEventListener('focusout', handleFocusOut);
|
|
30599
|
+
return function () {
|
|
30600
|
+
clearTimeout(announceTimer);
|
|
30601
|
+
container.removeEventListener('focusin', handleFocusIn);
|
|
30602
|
+
container.removeEventListener('focusout', handleFocusOut);
|
|
30603
|
+
};
|
|
30604
|
+
}, [isMacOS, isChrome, legendLabel]);
|
|
30524
30605
|
var handleModalDownloadCsv = React__default__namespace.useCallback(function () {
|
|
30525
30606
|
downloadCsv(dataSet, chartTitle);
|
|
30526
30607
|
}, [dataSet, chartTitle]);
|
|
@@ -30605,6 +30686,17 @@
|
|
|
30605
30686
|
activeLabels.push(((_a = label.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
30606
30687
|
}
|
|
30607
30688
|
});
|
|
30689
|
+
// Carbon re-applies aria-checked (with the same values) on every
|
|
30690
|
+
// render, which still triggers this observer. Only announce when the
|
|
30691
|
+
// selection actually changed, otherwise unrelated re-renders (e.g.
|
|
30692
|
+
// the legend group announcement) cause phantom announcements.
|
|
30693
|
+
var selectionSignature = "".concat(activeLabels.join('|'), "::").concat(allItems.length);
|
|
30694
|
+
if (selectionSignatureRef.current === selectionSignature)
|
|
30695
|
+
return;
|
|
30696
|
+
var isFirstRun = selectionSignatureRef.current === undefined;
|
|
30697
|
+
selectionSignatureRef.current = selectionSignature;
|
|
30698
|
+
if (isFirstRun)
|
|
30699
|
+
return;
|
|
30608
30700
|
if (activeLabels.length === 1) {
|
|
30609
30701
|
if (!legendAnnouncedRef.current) {
|
|
30610
30702
|
legendAnnouncedRef.current = true;
|
|
@@ -30621,6 +30713,7 @@
|
|
|
30621
30713
|
}
|
|
30622
30714
|
});
|
|
30623
30715
|
observer.observe(wrapper, {
|
|
30716
|
+
childList: true,
|
|
30624
30717
|
subtree: true,
|
|
30625
30718
|
attributes: true,
|
|
30626
30719
|
attributeFilter: ['aria-checked'],
|
|
@@ -30632,6 +30725,8 @@
|
|
|
30632
30725
|
return (React__default__namespace.createElement(FullscreenRoot, { ref: mergedRef, isInverse: isInverse, theme: theme },
|
|
30633
30726
|
React__default__namespace.createElement(VisuallyHidden, null,
|
|
30634
30727
|
React__default__namespace.createElement(Announce, null, legendAnnouncement)),
|
|
30728
|
+
React__default__namespace.createElement(VisuallyHidden, null,
|
|
30729
|
+
React__default__namespace.createElement("div", { "aria-live": "polite", ref: legendGroupAnnounceRef })),
|
|
30635
30730
|
React__default__namespace.createElement(CarbonChartWrapper, __assign({ "data-testid": testId, isInverse: isInverse, theme: theme, className: "carbon-chart-wrapper".concat(chartToolbar ? ' has-magma-toolbar' : ''), groupsLength: groupsLength < 6 ? groupsLength : 14, role: "region", "aria-label": ariaLabel || chartTitle, "aria-roledescription": "chart" }, rest),
|
|
30636
30731
|
React__default__namespace.createElement(ChartContentWrapper, null,
|
|
30637
30732
|
chartToolbar && (React__default__namespace.createElement(CarbonChartToolbar, { config: chartToolbar, dataSet: dataSet, isInverse: isInverse, isTableOpen: isTableOpen, isFullscreen: isFullscreen, onOpenTable: openTableModal, onToggleFullscreen: toggleFullscreen, theme: theme, title: chartTitle, wrapperRef: internalRef })),
|