Skip to content

Commit 35e1420

Browse files
authored
fix(AnalyticalTable): allow typing SPACE in custom cell content (#6881)
Previously this was only possible by calling `event.stopPropagation()` in the respective handler.
1 parent 9bf0e7c commit 35e1420

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { useManualRowSelect } from './pluginHooks/useManualRowSelect';
2626
import { useRowDisableSelection } from './pluginHooks/useRowDisableSelection';
2727
import { cssVarToRgb, cypressPassThroughTestsFactory } from '@/cypress/support/utils';
28+
import type { RowType } from '@/packages/main/src/components/AnalyticalTable/types/index.js';
2829
import { getUi5TagWithSuffix } from '@/packages/main/src/internal/utils.js';
2930

3031
const generateMoreData = (count) => {
@@ -3416,6 +3417,78 @@ describe('AnalyticalTable', () => {
34163417
cy.get('[data-component-name="ATHeaderPopover"]').should('not.exist');
34173418
});
34183419

3420+
it('Interactive Cell content', () => {
3421+
const columns: AnalyticalTableColumnDefinition[] = [
3422+
{ Header: 'Name', accessor: 'name' },
3423+
{
3424+
Header: 'Custom',
3425+
id: 'custom',
3426+
Cell: ({ row }: { row: RowType }) => {
3427+
switch (row.index) {
3428+
case 0:
3429+
return <Input />;
3430+
case 1:
3431+
return (
3432+
<Button
3433+
onClick={() => {
3434+
document.querySelector('[data-testid="btn-was-clicked"]').textContent = 'true';
3435+
}}
3436+
>
3437+
Click
3438+
</Button>
3439+
);
3440+
default:
3441+
return <Input />;
3442+
}
3443+
}
3444+
}
3445+
];
3446+
const TestComp = () => {
3447+
const [selected, setSelected] = useState({});
3448+
return (
3449+
<>
3450+
<AnalyticalTable
3451+
data={data}
3452+
columns={columns}
3453+
selectionMode="Multiple"
3454+
onRowSelect={(e) => {
3455+
setSelected(e.detail.selectedRowIds);
3456+
}}
3457+
/>
3458+
<span data-testid="sel">{JSON.stringify(selected)}</span>
3459+
<span data-testid="btn-was-clicked" />
3460+
</>
3461+
);
3462+
};
3463+
cy.mount(<TestComp />);
3464+
// for some reason only required for React18
3465+
cy.wait(300);
3466+
3467+
// Pressing SPACE inside input components should work
3468+
// Focus: (1,0) -> (col, row)
3469+
cy.realPress('Tab');
3470+
// (1,1)
3471+
cy.realPress('ArrowDown');
3472+
cy.focused().realPress('Space');
3473+
cy.findByTestId('sel').should('have.text', '{"0":true}');
3474+
// (2,1)
3475+
cy.realPress('ArrowRight');
3476+
cy.focused().realPress('Space');
3477+
cy.findByTestId('sel').should('have.text', '{}');
3478+
// Focus: Input (2,1)
3479+
cy.realPress('Tab');
3480+
cy.focused().type('3Spaces 2Spaces ');
3481+
cy.focused().should('have.value', '3Spaces 2Spaces ');
3482+
cy.findByTestId('sel').should('have.text', '{}');
3483+
// (2,2)
3484+
cy.realPress('ArrowDown');
3485+
// Focus: Button (2,2)
3486+
cy.realPress('Tab');
3487+
cy.focused().realPress('Space');
3488+
cy.findByTestId('sel').should('have.text', '{}');
3489+
cy.findByTestId('btn-was-clicked').should('have.text', 'true');
3490+
});
3491+
34193492
cypressPassThroughTestsFactory(AnalyticalTable, { data, columns });
34203493
});
34213494

packages/main/src/components/AnalyticalTable/hooks/useSingleRowStateSelection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ const getRowProps = (rowProps, { row, instance }: { row: RowType; instance: Tabl
6565
}
6666
handleRowSelect(e);
6767
}
68-
if (e.code === 'Space') {
68+
69+
// only prevent the default behavior if event was invoked in cell (not e.g. Input)
70+
if (e.code === 'Space' && e.target.role === 'gridcell') {
6971
e.preventDefault();
7072
}
7173
};

0 commit comments

Comments
 (0)