Skip to content
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

Render children in DropIndicators #5527

Merged
merged 3 commits into from Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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