Skip to content

Commit 3f74ca4

Browse files
committed
AnalyticalTable: use portals
1 parent e8bb96d commit 3f74ca4

File tree

3 files changed

+1072
-2504
lines changed

3 files changed

+1072
-2504
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.test.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createPassThroughPropsTest } from '@shared/tests/utils';
2-
import { act, render } from '@testing-library/react';
2+
import { act, render, screen, fireEvent, cleanStaticAreaAfterEachTest, waitFor } from '@shared/tests';
33
import { AnalyticalTable } from '@ui5/webcomponents-react/lib/AnalyticalTable';
44
import { TableSelectionBehavior } from '@ui5/webcomponents-react/lib/TableSelectionBehavior';
55
import { TableSelectionMode } from '@ui5/webcomponents-react/lib/TableSelectionMode';
@@ -142,24 +142,25 @@ const dataTree = [
142142
];
143143

144144
describe('AnalyticalTable', () => {
145-
test('test Asc desc', () => {
146-
const wrapper = mount(<AnalyticalTable data={data} title={'Test'} columns={columns} />);
145+
cleanStaticAreaAfterEachTest();
147146

148-
expect(wrapper.render()).toMatchSnapshot();
147+
beforeEach(() => {
148+
window = Object.assign(window, { innerWidth: 1440 });
149+
});
149150

150-
// test asc function inside the popover element
151-
let component = wrapper.find('ui5-li').at(1).instance();
152-
// @ts-ignore
153-
component.click();
151+
test('test Asc desc', async () => {
152+
const { asFragment } = render(<AnalyticalTable data={data} title={'Test'} columns={columns} />);
154153

155-
expect(wrapper.render()).toMatchSnapshot();
154+
expect(asFragment()).toMatchSnapshot();
155+
156+
fireEvent.click(screen.getAllByText('Sort Ascending')[0], { bubbles: false });
157+
158+
expect(asFragment()).toMatchSnapshot();
156159

157160
// test desc function inside the popover element
158-
component = wrapper.find('ui5-li').at(0).instance();
159-
// @ts-ignore
160-
component.click();
161+
fireEvent.click(screen.getAllByText('Sort Descending')[0], { bubbles: false });
161162

162-
expect(wrapper.render()).toMatchSnapshot();
163+
expect(asFragment()).toMatchSnapshot();
163164
});
164165

165166
test('Tree Table', () => {

packages/main/src/components/AnalyticalTable/ColumnHeader/ColumnHeaderModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Popover } from '@ui5/webcomponents-react/lib/Popover';
1919
import { PopoverHorizontalAlign } from '@ui5/webcomponents-react/lib/PopoverHorizontalAlign';
2020
import { StandardListItem } from '@ui5/webcomponents-react/lib/StandardListItem';
2121
import React, { CSSProperties, forwardRef, RefObject, useCallback } from 'react';
22+
import { createPortal } from 'react-dom';
2223
import { Ui5PopoverDomRef } from '../../../interfaces/Ui5PopoverDomRef';
2324
import { stopPropagation } from '../../../internal/stopPropagation';
2425
import { ColumnType } from '../types/ColumnType';
@@ -109,7 +110,7 @@ export const ColumnHeaderModal = forwardRef((props: ColumnHeaderModalProperties,
109110
const isSortedAscending = column.isSorted && column.isSortedDesc === false;
110111
const isSortedDescending = column.isSorted && column.isSortedDesc === true;
111112

112-
return (
113+
return createPortal(
113114
<Popover
114115
noArrow
115116
horizontalAlign={PopoverHorizontalAlign.Left}
@@ -158,7 +159,8 @@ export const ColumnHeaderModal = forwardRef((props: ColumnHeaderModalProperties,
158159
</StandardListItem>
159160
)}
160161
</List>
161-
</Popover>
162+
</Popover>,
163+
document.body
162164
);
163165
});
164166
ColumnHeaderModal.displayName = 'ColumnHeaderModal';

0 commit comments

Comments
 (0)