Skip to content

fix(AnalyticalTable): restore focus when ungrouping a column #7299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,11 @@ describe('AnalyticalTable', () => {

cy.findByText('Friend Name').click();
cy.findByText('Group').realClick();
cy.focused()
.should('have.attr', 'data-row-index', '0')
.and('have.attr', 'data-column-index', '2')
.and('have.text', 'Friend Name');

cy.get('[aria-rowindex="7"] > [aria-colindex="3"] > [title="Expand Node"] > [ui5-icon]').click();

cy.findByText('25').click();
Expand All @@ -887,6 +892,13 @@ describe('AnalyticalTable', () => {
cy.findByTestId('selectedFlatRowsLength').should('have.text', '1');
cy.findByTestId('selectedRowIds').should('have.text', '{"2":true}');
cy.findByTestId('isSelected').should('have.text', 'false');

cy.findByText('Friend Name').click();
cy.findByText('Ungroup').realClick();
cy.focused()
.should('have.attr', 'data-row-index', '0')
.and('have.attr', 'data-column-index', '3')
.and('have.text', 'Friend Name');
});

it('useIndeterminateRowSelection - select subRows', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import iconFilter from '@ui5/webcomponents-icons/dist/filter.js';
import iconGroup from '@ui5/webcomponents-icons/dist/group-2.js';
import iconSortAscending from '@ui5/webcomponents-icons/dist/sort-ascending.js';
import iconSortDescending from '@ui5/webcomponents-icons/dist/sort-descending.js';
import { ThemingParameters } from '@ui5/webcomponents-react-base';
import { ThemingParameters, useIsomorphicLayoutEffect } from '@ui5/webcomponents-react-base';
import { clsx } from 'clsx';
import type {
AriaAttributes,
Expand Down Expand Up @@ -163,6 +163,16 @@ export const ColumnHeader = (props: ColumnHeaderProps) => {
}
};

// restore focus after grouping to header cell
const prevIsGrouped = useRef(null);
useIsomorphicLayoutEffect(() => {
const prevOpener = columnHeaderRef.current;
if (column.canGroupBy && prevIsGrouped.current && !popoverOpen && prevOpener) {
(prevOpener.children[0] as HTMLDivElement).focus();
}
prevIsGrouped.current = column.isGrouped;
}, [popoverOpen]);

if (!column) return null;
return (
<div
Expand All @@ -174,6 +184,7 @@ export const ColumnHeader = (props: ColumnHeaderProps) => {
width: `${virtualColumn.size}px`,
...directionStyles
}}
data-component-name={`ATHeaderContainer-${columnId}`}
>
<div
ref={columnVirtualizer.measureElement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Icon } from '../../../../webComponents/Icon/index.js';
import { List } from '../../../../webComponents/List/index.js';
import { ListItemCustom } from '../../../../webComponents/ListItemCustom/index.js';
import { ListItemStandard } from '../../../../webComponents/ListItemStandard/index.js';
import type { PopoverDomRef } from '../../../../webComponents/Popover/index.js';
import type { PopoverDomRef, PopoverPropTypes } from '../../../../webComponents/Popover/index.js';
import { Popover } from '../../../../webComponents/Popover/index.js';
import { Text } from '../../../../webComponents/Text/index.js';
import { FlexBox } from '../../../FlexBox/index.js';
Expand Down Expand Up @@ -128,7 +128,7 @@ export const ColumnHeaderModal = (instance: TableInstanceWithPopoverProps) => {
const isSortedAscending = column.isSorted && column.isSortedDesc === false;
const isSortedDescending = column.isSorted && column.isSortedDesc === true;

const onAfterClose = (e) => {
const onAfterClose: PopoverPropTypes['onClose'] = (e) => {
stopPropagation(e);
setOpen(false);
};
Expand Down Expand Up @@ -167,13 +167,13 @@ export const ColumnHeaderModal = (instance: TableInstanceWithPopoverProps) => {
};

useEffect(() => {
if (open && ref.current && openerRef.current) {
if (ref.current && openerRef.current) {
void customElements.whenDefined(getUi5TagWithSuffix('ui5-popover')).then(() => {
ref.current.opener = openerRef.current;
ref.current.open = true;
});
}
}, [open]);
}, []);

return (
<Popover
Expand Down
Loading