Skip to content

Run tests in FF #3772

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Build website
run: node --run build:website
- name: Install Playwright Browsers
run: npx playwright install chromium
run: npx playwright install chromium firefox
- name: Test
run: node --run test
timeout-minutes: 4
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@typescript-eslint/parser": "^8.29.0",
"@vitejs/plugin-react": "^4.4.1",
"@vitest/browser": "^3.1.2",
"@vitest/coverage-v8": "^3.1.2",
"@vitest/coverage-istanbul": "^3.1.2",
"@vitest/eslint-plugin": "^1.1.43",
"@wyw-in-js/rollup": "^0.6.0",
"@wyw-in-js/vite": "^0.6.0",
Expand Down
21 changes: 17 additions & 4 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
const selectedCellIsWithinViewportBounds = isCellWithinViewportBounds(selectedPosition);
const scrollHeight =
headerRowHeight + totalRowHeight + summaryRowsHeight + horizontalScrollbarHeight;
const shouldFocusGrid = !selectedCellIsWithinSelectionBounds;

/**
* The identity of the wrapper function is stable so it won't break memoization
Expand All @@ -499,9 +500,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
const selectRowLatest = useLatestFunc(selectRow);
const handleFormatterRowChangeLatest = useLatestFunc(updateRow);
const selectCellLatest = useLatestFunc(selectCell);
const selectHeaderCellLatest = useLatestFunc(({ idx, rowIdx }: Position) => {
selectCell({ rowIdx: minRowIdx + rowIdx - 1, idx });
});
const selectHeaderCellLatest = useLatestFunc(selectHeaderCell);

/**
* callbacks
Expand Down Expand Up @@ -661,6 +660,13 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
}
}

function handleFocus(event: React.FocusEvent<HTMLDivElement>) {
// select the first header cell if the focus event is triggered by the grid
if (event.target === event.currentTarget) {
selectHeaderCell({ idx: 0, rowIdx: headerRowsCount });
}
}

function handleScroll(event: React.UIEvent<HTMLDivElement>) {
const { scrollTop, scrollLeft } = event.currentTarget;
flushSync(() => {
Expand Down Expand Up @@ -867,6 +873,10 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
}
}

function selectHeaderCell({ idx, rowIdx }: Position) {
selectCell({ rowIdx: minRowIdx + rowIdx - 1, idx });
}

function getNextPosition(key: string, ctrlKey: boolean, shiftKey: boolean): Position {
const { idx, rowIdx } = selectedPosition;
const isRowSelected = selectedCellIsWithinSelectionBounds && idx === -1;
Expand Down Expand Up @@ -1185,6 +1195,9 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
aria-multiselectable={isSelectable ? true : undefined}
aria-colcount={columns.length}
aria-rowcount={ariaRowCount}
// Scrollable containers without tabIndex are keyboard focusable in Chrome only if there is no focusable element inside
// whereas they are are always focusable in Firefox. We need to set tabIndex to have a consistent behavior across browsers.
tabIndex={shouldFocusGrid ? 0 : -1}
className={clsx(
rootClassname,
{
Expand Down Expand Up @@ -1216,6 +1229,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
}
dir={direction}
ref={gridRef}
onFocus={shouldFocusGrid ? handleFocus : undefined}
onScroll={handleScroll}
onKeyDown={handleKeyDown}
onCopy={handleCellCopy}
Expand Down Expand Up @@ -1252,7 +1266,6 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
selectedPosition.rowIdx === mainHeaderRowIdx ? selectedPosition.idx : undefined
}
selectCell={selectHeaderCellLatest}
shouldFocusGrid={!selectedCellIsWithinSelectionBounds}
direction={direction}
/>
</HeaderRowSelectionContext>
Expand Down
15 changes: 2 additions & 13 deletions src/HeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ type SharedHeaderRowProps<R, SR> = Pick<
| 'selectCell'
| 'onColumnResize'
| 'onColumnResizeEnd'
| 'shouldFocusGrid'
| 'direction'
| 'onColumnsReorder'
>;
Expand All @@ -85,7 +84,6 @@ export default function HeaderCell<R, SR>({
sortColumns,
onSortColumnsChange,
selectCell,
shouldFocusGrid,
direction,
dragDropKey
}: HeaderCellProps<R, SR>) {
Expand Down Expand Up @@ -155,14 +153,6 @@ export default function HeaderCell<R, SR>({
}
}

function handleFocus(event: React.FocusEvent<HTMLDivElement>) {
onFocus?.(event);
if (shouldFocusGrid) {
// Select the first header cell if there is no selected cell
selectCell({ idx: 0, rowIdx });
}
}

function onKeyDown(event: React.KeyboardEvent<HTMLSpanElement>) {
const { key } = event;
if (sortable && (key === ' ' || key === 'Enter')) {
Expand Down Expand Up @@ -254,14 +244,13 @@ export default function HeaderCell<R, SR>({
aria-rowspan={rowSpan}
aria-selected={isCellSelected}
aria-sort={ariaSort}
// set the tabIndex to 0 when there is no selected cell so grid can receive focus
tabIndex={shouldFocusGrid ? 0 : tabIndex}
tabIndex={tabIndex}
className={className}
style={{
...getHeaderCellStyle(column, rowIdx, rowSpan),
...getCellStyle(column, colSpan)
}}
onFocus={handleFocus}
onFocus={onFocus}
onClick={onClick}
onKeyDown={onKeyDown}
{...draggableProps}
Expand Down
3 changes: 0 additions & 3 deletions src/HeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface HeaderRowProps<R, SR, K extends React.Key> extends SharedDataGr
selectCell: (position: Position) => void;
lastFrozenColumnIndex: number;
selectedCellIdx: number | undefined;
shouldFocusGrid: boolean;
direction: Direction;
headerRowClass: Maybe<string>;
}
Expand Down Expand Up @@ -59,7 +58,6 @@ function HeaderRow<R, SR, K extends React.Key>({
lastFrozenColumnIndex,
selectedCellIdx,
selectCell,
shouldFocusGrid,
direction
}: HeaderRowProps<R, SR, K>) {
const dragDropKey = useId();
Expand All @@ -85,7 +83,6 @@ function HeaderRow<R, SR, K extends React.Key>({
onSortColumnsChange={onSortColumnsChange}
sortColumns={sortColumns}
selectCell={selectCell}
shouldFocusGrid={shouldFocusGrid && index === 0}
direction={direction}
dragDropKey={dragDropKey}
/>
Expand Down
11 changes: 6 additions & 5 deletions test/browser/column/renderEditCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Editor', () => {
await userEvent.keyboard('2');
await userEvent.tab();
await expect.element(editor).not.toBeInTheDocument();
expect(getCellsAtRowIndex(0)[0]).toHaveTextContent(/^12$/);
expect(getCellsAtRowIndex(0)[0]).toHaveTextContent(12);
});

it('should open and commit changes on enter', async () => {
Expand All @@ -42,7 +42,7 @@ describe('Editor', () => {
page.render(<EditorTest />);
await userEvent.click(getCellsAtRowIndex(0)[0]);
await userEvent.keyboard('123{enter}');
expect(getCellsAtRowIndex(0)[0]).toHaveTextContent(/^1123$/);
expect(getCellsAtRowIndex(0)[0]).toHaveTextContent('123');
});

it('should close editor and discard changes on escape', async () => {
Expand Down Expand Up @@ -99,7 +99,8 @@ describe('Editor', () => {
const editor = page.getByRole('spinbutton', { name: 'col1-editor' });
await expect.element(editor).not.toBeInTheDocument();
expect(getGrid().element().scrollTop).toBe(2000);
await userEvent.keyboard('123');
// `1{backspace}` is needed to fix tests in FF
await userEvent.keyboard('1{backspace}123');
expect(getCellsAtRowIndex(0)).toHaveLength(2);
await expect.element(editor).toHaveValue(123);
expect(getGrid().element().scrollTop).toBe(0);
Expand Down Expand Up @@ -193,9 +194,9 @@ describe('Editor', () => {
}}
/>
);
await userEvent.click(getCellsAtRowIndex(0)[1]);
await userEvent.dblClick(getCellsAtRowIndex(0)[1]);
await userEvent.keyboard('yz{enter}');
expect(getCellsAtRowIndex(0)[1]).toHaveTextContent(/^a1yz$/);
expect(getCellsAtRowIndex(0)[1]).toHaveTextContent('yz');
await userEvent.keyboard('x');
await expect
.element(page.getByRole('textbox', { name: 'col2-editor' }))
Expand Down
4 changes: 3 additions & 1 deletion test/browser/dragFill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ test('should update single row using mouse', async () => {
await commands.dragFill('a1', 'a2');
await expect.element(getCellsAtRowIndex(1)[0]).toHaveTextContent('a1');
await expect.element(getCellsAtRowIndex(2)[0]).toHaveTextContent('a3');
await expect.element(getCellsAtRowIndex(0)[0]).toHaveFocus();
// https://bugzilla.mozilla.org/show_bug.cgi?id=1961462
const rowIdx = navigator.userAgent.includes('Firefox') ? 1 : 0;
await expect.element(getCellsAtRowIndex(rowIdx)[0]).toHaveFocus();
});

test('should update multiple rows using mouse', async () => {
Expand Down
11 changes: 6 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,15 @@ export default defineConfig(({ command }) => ({
server: {
open: true
},
optimizeDeps: {
include: ['@vitest/coverage-v8/browser']
},
test: {
globals: true,
coverage: {
provider: 'v8',
provider: 'istanbul',
enabled: isCI,
include: ['src/**/*.{ts,tsx}'],
reporter: ['json']
},
testTimeout: isCI ? 10000 : 5000,
testTimeout: 20_000,
restoreMocks: true,
sequence: {
shuffle: true
Expand All @@ -102,6 +99,10 @@ export default defineConfig(({ command }) => ({
{
browser: 'chromium',
context: { viewport }
},
{
browser: 'firefox',
context: { viewport }
}
],
commands: { resizeColumn, dragFill },
Expand Down
Loading