Skip to content

Commit 7e8bcfe

Browse files
committed
fix: resolve lint and CI test compilation errors
1 parent 11a8867 commit 7e8bcfe

2 files changed

Lines changed: 41 additions & 37 deletions

File tree

packages/react-aria/src/grid/useGridCell.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { DOMAttributes, FocusableElement, Key, RefObject } from '@react-types/shared';
14-
import { focusSafely } from '../interactions/focusSafely';
13+
import {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';
14+
import {focusSafely} from '../interactions/focusSafely';
1515
import {
1616
getActiveElement,
1717
getEventTarget,
1818
isFocusWithin,
1919
nodeContains
2020
} from '../utils/shadowdom/DOMFunctions';
21-
import { getFocusableTreeWalker } from '../focus/FocusScope';
22-
import { getScrollParent } from '../utils/getScrollParent';
21+
import {getFocusableTreeWalker} from '../focus/FocusScope';
22+
import {getScrollParent} from '../utils/getScrollParent';
2323
import {
2424
IGridCollection as GridCollection,
2525
GridNode
2626
} from 'react-stately/private/grid/GridCollection';
27-
import { gridMap } from './utils';
28-
import { GridState } from 'react-stately/private/grid/useGridState';
29-
import { isFocusVisible } from '../interactions/useFocusVisible';
30-
import { mergeProps } from '../utils/mergeProps';
31-
import { KeyboardEvent as ReactKeyboardEvent, useRef } from 'react';
32-
import { scrollIntoViewport } from '../utils/scrollIntoView';
33-
import { useLocale } from '../i18n/I18nProvider';
34-
import { useSelectableItem } from '../selection/useSelectableItem';
27+
import {gridMap} from './utils';
28+
import {GridState} from 'react-stately/private/grid/useGridState';
29+
import {isFocusVisible} from '../interactions/useFocusVisible';
30+
import {mergeProps} from '../utils/mergeProps';
31+
import {KeyboardEvent as ReactKeyboardEvent, useRef} from 'react';
32+
import {scrollIntoViewport} from '../utils/scrollIntoView';
33+
import {useLocale} from '../i18n/I18nProvider';
34+
import {useSelectableItem} from '../selection/useSelectableItem';
3535

3636
export interface GridCellProps {
3737
/**
@@ -77,12 +77,12 @@ export function useGridCell<T, C extends GridCollection<T>>(
7777
state: GridState<T, C>,
7878
ref: RefObject<FocusableElement | null>
7979
): GridCellAria {
80-
let { node, isVirtualized, focusMode = 'child', shouldSelectOnPressUp, onAction } = props;
80+
let {node, isVirtualized, focusMode = 'child', shouldSelectOnPressUp, onAction} = props;
8181

82-
let { direction } = useLocale();
82+
let {direction} = useLocale();
8383
let {
8484
keyboardDelegate,
85-
actions: { onCellAction }
85+
actions: {onCellAction}
8686
} = gridMap.get(state)!;
8787

8888
// We need to track the key of the item at the time it was last focused so that we force
@@ -119,7 +119,7 @@ export function useGridCell<T, C extends GridCollection<T>>(
119119
}
120120
};
121121

122-
let { itemProps, isPressed } = useSelectableItem({
122+
let {itemProps, isPressed} = useSelectableItem({
123123
selectionManager: state.selectionManager,
124124
key: node.key,
125125
ref,
@@ -161,7 +161,7 @@ export function useGridCell<T, C extends GridCollection<T>>(
161161
e.stopPropagation();
162162
if (focusable) {
163163
focusSafely(focusable);
164-
scrollIntoViewport(focusable, { containingElement: getScrollParent(ref.current) });
164+
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
165165
} else {
166166
// If there is no next focusable child, then move to the next cell to the left of this one.
167167
// This will be handled by useSelectableCollection. However, if there is no cell to the left
@@ -181,14 +181,14 @@ export function useGridCell<T, C extends GridCollection<T>>(
181181

182182
if (focusMode === 'cell' && direction === 'rtl') {
183183
focusSafely(ref.current);
184-
scrollIntoViewport(ref.current, { containingElement: getScrollParent(ref.current) });
184+
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
185185
} else {
186186
walker.currentNode = ref.current;
187187
focusable =
188188
direction === 'rtl' ? (walker.firstChild() as FocusableElement) : last(walker);
189189
if (focusable) {
190190
focusSafely(focusable);
191-
scrollIntoViewport(focusable, { containingElement: getScrollParent(ref.current) });
191+
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
192192
}
193193
}
194194
}
@@ -208,7 +208,7 @@ export function useGridCell<T, C extends GridCollection<T>>(
208208
e.stopPropagation();
209209
if (focusable) {
210210
focusSafely(focusable);
211-
scrollIntoViewport(focusable, { containingElement: getScrollParent(ref.current) });
211+
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
212212
} else {
213213
let next = keyboardDelegate.getKeyRightOf?.(node.key);
214214
if (next !== node.key) {
@@ -223,14 +223,14 @@ export function useGridCell<T, C extends GridCollection<T>>(
223223

224224
if (focusMode === 'cell' && direction === 'ltr') {
225225
focusSafely(ref.current);
226-
scrollIntoViewport(ref.current, { containingElement: getScrollParent(ref.current) });
226+
scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});
227227
} else {
228228
walker.currentNode = ref.current;
229229
focusable =
230230
direction === 'rtl' ? last(walker) : (walker.firstChild() as FocusableElement);
231231
if (focusable) {
232232
focusSafely(focusable);
233-
scrollIntoViewport(focusable, { containingElement: getScrollParent(ref.current) });
233+
scrollIntoViewport(focusable, {containingElement: getScrollParent(ref.current)});
234234
}
235235
}
236236
}
@@ -257,8 +257,12 @@ export function useGridCell<T, C extends GridCollection<T>>(
257257
let onFocus = (e: any) => {
258258
keyWhenFocused.current = node.key;
259259

260-
// FIX: If focus is moving directly to a specific inner child element
261-
// (like our restored Open Dialog button), update the selection state
260+
// FIX: If focus is moving directly to a specific inner child element
261+
// (like our restored Open Dialog button), update the selection state
262+
// and exit early. Do not call focus(), which resets to the first child.
263+
264+
// FIX: If focus is moving directly to a specific inner child element
265+
// (like our restored Open Dialog button), update the selection state
262266
// and exit early. Do not call focus(), which resets to the first child.
263267
if (getEventTarget(e) !== ref.current) {
264268
if (!isFocusVisible()) {
@@ -268,7 +272,7 @@ export function useGridCell<T, C extends GridCollection<T>>(
268272
}
269273

270274
if (focusMode === 'child') {
271-
// Safeguard: Check if the browser's active element has already shifted
275+
// Safeguard: Check if the browser's active element has already shifted
272276
// into a nested child node during this event loop tick before forcing a reset.
273277
let activeElement = getActiveElement();
274278
if (ref.current && isFocusWithin(ref.current) && activeElement !== ref.current) {

packages/react-aria/test/grid/useGrid.test.js

100644100755
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { act, pointerMap, render } from '@react-spectrum/test-utils-internal';
14-
import { Grid } from '../../stories/grid/example';
15-
import { Item } from 'react-stately/Item';
13+
import {act, pointerMap, render} from '@react-spectrum/test-utils-internal';
14+
import {Grid} from '../../stories/grid/example';
15+
import {Item} from 'react-stately/Item';
1616
import React from 'react';
17-
import { Switch } from '@adobe/react-spectrum/Switch';
17+
import {Switch} from '@adobe/react-spectrum/Switch';
1818
import userEvent from '@testing-library/user-event';
1919

2020
function renderGrid(props = {}) {
@@ -41,7 +41,7 @@ describe('useGrid', () => {
4141
let user;
4242

4343
beforeAll(() => {
44-
user = userEvent.setup({ delay: null, pointerMap });
44+
user = userEvent.setup({delay: null, pointerMap});
4545
jest.useFakeTimers();
4646
});
4747
afterEach(() => {
@@ -51,7 +51,7 @@ describe('useGrid', () => {
5151
});
5252
});
5353
it('gridFocusMode = row, cellFocusMode = cell', async () => {
54-
let tree = renderGrid({ gridFocusMode: 'row', cellFocusMode: 'cell' });
54+
let tree = renderGrid({gridFocusMode: 'row', cellFocusMode: 'cell'});
5555

5656
await user.tab();
5757
expect(document.activeElement).toBe(tree.getAllByRole('row')[0]);
@@ -84,7 +84,7 @@ describe('useGrid', () => {
8484
});
8585

8686
it('gridFocusMode = row, cellFocusMode = child', async () => {
87-
let tree = renderGrid({ gridFocusMode: 'row', cellFocusMode: 'child' });
87+
let tree = renderGrid({gridFocusMode: 'row', cellFocusMode: 'child'});
8888

8989
await user.tab();
9090
expect(document.activeElement).toBe(tree.getAllByRole('row')[0]);
@@ -112,7 +112,7 @@ describe('useGrid', () => {
112112
});
113113

114114
it('gridFocusMode = cell, cellFocusMode = child', async () => {
115-
let tree = renderGrid({ gridFocusMode: 'cell', cellFocusMode: 'child' });
115+
let tree = renderGrid({gridFocusMode: 'cell', cellFocusMode: 'child'});
116116

117117
await user.tab();
118118
expect(document.activeElement).toBe(tree.getAllByRole('switch')[0]);
@@ -134,7 +134,7 @@ describe('useGrid', () => {
134134
});
135135

136136
it('gridFocusMode = cell, cellFocusMode = cell', async () => {
137-
let tree = renderGrid({ gridFocusMode: 'cell', cellFocusMode: 'cell' });
137+
let tree = renderGrid({gridFocusMode: 'cell', cellFocusMode: 'cell'});
138138

139139
await user.tab();
140140
expect(document.activeElement).toBe(tree.getAllByRole('gridcell')[0]);
@@ -159,7 +159,7 @@ describe('useGrid', () => {
159159
});
160160

161161
it('should retain focus on a specific child element if focus is restored to it', async () => {
162-
let tree = renderGrid({ gridFocusMode: 'cell', cellFocusMode: 'child' });
162+
let tree = renderGrid({gridFocusMode: 'cell', cellFocusMode: 'child'});
163163
let switches = tree.getAllByRole('switch');
164164
let cells = tree.getAllByRole('gridcell');
165165

@@ -174,10 +174,10 @@ describe('useGrid', () => {
174174
});
175175
expect(document.activeElement).toBe(switches[1]);
176176

177-
// 3. Fire a focus event directly on the gridcell container to trigger your
177+
// 3. Fire a focus event directly on the gridcell container to trigger your
178178
// onFocus handler in useGridCell.ts and simulate event bubbling
179179
act(() => {
180-
cells[0].dispatchEvent(new FocusEvent('focus', { bubbles: true }));
180+
cells[0].dispatchEvent(new FocusEvent('focus', {bubbles: true}));
181181
});
182182

183183
// 4. Force Jest's timer and requestAnimationFrame microtask cycles to execute completely

0 commit comments

Comments
 (0)