Skip to content

Commit

Permalink
Render children in DropIndicators (#5527)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Dec 6, 2023
1 parent daf929f commit dd348f1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/react-aria-components/src/GridList.tsx
Expand Up @@ -426,6 +426,7 @@ function GridListDropIndicator(props: GridListDropIndicatorProps, ref: Forwarded
data-drop-target={isDropTarget || undefined}>
<div role="gridcell">
<div {...visuallyHiddenProps} role="button" {...dropIndicatorProps} ref={buttonRef} />
{renderProps.children}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions packages/react-aria-components/src/Table.tsx
Expand Up @@ -1222,6 +1222,7 @@ function TableDropIndicator(props: TableDropIndicatorProps, ref: ForwardedRef<HT
colSpan={state.collection.columnCount}
style={{padding: 0}}>
<div {...visuallyHiddenProps} role="button" {...dropIndicatorProps} ref={buttonRef} />
{renderProps.children}
</td>
</tr>
);
Expand Down
5 changes: 3 additions & 2 deletions packages/react-aria-components/test/GridList.test.js
Expand Up @@ -11,7 +11,7 @@
*/

import {act, fireEvent, pointerMap, render, within} from '@react-spectrum/test-utils';
import {Button, Checkbox, GridList, GridListContext, GridListItem, useDragAndDrop} from '../';
import {Button, Checkbox, DropIndicator, GridList, GridListContext, GridListItem, useDragAndDrop} from '../';
import React from 'react';
import userEvent from '@testing-library/user-event';

Expand Down Expand Up @@ -247,7 +247,7 @@ describe('GridList', () => {

it('should render drop indicators', () => {
let onReorder = jest.fn();
let {getAllByRole} = render(<DraggableGridList onReorder={onReorder} />);
let {getAllByRole} = render(<DraggableGridList onReorder={onReorder} renderDropIndicator={(target) => <DropIndicator target={target}>Test</DropIndicator>} />);
let button = getAllByRole('button')[0];
fireEvent.keyDown(button, {key: 'Enter'});
fireEvent.keyUp(button, {key: 'Enter'});
Expand All @@ -257,6 +257,7 @@ describe('GridList', () => {
expect(rows).toHaveLength(5);
expect(rows[0]).toHaveAttribute('class', 'react-aria-DropIndicator');
expect(rows[0]).toHaveAttribute('data-drop-target', 'true');
expect(rows[0]).toHaveTextContent('Test');
expect(within(rows[0]).getByRole('button')).toHaveAttribute('aria-label', 'Insert before Cat');
expect(rows[2]).toHaveAttribute('class', 'react-aria-DropIndicator');
expect(rows[2]).not.toHaveAttribute('data-drop-target');
Expand Down
5 changes: 3 additions & 2 deletions packages/react-aria-components/test/ListBox.test.js
Expand Up @@ -11,7 +11,7 @@
*/

import {act, fireEvent, pointerMap, render, within} from '@react-spectrum/test-utils';
import {Header, ListBox, ListBoxContext, ListBoxItem, Section, Text, useDragAndDrop} from '../';
import {DropIndicator, Header, ListBox, ListBoxContext, ListBoxItem, Section, Text, useDragAndDrop} from '../';
import React, {useState} from 'react';
import userEvent from '@testing-library/user-event';

Expand Down Expand Up @@ -478,7 +478,7 @@ describe('ListBox', () => {

it('should render drop indicators', () => {
let onReorder = jest.fn();
let {getAllByRole} = render(<DraggableListBox onReorder={onReorder} />);
let {getAllByRole} = render(<DraggableListBox onReorder={onReorder} renderDropIndicator={(target) => <DropIndicator target={target}>Test</DropIndicator>} />);
let option = getAllByRole('option')[0];
fireEvent.keyDown(option, {key: 'Enter'});
fireEvent.keyUp(option, {key: 'Enter'});
Expand All @@ -489,6 +489,7 @@ describe('ListBox', () => {
expect(rows[0]).toHaveAttribute('class', 'react-aria-DropIndicator');
expect(rows[0]).toHaveAttribute('data-drop-target', 'true');
expect(rows[0]).toHaveAttribute('aria-label', 'Insert before Cat');
expect(rows[0]).toHaveTextContent('Test');
expect(rows[1]).toHaveAttribute('class', 'react-aria-DropIndicator');
expect(rows[1]).not.toHaveAttribute('data-drop-target');
expect(rows[1]).toHaveAttribute('aria-label', 'Insert between Cat and Dog');
Expand Down
5 changes: 3 additions & 2 deletions packages/react-aria-components/test/Table.test.js
Expand Up @@ -11,7 +11,7 @@
*/

import {act, fireEvent, pointerMap, render, within} from '@react-spectrum/test-utils';
import {Button, Cell, Checkbox, Collection, Column, ColumnResizer, ResizableTableContainer, Row, Table, TableBody, TableHeader, useDragAndDrop, useTableOptions} from '../';
import {Button, Cell, Checkbox, Collection, Column, ColumnResizer, DropIndicator, ResizableTableContainer, Row, Table, TableBody, TableHeader, useDragAndDrop, useTableOptions} from '../';
import React, {useMemo, useState} from 'react';
import {resizingTests} from '@react-aria/table/test/tableResizingTests';
import {setInteractionModality} from '@react-aria/interactions';
Expand Down Expand Up @@ -693,7 +693,7 @@ describe('Table', () => {

it('should render drop indicators', () => {
let onReorder = jest.fn();
let {getAllByRole} = render(<DraggableTable onReorder={onReorder} />);
let {getAllByRole} = render(<DraggableTable onReorder={onReorder} renderDropIndicator={(target) => <DropIndicator target={target}>Test</DropIndicator>} />);
let button = getAllByRole('button')[0];
fireEvent.keyDown(button, {key: 'Enter'});
fireEvent.keyUp(button, {key: 'Enter'});
Expand All @@ -703,6 +703,7 @@ describe('Table', () => {
expect(rows).toHaveLength(5);
expect(rows[0]).toHaveAttribute('class', 'react-aria-DropIndicator');
expect(rows[0]).toHaveAttribute('data-drop-target', 'true');
expect(rows[0]).toHaveTextContent('Test');
expect(within(rows[0]).getByRole('button')).toHaveAttribute('aria-label', 'Insert before Games');
expect(rows[2]).toHaveAttribute('class', 'react-aria-DropIndicator');
expect(rows[2]).not.toHaveAttribute('data-drop-target');
Expand Down

1 comment on commit dd348f1

@rspbot
Copy link

@rspbot rspbot commented on dd348f1 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.