Skip to content

Commit 9a5efd8

Browse files
committed
fix examples in dnd
1 parent 2dfed5e commit 9a5efd8

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

packages/dev/s2-docs/pages/react-aria/DropTarget.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import React, {JSX} from 'react';
3+
import React, {JSX, ReactNode} from 'react';
44
import type {TextDropItem} from '@react-aria/dnd';
55
import {useDrop} from '@react-aria/dnd';
66

@@ -18,7 +18,7 @@ export function DropTarget() {
1818
let items = await Promise.all(
1919
(e.items as TextDropItem[])
2020
.filter(item => item.kind === 'text' && (item.types.has('text/plain') || item.types.has('my-app-custom-type')))
21-
.map(async item => {
21+
.map(async (item: TextDropItem) => {
2222
if (item.types.has('my-app-custom-type')) {
2323
return JSON.parse(await item.getText('my-app-custom-type'));
2424
} else {
@@ -30,16 +30,16 @@ export function DropTarget() {
3030
}
3131
});
3232

33-
let message: JSX.Element[] = [<div>{`Drop here`}</div>];
33+
let message: ReactNode = <div key="drop here">'Drop here'</div>;
3434
if (dropped) {
3535
message = dropped.map((d, index) => {
36-
let m = d.message;
36+
let m: ReactNode = d.message;
3737
if (d.style === 'bold') {
38-
message = [<strong>{m}</strong>];
38+
m = <strong key={index}>{m}</strong>;
3939
} else if (d.style === 'italic') {
40-
message = [<em>{m}</em>];
40+
m = <em key={index}>{m}</em>;
4141
}
42-
return <div key={index}>{message}</div>;
42+
return <div key={index}>{m}</div>;
4343
});
4444
}
4545

packages/dev/s2-docs/pages/react-aria/useDrag.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export const section = 'Interactions';
2121

2222
## Introduction
2323

24-
Drag and drop is a common UI interaction that allows users to transfer data between two locations by directly moving a visual representation on screen. It is a flexible, efficient, and intuitive way for users to perform a variety of tasks, and is widely supported across both desktop and mobile operating systems.
25-
2624
React Aria supports traditional mouse and touch based drag and drop, but also implements keyboard and screen reader friendly interactions. Users can press <Keyboard>Enter</Keyboard> on a draggable element to enter drag and drop mode. Then, they can press <Keyboard>Tab</Keyboard> to navigate between drop targets, and <Keyboard>Enter</Keyboard> to drop or <Keyboard>Escape</Keyboard> to cancel. Touch screen reader users can also drag by double tapping to activate drag and drop mode, swiping between drop targets, and double tapping again to drop.
2725

2826
See the [drag and drop introduction](dnd.html) to learn more.
@@ -36,6 +34,7 @@ This example shows how to make a simple draggable element that provides data as
3634
import {useDrag} from '@react-aria/dnd';
3735
import {DropTarget} from './DropTarget.tsx';
3836
import './useDragExample.css';
37+
import 'vanilla-starter/theme.css';
3938

4039
function Draggable() {
4140
let {dragProps, isDragging} = useDrag({
@@ -151,9 +150,11 @@ A <TypeLink links={sharedDocs.links} type={sharedDocs.links[sharedDocs.exports.D
151150
* `copy` – indicates that the dragged data will be copied to the target destination.
152151
* `link` – indicates that there will be a relationship established between the source and target locations.
153152
* `cancel` – indicates that the drag and drop operation will be canceled, resulting in no changes made to the source or target.
153+
154154
Many operating systems display these in the form of a cursor change, e.g. a plus sign to indicate a copy operation. The user may also be able to use a modifier key to choose which drop operation to perform, such as <Keyboard>Option</Keyboard> or <Keyboard>Alt</Keyboard> to switch from move to copy.
155155
The `onDragEnd` event allows the drag source to respond when a drag that it initiated ends, either because it was dropped or because it was canceled by the user. The `dropOperation` property of the event object indicates the operation that was performed. For example, when data is moved, the UI could be updated to reflect this change by removing the original dragged element.
156156
This example removes the draggable element from the UI when a move operation is completed. Try holding the <Keyboard>Option</Keyboard> or <Keyboard>Alt</Keyboard> keys to change the operation to copy, and see how the behavior changes.
157+
157158
```tsx render
158159
"use client"
159160
import React from 'react';

packages/dev/s2-docs/pages/react-aria/useDrop.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export const section = 'Interactions';
2222

2323
## Introduction
2424

25-
Drag and drop is a common UI interaction that allows users to transfer data between two locations by directly moving a visual representation on screen. It is a flexible, efficient, and intuitive way for users to perform a variety of tasks, and is widely supported across both desktop and mobile operating systems.
26-
2725
React Aria supports traditional mouse and touch based drag and drop, but also implements keyboard and screen reader friendly interactions. Users can press <Keyboard>Enter</Keyboard> on a draggable element to enter drag and drop mode. Then, they can press <Keyboard>Tab</Keyboard> to navigate between drop targets, and <Keyboard>Enter</Keyboard> to drop or <Keyboard>Escape</Keyboard> to cancel. Touch screen reader users can also drag by double tapping to activate drag and drop mode, swiping between drop targets, and double tapping again to drop.
2826

2927
See the [drag and drop introduction](dnd.html) to learn more.
@@ -39,6 +37,7 @@ import type {TextDropItem} from '@react-aria/dnd';
3937
import {useDrop} from '@react-aria/dnd';
4038
import {Draggable} from './Draggable.tsx';
4139
import './useDragExample.css';
40+
import 'vanilla-starter/theme.css';
4241

4342
function DropTarget() {
4443
let [dropped, setDropped] = React.useState(null);
@@ -74,6 +73,7 @@ function DropTarget() {
7473
* `directory` – references the contents of a directory
7574
### Text
7675
A <TypeLink links={sharedDocs.links} type={sharedDocs.exports.TextDropItem} /> represents textual data in one or more different formats. These may be either standard [mime types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) or custom app-specific formats. Representing data in multiple formats allows drop targets both within and outside an application to choose data in a format that they understand. For example, a complex object may be serialized in a custom format for use within an application, with fallbacks in plain text and/or rich HTML that can be used when a user drops data from an external application.
76+
7777
The example below finds the first available item that includes a custom app-specific type. The same draggable component as used in the above example is used here, but rather than displaying the plain text representation, the custom format is used instead.
7878

7979
```tsx render
@@ -114,8 +114,8 @@ function DropTarget() {
114114
```
115115
### Files
116116
A <TypeLink links={sharedDocs.links} type={sharedDocs.exports.FileDropItem} /> references a file on the user's device. It includes the name and mime type of the file, and methods to read the contents as plain text, or retrieve a native [File](https://developer.mozilla.org/en-US/docs/Web/API/File) object which can be attached to form data for uploading.
117-
This example accepts JPEG and PNG image files, and renders them by creating a local [object URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL).
118117

118+
This example accepts JPEG and PNG image files, and renders them by creating a local [object URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL).
119119
```tsx render
120120
'use client';
121121
import React from 'react';
@@ -194,7 +194,7 @@ function DropTarget() {
194194
);
195195
}
196196
return (
197-
<div {...dropProps} role="button" tabIndex={0} ref={ref} className={`droppable grid ${isDropTarget ? 'target' : ''}`}>
197+
<div {...dropProps} role="button" tabIndex={0} ref={ref} className={`droppable grid ${isDropTarget ? 'target' : ''}`} style={{overflow: 'auto'}}>
198198
{contents}
199199
</div>
200200
);
@@ -208,6 +208,7 @@ A <TypeLink links={sharedDocs.links} type={sharedDocs.exports.DropOperation} />
208208
* `copy` – indicates that the dragged data will be copied to the target destination.
209209
* `link` – indicates that there will be a relationship established between the source and target locations.
210210
* `cancel` – indicates that the drag and drop operation will be canceled, resulting in no changes made to the source or target.
211+
211212
Many operating systems display these in the form of a cursor change, e.g. a plus sign to indicate a copy operation. The user may also be able to use a modifier key to choose which drop operation to perform, such as <Keyboard>Option</Keyboard> or <Keyboard>Alt</Keyboard> to switch from move to copy.
212213
The drag source can specify which drop operations are allowed for the dragged data (see the [useDrag docs](useDrag.html) for how to customize this). By default, the first allowed operation is allowed by drop targets, meaning that the drop target accepts data of any type and operation.
213214

@@ -305,7 +306,7 @@ function DropTarget() {
305306
onDrop: onEvent
306307
});
307308
return (
308-
<ul {...dropProps} role="button" tabIndex={0} ref={ref} className={`droppable ${isDropTarget ? 'target' : ''}`} style={{display: 'block', width: 'auto'}}>
309+
<ul {...dropProps} role="button" tabIndex={0} ref={ref} className={`droppable ${isDropTarget ? 'target' : ''}`} style={{display: 'block', width: 'auto', overflow: 'auto'}}>
309310
{events.map((e, i) => <li key={i}>{e}</li>)}
310311
</ul>
311312
);

0 commit comments

Comments
 (0)