Skip to content

Commit bb8f4d1

Browse files
committed
fix no-data rtl
1 parent 413840d commit bb8f4d1

File tree

4 files changed

+16
-39
lines changed

4 files changed

+16
-39
lines changed

src/core/chart-api/chart-extra-nodata.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,21 @@ import type Highcharts from "highcharts";
66
import AsyncStore from "../../internal/utils/async-store";
77
import { ChartExtraContext } from "./chart-extra-context";
88

9-
import styles from "../styles.css.js";
10-
119
// The reactive state is used to propagate updates to the corresponding no-data React component.
1210
// It can be used by other components to assert if the chart is in no-data state (by checking if container is present).
1311
export interface ReactiveNodataState {
14-
container: null | Element;
12+
visible: boolean;
13+
style: React.CSSProperties;
1514
noMatch: boolean;
1615
}
1716

1817
// Chart helper that implements custom nodata behaviors.
1918
export class ChartExtraNodata extends AsyncStore<ReactiveNodataState> {
2019
private context: ChartExtraContext;
21-
private noDataContainer: HTMLElement;
2220

2321
constructor(context: ChartExtraContext) {
24-
super({ container: null, noMatch: false });
22+
super({ visible: false, style: {}, noMatch: false });
2523
this.context = context;
26-
this.noDataContainer = document.createElement("div");
27-
this.noDataContainer.className = styles["no-data-container"];
2824
}
2925

3026
public onChartRender = () => {
@@ -35,26 +31,14 @@ export class ChartExtraNodata extends AsyncStore<ReactiveNodataState> {
3531
const visibleSeries = findAllVisibleSeries(this.chart);
3632
// The no-data is not shown when there is at least one series or point (for pie series) non-empty and visible.
3733
if (visibleSeries.length > 0) {
38-
this.removeContainer();
39-
this.set(() => ({ container: null, noMatch: false }));
34+
this.set(() => ({ visible: false, style: {}, noMatch: false }));
4035
} else {
41-
this.appendContainer();
42-
this.set(() => ({ container: this.noDataContainer, noMatch: allSeriesWithData.length > 0 }));
36+
this.set(() => ({ visible: true, style: this.getContainerStyle(), noMatch: allSeriesWithData.length > 0 }));
4337
}
4438
};
4539

46-
private appendContainer() {
47-
if (!this.chart.container.contains(this.noDataContainer)) {
48-
this.chart.container.appendChild(this.noDataContainer);
49-
}
50-
this.noDataContainer.style.left = `${this.chart.plotLeft}px`;
51-
this.noDataContainer.style.bottom = `${this.chart.chartHeight - this.chart.plotHeight}px`;
52-
}
53-
54-
private removeContainer() {
55-
if (this.chart.container.contains(this.noDataContainer)) {
56-
this.chart.container.removeChild(this.noDataContainer);
57-
}
40+
private getContainerStyle() {
41+
return { left: `${this.chart.plotLeft}px`, bottom: `${this.chart.chartHeight - this.chart.plotHeight}px` };
5842
}
5943

6044
private get chart() {

src/core/components/core-application.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function ChartApplication({
1616
keyboardNavigation: boolean;
1717
ariaLabel?: string;
1818
}) {
19-
const hasData = useSelector(api.nodataStore, (s) => !s.container);
19+
const hasData = useSelector(api.nodataStore, (s) => !s.visible);
2020
return keyboardNavigation && hasData ? (
2121
// Do not remove the empty outer div. It is used to contain the application element to perform
2222
// focus juggling, necessary to trigger a screen-reader announcement.

src/core/components/core-no-data.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import clsx from "clsx";
55

6-
import { Portal } from "@cloudscape-design/component-toolkit/internal";
76
import Button from "@cloudscape-design/components/button";
87
import { useInternalI18n } from "@cloudscape-design/components/internal/do-not-use/i18n";
98
import LiveRegion from "@cloudscape-design/components/live-region";
@@ -32,7 +31,7 @@ export function ChartNoData({
3231
i18nStrings?: BaseI18nStrings;
3332
}) {
3433
const state = useSelector(api.nodataStore, (s) => s);
35-
if (!state.container) {
34+
if (!state.visible) {
3635
return null;
3736
}
3837
let content = null;
@@ -55,15 +54,13 @@ export function ChartNoData({
5554
}
5655
return (
5756
content && (
58-
<Portal container={state.container}>
57+
<div className={styles["no-data-container"]} style={state.style}>
5958
<div className={styles["no-data-wrapper"]}>
6059
<div className={clsx(testClasses["no-data"], styles["no-data"])}>
61-
<div className={styles["no-data-content"]}>
62-
<LiveRegion>{content}</LiveRegion>
63-
</div>
60+
<LiveRegion>{content}</LiveRegion>
6461
</div>
6562
</div>
66-
</Portal>
63+
</div>
6764
)
6865
);
6966
}

src/core/styles.scss

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ $side-legend-min-inline-size: max(20%, 150px);
2929
}
3030

3131
.no-data {
32-
overflow: hidden;
32+
overflow-x: auto;
33+
overflow-y: hidden;
34+
padding-block: cs.$space-static-xs;
35+
padding-inline: cs.$space-static-m;
3336
background-color: cs.$color-background-container-content;
3437
border-radius: 8px;
3538
border: 1px solid cs.$color-border-divider-default;
@@ -47,13 +50,6 @@ $side-legend-min-inline-size: max(20%, 150px);
4750
color: cs.$color-text-empty;
4851
}
4952

50-
.no-data-content {
51-
overflow-x: auto;
52-
overflow-y: hidden;
53-
padding-block: cs.$space-static-xs;
54-
padding-inline: cs.$space-static-m;
55-
}
56-
5753
.chart-filters {
5854
padding-block-end: cs.$space-scaled-l;
5955

0 commit comments

Comments
 (0)