mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-06 16:01:00 +00:00
fix(table): dispatch Home and End from the focused row
Focusing the row in capture left the original event on the cell path, allowing competing grid handling in Firefox. Cancel that event and redispatch from the row, following React Aria cell navigation. Settle pointer selection before explicitly focusing the test control and expose an optional Firefox project.
This commit is contained in:
1 parent
fffa93ab37
commit
36015d043b
3 files changed
+14
-5
No files matched your search
@@ -92,7 +92,10 @@ test('Home and End move between rows from a control inside a cell', async ({page
|
||||
const grid = page.getByRole('grid', {name: 'Connections'});
|
||||
const focusedRow = grid.locator('[role=row]:focus');
|
||||
const inCell = grid.locator(':is([role=rowheader], [role=gridcell]) :focus');
|
||||
await grid.locator('[data-key="c-0002"]').getByRole('gridcell').nth(1).click();
|
||||
const cell = grid.locator('[data-key="c-0002"]').getByRole('gridcell').nth(1);
|
||||
await cell.click();
|
||||
await expect(grid.locator('[data-key="c-0002"]')).toHaveAttribute('aria-selected', 'true');
|
||||
await cell.locator('.rp-truncate').focus();
|
||||
await expect(inCell).toHaveCount(1);
|
||||
await page.keyboard.press('End');
|
||||
await expect(focusedRow).toHaveAttribute('aria-rowindex', '1001');
|
||||
|
||||
@@ -22,6 +22,7 @@ export default defineConfig({
|
||||
projects: [
|
||||
{name: 'chromium', testIgnore: 'subpath.spec.ts', use: {...devices['Desktop Chrome']}},
|
||||
{name: 'subpath', testMatch: 'subpath.spec.ts', use: {...devices['Desktop Chrome'], baseURL: 'http://127.0.0.1:4186'}},
|
||||
...(process.env.DOONA_E2E_FIREFOX === '1' ? [{name: 'firefox', testMatch: 'connections.spec.ts', use: {...devices['Desktop Firefox']}}] : []),
|
||||
...(webkit
|
||||
? [
|
||||
// Safari carries the installed iOS app: a smoke pass over navigation, drag and drop, dialogs and the keyboard.
|
||||
|
||||
+9
-4
@@ -340,16 +340,21 @@ export function DataTable<T extends {id: string}>({
|
||||
data-row-detail={rowDetail || detail ? '' : undefined}
|
||||
style={{height: fitted}}
|
||||
// RAC (1.21) keeps Home/End inside the row while a cell or a control in one has focus, which is where a click on
|
||||
// cut text leaves it. Focusing the row first sends them to the first and last rows instead, as the tree mode
|
||||
// promises. The container passes no key handlers, so a tree renders its own div to catch the key first.
|
||||
// cut text leaves it. Focus the row and re-dispatch there so the cell cannot handle the original event.
|
||||
// The container passes no key handlers, so a tree renders its own div to catch the key first.
|
||||
render={
|
||||
tree
|
||||
? props => (
|
||||
<div
|
||||
{...props}
|
||||
onKeyDownCapture={event => {
|
||||
if (event.key === 'Home' || event.key === 'End')
|
||||
(event.target as HTMLElement).closest<HTMLElement>('[role="row"][data-key]')?.focus({preventScroll: true});
|
||||
if (event.key !== 'Home' && event.key !== 'End') return;
|
||||
const row = (event.target as HTMLElement).closest<HTMLElement>('[role="row"][data-key]');
|
||||
if (!row || event.target === row) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
row.focus({preventScroll: true});
|
||||
row.dispatchEvent(new KeyboardEvent(event.nativeEvent.type, event.nativeEvent));
|
||||
}}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user