Skip to content

Commit 5e3baf6

Browse files
committed
Revert "feat: focus loading indicator in rac tree (#8270)"
This reverts commit ca2d897.
1 parent 081172e commit 5e3baf6

File tree

5 files changed

+25
-37
lines changed

5 files changed

+25
-37
lines changed

packages/@react-aria/selection/src/ListKeyboardDelegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
7878
let nextKey = key;
7979
while (nextKey != null) {
8080
let item = this.collection.getItem(nextKey);
81-
if (item?.type === 'loader' || (item?.type === 'item' && !this.isDisabled(item))) {
81+
if (item?.type === 'item' && !this.isDisabled(item)) {
8282
return nextKey;
8383
}
8484

packages/react-aria-components/example/index.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ html {
2323
}
2424
}
2525

26-
.tree-loader,
2726
.tree-item {
2827
padding: 4px 5px;
2928
outline: none;

packages/react-aria-components/src/Tree.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ export const TreeItem = /*#__PURE__*/ createBranchComponent('item', <T extends o
699699
);
700700
});
701701

702-
export interface UNSTABLE_TreeLoadingIndicatorRenderProps extends Pick<TreeItemRenderProps, 'isFocused' | 'isFocusVisible'> {
702+
export interface UNSTABLE_TreeLoadingIndicatorRenderProps {
703703
/**
704704
* What level the tree item has within the tree.
705705
* @selector [data-level]
@@ -711,44 +711,36 @@ export interface TreeLoaderProps extends RenderProps<UNSTABLE_TreeLoadingIndicat
711711

712712
export const UNSTABLE_TreeLoadingIndicator = createLeafComponent('loader', function TreeLoader<T extends object>(props: TreeLoaderProps, ref: ForwardedRef<HTMLDivElement>, item: Node<T>) {
713713
let state = useContext(TreeStateContext)!;
714-
ref = useObjectRef<HTMLDivElement>(ref);
715-
let {rowProps, gridCellProps, ...states} = useTreeItem({node: item}, state, ref);
714+
// This loader row is is non-interactable, but we want the same aria props calculated as a typical row
715+
// @ts-ignore
716+
let {rowProps} = useTreeItem({node: item}, state, ref);
716717
let level = rowProps['aria-level'] || 1;
717718

718719
let ariaProps = {
719-
role: 'row',
720720
'aria-level': rowProps['aria-level'],
721721
'aria-posinset': rowProps['aria-posinset'],
722-
'aria-setsize': rowProps['aria-setsize'],
723-
tabIndex: rowProps.tabIndex
722+
'aria-setsize': rowProps['aria-setsize']
724723
};
725724

726-
let {isFocusVisible, focusProps} = useFocusRing();
727-
728725
let renderProps = useRenderProps({
729726
...props,
730727
id: undefined,
731728
children: item.rendered,
732729
defaultClassName: 'react-aria-TreeLoader',
733730
values: {
734-
level,
735-
isFocused: states.isFocused,
736-
isFocusVisible
731+
level
737732
}
738733
});
739734

740735
return (
741736
<>
742737
<div
738+
role="row"
743739
ref={ref}
744-
{...mergeProps(filterDOMProps(props as any), ariaProps, focusProps)}
740+
{...mergeProps(filterDOMProps(props as any), ariaProps)}
745741
{...renderProps}
746-
data-key={rowProps['data-key']}
747-
data-collection={rowProps['data-collection']}
748-
data-focused={states.isFocused || undefined}
749-
data-focus-visible={isFocusVisible || undefined}
750742
data-level={level}>
751-
<div {...gridCellProps}>
743+
<div role="gridcell" aria-colindex={1}>
752744
{renderProps.children}
753745
</div>
754746
</div>

packages/react-aria-components/stories/Tree.stories.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ let rows = [
208208

209209
const MyTreeLoader = () => {
210210
return (
211-
<UNSTABLE_TreeLoadingIndicator
212-
className={({isFocused, isFocusVisible}) => classNames(styles, 'tree-loader', {
213-
focused: isFocused,
214-
'focus-visible': isFocusVisible
215-
})}>
211+
<UNSTABLE_TreeLoadingIndicator>
216212
{({level}) => {
217213
let message = `Level ${level} loading spinner`;
218214
if (level === 1) {

packages/react-aria-components/test/Tree.test.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ describe('Tree', () => {
11241124
expect(cell).toHaveAttribute('aria-colindex', '1');
11251125
});
11261126

1127-
it('should focus the load more row when using ArrowDown/ArrowUp', async () => {
1127+
it('should not focus the load more row when using ArrowDown/ArrowUp', async () => {
11281128
let {getAllByRole} = render(<LoadingMoreTree isLoading />);
11291129

11301130
let rows = getAllByRole('row');
@@ -1133,18 +1133,19 @@ describe('Tree', () => {
11331133

11341134
await user.tab();
11351135
expect(document.activeElement).toBe(rows[0]);
1136-
for (let i = 1; i < 8; i++) {
1136+
for (let i = 0; i < 5; i++) {
11371137
await user.keyboard('{ArrowDown}');
1138-
expect(document.activeElement).toBe(rows[i]);
11391138
}
1139+
expect(document.activeElement).toBe(rows[5]);
11401140

1141-
for (let i = 6; i >= 0; i--) {
1142-
await user.keyboard('{ArrowUp}');
1143-
expect(document.activeElement).toBe(rows[i]);
1144-
}
1141+
await user.keyboard('{ArrowDown}');
1142+
expect(document.activeElement).toBe(rows[7]);
1143+
1144+
await user.keyboard('{ArrowUp}');
1145+
expect(document.activeElement).toBe(rows[5]);
11451146
});
11461147

1147-
it('should focus the load more row when using End', async () => {
1148+
it('should not focus the load more row when using End', async () => {
11481149
let {getAllByRole} = render(<LoadingMoreTree isLoading />);
11491150

11501151
let rows = getAllByRole('row');
@@ -1154,14 +1155,14 @@ describe('Tree', () => {
11541155
await user.tab();
11551156
expect(document.activeElement).toBe(rows[0]);
11561157
await user.keyboard('{End}');
1157-
expect(document.activeElement).toBe(rows[21]);
1158+
expect(document.activeElement).toBe(rows[20]);
11581159

11591160
// Check that it didn't shift the focusedkey to the loader key even if DOM focus didn't shift to the loader
11601161
await user.keyboard('{ArrowUp}');
1161-
expect(document.activeElement).toBe(rows[20]);
1162+
expect(document.activeElement).toBe(rows[19]);
11621163
});
11631164

1164-
it('should focus the load more row when using PageDown', async () => {
1165+
it('should not focus the load more row when using PageDown', async () => {
11651166
let {getAllByRole} = render(<LoadingMoreTree isLoading />);
11661167

11671168
let rows = getAllByRole('row');
@@ -1171,11 +1172,11 @@ describe('Tree', () => {
11711172
await user.tab();
11721173
expect(document.activeElement).toBe(rows[0]);
11731174
await user.keyboard('{PageDown}');
1174-
expect(document.activeElement).toBe(rows[21]);
1175+
expect(document.activeElement).toBe(rows[20]);
11751176

11761177
// Check that it didn't shift the focusedkey to the loader key even if DOM focus didn't shift to the loader
11771178
await user.keyboard('{ArrowUp}');
1178-
expect(document.activeElement).toBe(rows[20]);
1179+
expect(document.activeElement).toBe(rows[19]);
11791180
});
11801181

11811182
it('should not render no results state and the loader at the same time', () => {

0 commit comments

Comments
 (0)