Skip to content

Commit 980449e

Browse files
authored
fix(AnalyticalTable): restore focus when ungrouping a column (#7299)
Fixes #7284
1 parent e8b3e14 commit 980449e

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,11 @@ describe('AnalyticalTable', () => {
874874

875875
cy.findByText('Friend Name').click();
876876
cy.findByText('Group').realClick();
877+
cy.focused()
878+
.should('have.attr', 'data-row-index', '0')
879+
.and('have.attr', 'data-column-index', '2')
880+
.and('have.text', 'Friend Name');
881+
877882
cy.get('[aria-rowindex="7"] > [aria-colindex="3"] > [title="Expand Node"] > [ui5-icon]').click();
878883

879884
cy.findByText('25').click();
@@ -887,6 +892,13 @@ describe('AnalyticalTable', () => {
887892
cy.findByTestId('selectedFlatRowsLength').should('have.text', '1');
888893
cy.findByTestId('selectedRowIds').should('have.text', '{"2":true}');
889894
cy.findByTestId('isSelected').should('have.text', 'false');
895+
896+
cy.findByText('Friend Name').click();
897+
cy.findByText('Ungroup').realClick();
898+
cy.focused()
899+
.should('have.attr', 'data-row-index', '0')
900+
.and('have.attr', 'data-column-index', '3')
901+
.and('have.text', 'Friend Name');
890902
});
891903

892904
it('useIndeterminateRowSelection - select subRows', () => {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import iconFilter from '@ui5/webcomponents-icons/dist/filter.js';
55
import iconGroup from '@ui5/webcomponents-icons/dist/group-2.js';
66
import iconSortAscending from '@ui5/webcomponents-icons/dist/sort-ascending.js';
77
import iconSortDescending from '@ui5/webcomponents-icons/dist/sort-descending.js';
8-
import { ThemingParameters } from '@ui5/webcomponents-react-base';
8+
import { ThemingParameters, useIsomorphicLayoutEffect } from '@ui5/webcomponents-react-base';
99
import { clsx } from 'clsx';
1010
import type {
1111
AriaAttributes,
@@ -163,6 +163,16 @@ export const ColumnHeader = (props: ColumnHeaderProps) => {
163163
}
164164
};
165165

166+
// restore focus after grouping to header cell
167+
const prevIsGrouped = useRef(null);
168+
useIsomorphicLayoutEffect(() => {
169+
const prevOpener = columnHeaderRef.current;
170+
if (column.canGroupBy && prevIsGrouped.current && !popoverOpen && prevOpener) {
171+
(prevOpener.children[0] as HTMLDivElement).focus();
172+
}
173+
prevIsGrouped.current = column.isGrouped;
174+
}, [popoverOpen]);
175+
166176
if (!column) return null;
167177
return (
168178
<div
@@ -174,6 +184,7 @@ export const ColumnHeader = (props: ColumnHeaderProps) => {
174184
width: `${virtualColumn.size}px`,
175185
...directionStyles
176186
}}
187+
data-component-name={`ATHeaderContainer-${columnId}`}
177188
>
178189
<div
179190
ref={columnVirtualizer.measureElement}

packages/main/src/components/AnalyticalTable/defaults/Column/ColumnHeaderModal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Icon } from '../../../../webComponents/Icon/index.js';
2626
import { List } from '../../../../webComponents/List/index.js';
2727
import { ListItemCustom } from '../../../../webComponents/ListItemCustom/index.js';
2828
import { ListItemStandard } from '../../../../webComponents/ListItemStandard/index.js';
29-
import type { PopoverDomRef } from '../../../../webComponents/Popover/index.js';
29+
import type { PopoverDomRef, PopoverPropTypes } from '../../../../webComponents/Popover/index.js';
3030
import { Popover } from '../../../../webComponents/Popover/index.js';
3131
import { Text } from '../../../../webComponents/Text/index.js';
3232
import { FlexBox } from '../../../FlexBox/index.js';
@@ -128,7 +128,7 @@ export const ColumnHeaderModal = (instance: TableInstanceWithPopoverProps) => {
128128
const isSortedAscending = column.isSorted && column.isSortedDesc === false;
129129
const isSortedDescending = column.isSorted && column.isSortedDesc === true;
130130

131-
const onAfterClose = (e) => {
131+
const onAfterClose: PopoverPropTypes['onClose'] = (e) => {
132132
stopPropagation(e);
133133
setOpen(false);
134134
};
@@ -167,13 +167,13 @@ export const ColumnHeaderModal = (instance: TableInstanceWithPopoverProps) => {
167167
};
168168

169169
useEffect(() => {
170-
if (open && ref.current && openerRef.current) {
170+
if (ref.current && openerRef.current) {
171171
void customElements.whenDefined(getUi5TagWithSuffix('ui5-popover')).then(() => {
172172
ref.current.opener = openerRef.current;
173173
ref.current.open = true;
174174
});
175175
}
176-
}, [open]);
176+
}, []);
177177

178178
return (
179179
<Popover

0 commit comments

Comments
 (0)