@patternfly/react-core 4.157.5 → 4.157.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/esm/components/DataList/DataList.d.ts +7 -5
  3. package/dist/esm/components/DataList/DataList.d.ts.map +1 -1
  4. package/dist/esm/components/DataList/DataList.js +11 -10
  5. package/dist/esm/components/DataList/DataList.js.map +1 -1
  6. package/dist/esm/components/DragDrop/DragDrop.d.ts +3 -0
  7. package/dist/esm/components/DragDrop/DragDrop.d.ts.map +1 -1
  8. package/dist/esm/components/DragDrop/DragDrop.js +2 -1
  9. package/dist/esm/components/DragDrop/DragDrop.js.map +1 -1
  10. package/dist/esm/components/DragDrop/Draggable.d.ts +2 -0
  11. package/dist/esm/components/DragDrop/Draggable.d.ts.map +1 -1
  12. package/dist/esm/components/DragDrop/Draggable.js +27 -18
  13. package/dist/esm/components/DragDrop/Draggable.js.map +1 -1
  14. package/dist/esm/components/DragDrop/Droppable.d.ts +2 -0
  15. package/dist/esm/components/DragDrop/Droppable.d.ts.map +1 -1
  16. package/dist/esm/components/DragDrop/Droppable.js +3 -3
  17. package/dist/esm/components/DragDrop/Droppable.js.map +1 -1
  18. package/dist/js/components/DataList/DataList.d.ts +7 -5
  19. package/dist/js/components/DataList/DataList.d.ts.map +1 -1
  20. package/dist/js/components/DataList/DataList.js +11 -10
  21. package/dist/js/components/DataList/DataList.js.map +1 -1
  22. package/dist/js/components/DragDrop/DragDrop.d.ts +3 -0
  23. package/dist/js/components/DragDrop/DragDrop.d.ts.map +1 -1
  24. package/dist/js/components/DragDrop/DragDrop.js +2 -1
  25. package/dist/js/components/DragDrop/DragDrop.js.map +1 -1
  26. package/dist/js/components/DragDrop/Draggable.d.ts +2 -0
  27. package/dist/js/components/DragDrop/Draggable.d.ts.map +1 -1
  28. package/dist/js/components/DragDrop/Draggable.js +27 -18
  29. package/dist/js/components/DragDrop/Draggable.js.map +1 -1
  30. package/dist/js/components/DragDrop/Droppable.d.ts +2 -0
  31. package/dist/js/components/DragDrop/Droppable.d.ts.map +1 -1
  32. package/dist/js/components/DragDrop/Droppable.js +3 -3
  33. package/dist/js/components/DragDrop/Droppable.js.map +1 -1
  34. package/dist/umd/react-core.css +10584 -10584
  35. package/dist/umd/react-core.js +43 -31
  36. package/dist/umd/react-core.min.css +9271 -9271
  37. package/dist/umd/react-core.min.js +2 -2
  38. package/package.json +2 -2
  39. package/src/components/DataList/DataList.tsx +19 -15
  40. package/src/components/DataList/examples/DataList.md +78 -111
  41. package/src/components/DragDrop/DragDrop.tsx +7 -1
  42. package/src/components/DragDrop/Draggable.tsx +49 -41
  43. package/src/components/DragDrop/Droppable.tsx +21 -7
  44. package/src/components/DragDrop/__tests__/__snapshots__/DragDrop.test.tsx.snap +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.157.5",
3
+ "version": "4.157.6",
4
4
  "description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "94381180323c46d7071a0d1e1ae6ebdea5a0d2ff"
63
+ "gitHead": "d013adc9687d5873a6733b63ff6bc2d93a2b5915"
64
64
  }
@@ -29,13 +29,13 @@ export interface DataListProps extends Omit<React.HTMLProps<HTMLUListElement>, '
29
29
  'aria-label': string;
30
30
  /** Optional callback to make DataList selectable, fired when DataListItem selected */
31
31
  onSelectDataListItem?: (id: string) => void;
32
- /** Optional callback to make DataList draggable, fired when dragging ends */
32
+ /** @deprecated Optional callback to make DataList draggable, fired when dragging ends */
33
33
  onDragFinish?: (newItemOrder: string[]) => void;
34
- /** Optional informational callback for dragging, fired when dragging starts */
34
+ /** @deprecated Optional informational callback for dragging, fired when dragging starts */
35
35
  onDragStart?: (id: string) => void;
36
- /** Optional informational callback for dragging, fired when an item moves */
36
+ /** @deprecated Optional informational callback for dragging, fired when an item moves */
37
37
  onDragMove?: (oldIndex: number, newIndex: number) => void;
38
- /** Optional informational callback for dragging, fired when dragging is cancelled */
38
+ /** @deprecated Optional informational callback for dragging, fired when dragging is cancelled */
39
39
  onDragCancel?: () => void;
40
40
  /** Id of DataList item currently selected */
41
41
  selectedDataListItemId?: string;
@@ -45,7 +45,7 @@ export interface DataListProps extends Omit<React.HTMLProps<HTMLUListElement>, '
45
45
  gridBreakpoint?: 'none' | 'always' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
46
46
  /** Determines which wrapping modifier to apply to the DataList */
47
47
  wrapModifier?: DataListWrapModifier | 'nowrap' | 'truncate' | 'breakWord';
48
- /** Order of items in a draggable DataList */
48
+ /** @deprecated Order of items in a draggable DataList */
49
49
  itemOrder?: string[];
50
50
  }
51
51
 
@@ -93,6 +93,7 @@ export class DataList extends React.Component<DataListProps, DataListState> {
93
93
  wrapModifier: null
94
94
  };
95
95
  dragFinished: boolean = false;
96
+ html5DragDrop: boolean = false;
96
97
  arrayCopy: React.ReactElement[] = React.Children.toArray(this.props.children) as React.ReactElement[];
97
98
  ref = React.createRef<HTMLUListElement>();
98
99
 
@@ -103,6 +104,16 @@ export class DataList extends React.Component<DataListProps, DataListState> {
103
104
  dragging: false
104
105
  };
105
106
 
107
+ constructor(props: DataListProps) {
108
+ super(props);
109
+
110
+ this.html5DragDrop = Boolean(props.onDragFinish || props.onDragStart || props.onDragMove || props.onDragCancel);
111
+ if (this.html5DragDrop) {
112
+ // eslint-disable-next-line no-console
113
+ console.warn("DataList's onDrag API is deprecated. Use DragDrop instead.");
114
+ }
115
+ }
116
+
106
117
  componentDidUpdate(oldProps: DataListProps) {
107
118
  if (this.dragFinished) {
108
119
  this.dragFinished = false;
@@ -242,13 +253,7 @@ export class DataList extends React.Component<DataListProps, DataListState> {
242
253
 
243
254
  handleDragButtonKeys = (evt: React.KeyboardEvent) => {
244
255
  const { dragging } = this.state;
245
- if (
246
- evt.key !== ' ' &&
247
- evt.key !== 'Escape' &&
248
- evt.key !== 'Enter' &&
249
- evt.key !== 'ArrowUp' &&
250
- evt.key !== 'ArrowDown'
251
- ) {
256
+ if (![' ', 'Escape', 'Enter', 'ArrowUp', 'ArrowDown'].includes(evt.key) || !this.html5DragDrop) {
252
257
  if (dragging) {
253
258
  evt.preventDefault();
254
259
  }
@@ -308,13 +313,12 @@ export class DataList extends React.Component<DataListProps, DataListState> {
308
313
  } = this.props;
309
314
  const { dragging } = this.state;
310
315
  const isSelectable = onSelectDataListItem !== undefined;
311
- const isDraggable = onDragFinish !== undefined;
312
316
 
313
317
  const updateSelectedDataListItem = (id: string) => {
314
318
  onSelectDataListItem(id);
315
319
  };
316
320
 
317
- const dragProps = isDraggable && {
321
+ const dragProps = this.html5DragDrop && {
318
322
  onDragOver: this.dragOver,
319
323
  onDrop: this.dragOver,
320
324
  onDragLeave: this.dragLeave
@@ -326,7 +330,7 @@ export class DataList extends React.Component<DataListProps, DataListState> {
326
330
  isSelectable,
327
331
  selectedDataListItemId,
328
332
  updateSelectedDataListItem,
329
- isDraggable,
333
+ isDraggable: this.html5DragDrop,
330
334
  dragStart: this.dragStart,
331
335
  dragEnd: this.dragEnd,
332
336
  drop: this.drop,
@@ -1125,6 +1125,8 @@ import {
1125
1125
 
1126
1126
  ### Draggable
1127
1127
 
1128
+ Draggable data lists used to have their own HTML5-based API for drag and drop, which wasn't able to fulfill requirements such as custom styling on items being dragged. So we wrote generic `DragDrop`, `Draggable`, and `Droppable` components for this purpose. Use those new components instead of the deprecated (and buggy!) HTML5-based API.
1129
+
1128
1130
  ```js
1129
1131
  import React from 'react';
1130
1132
  import {
@@ -1135,129 +1137,94 @@ import {
1135
1137
  DataListCheck,
1136
1138
  DataListControl,
1137
1139
  DataListDragButton,
1138
- DataListItemCells
1140
+ DataListItemCells,
1141
+ DragDrop,
1142
+ Draggable,
1143
+ Droppable
1139
1144
  } from '@patternfly/react-core';
1140
1145
 
1146
+ const getItems = count =>
1147
+ Array.from({ length: count }, (v, k) => k).map(k => ({
1148
+ id: `item-${k}`,
1149
+ content: `item ${k} `.repeat(k === 4 ? 20 : 1)
1150
+ }));
1151
+
1152
+ const reorder = (list, startIndex, endIndex) => {
1153
+ const result = Array.from(list);
1154
+ const [removed] = result.splice(startIndex, 1);
1155
+ result.splice(endIndex, 0, removed);
1156
+ return result;
1157
+ };
1158
+
1141
1159
  DraggableDataList = () => {
1142
- const [ liveText, setLiveText ] = React.useState('');
1143
- const [ id, setId ] = React.useState('');
1144
- const [ itemOrder, setItemOrder ] = React.useState(['data1', 'data2', 'data3', 'data4']);
1160
+ const [items, setItems] = React.useState(getItems(10));
1161
+ const [liveText, setLiveText] = React.useState('');
1145
1162
 
1146
- const onDragStart = newId => {
1147
- setId(newId)
1148
- setLiveText(`Dragging tarted for item id: ${newId}.`);
1149
- };
1163
+ function onDrag(source) {
1164
+ setLiveText(`Started dragging ${items[source.index].content}`);
1165
+ // Return true to allow drag
1166
+ return true;
1167
+ }
1150
1168
 
1151
- const onDragMove = (oldIndex, newIndex) => {
1152
- setLiveText(`Dragging item ${id}. Item with index ${oldIndex} in now ${newIndex}.`);
1153
- };
1169
+ function onDragMove(source, dest) {
1170
+ const newText = dest
1171
+ ? `Move ${items[source.index].content} to ${items[dest.index].content}`
1172
+ : 'Invalid drop zone';
1173
+ if (newText !== liveText) {
1174
+ setLiveText(newText);
1175
+ }
1176
+ }
1154
1177
 
1155
- const onDragCancel = () => {
1156
- setLiveText('Dragging cancelled. List is unchanged.');
1157
- };
1178
+ function onDrop(source, dest) {
1179
+ if (dest) {
1180
+ const newItems = reorder(
1181
+ items,
1182
+ source.index,
1183
+ dest.index
1184
+ );
1185
+ setItems(newItems);
1158
1186
 
1159
- const onDragFinish = newItemOrder => {
1160
- setLiveText('Dragging finsihed');
1161
- setItemOrder(newItemOrder);
1162
- };
1187
+ setLiveText('Dragging finished.');
1188
+ return true; // Signal that this is a valid drop and not to animate the item returning home.
1189
+ } else {
1190
+ setLiveText('Dragging cancelled. List unchanged.');
1191
+ }
1192
+ }
1163
1193
 
1164
1194
  return (
1165
- <>
1166
- <DataList
1167
- aria-label="draggable data list example"
1168
- isCompact
1169
- onDragFinish={onDragFinish}
1170
- onDragStart={onDragStart}
1171
- onDragMove={onDragMove}
1172
- onDragCancel={onDragCancel}
1173
- itemOrder={itemOrder}
1174
- >
1175
- <DataListItem aria-labelledby="simple-item1" id="data1" key="1">
1176
- <DataListItemRow>
1177
- <DataListControl>
1178
- <DataListDragButton
1179
- aria-label="Reorder"
1180
- aria-labelledby="simple-item1"
1181
- aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
1182
- aria-pressed="false"
1183
- isDisabled
1184
- />
1185
- <DataListCheck aria-labelledby="simple-item1" name="check1" otherControls />
1186
- </DataListControl>
1187
- <DataListItemCells
1188
- dataListCells={[
1189
- <DataListCell key="item1">
1190
- <span id="simple-item1">Item 1</span>
1191
- </DataListCell>
1192
- ]}
1193
- />
1194
- </DataListItemRow>
1195
- </DataListItem>
1196
- <DataListItem aria-labelledby="simple-item2" id="data2" key="2">
1197
- <DataListItemRow>
1198
- <DataListControl>
1199
- <DataListDragButton
1200
- aria-label="Reorder"
1201
- aria-labelledby="simple-item2"
1202
- aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
1203
- aria-pressed="false"
1204
- />
1205
- <DataListCheck aria-labelledby="simple-item2" name="check2" otherControls />
1206
- </DataListControl>
1207
- <DataListItemCells
1208
- dataListCells={[
1209
- <DataListCell key="item2">
1210
- <span id="simple-item2">Item 2</span>
1211
- </DataListCell>
1212
- ]}
1213
- />
1214
- </DataListItemRow>
1215
- </DataListItem>
1216
- <DataListItem aria-labelledby="simple-item3" id="data3" key="3">
1217
- <DataListItemRow>
1218
- <DataListControl>
1219
- <DataListDragButton
1220
- aria-label="Reorder"
1221
- aria-labelledby="simple-item3"
1222
- aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
1223
- aria-pressed="false"
1224
- />
1225
- <DataListCheck aria-labelledby="simple-item3" name="check3" otherControls />
1226
- </DataListControl>
1227
- <DataListItemCells
1228
- dataListCells={[
1229
- <DataListCell key="item3">
1230
- <span id="simple-item3">Item 3</span>
1231
- </DataListCell>
1232
- ]}
1233
- />
1234
- </DataListItemRow>
1235
- </DataListItem>
1236
- <DataListItem aria-labelledby="simple-item4" id="data4" key="4">
1237
- <DataListItemRow>
1238
- <DataListControl>
1239
- <DataListDragButton
1240
- aria-label="Reorder"
1241
- aria-labelledby="simple-item4"
1242
- aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
1243
- aria-pressed="false"
1244
- />
1245
- <DataListCheck aria-labelledby="simple-item4" name="check4" otherControls />
1246
- </DataListControl>
1247
- <DataListItemCells
1248
- dataListCells={[
1249
- <DataListCell key="item4">
1250
- <span id="simple-item4">Item 4</span>
1251
- </DataListCell>
1252
- ]}
1253
- />
1254
- </DataListItemRow>
1255
- </DataListItem>
1256
- </DataList>
1195
+ <DragDrop onDrag={onDrag} onDragMove={onDragMove} onDrop={onDrop}>
1196
+ <Droppable hasNoWrapper>
1197
+ <DataList aria-label="draggable data list example" isCompact>
1198
+ {items.map(({id, content}) =>
1199
+ <Draggable key={id} hasNoWrapper>
1200
+ <DataListItem aria-labelledby={id} ref={React.createRef()}>
1201
+ <DataListItemRow>
1202
+ <DataListControl>
1203
+ <DataListDragButton
1204
+ aria-label="Reorder"
1205
+ aria-labelledby={id}
1206
+ aria-describedby="Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation."
1207
+ aria-pressed="false"
1208
+ />
1209
+ <DataListCheck aria-labelledby={id} name={id} otherControls />
1210
+ </DataListControl>
1211
+ <DataListItemCells
1212
+ dataListCells={[
1213
+ <DataListCell key={id}>
1214
+ <span id={id}>{content}</span>
1215
+ </DataListCell>
1216
+ ]}
1217
+ />
1218
+ </DataListItemRow>
1219
+ </DataListItem>
1220
+ </Draggable>
1221
+ )}
1222
+ </DataList>
1223
+ </Droppable>
1257
1224
  <div className="pf-screen-reader" aria-live="assertive">
1258
1225
  {liveText}
1259
1226
  </div>
1260
- </>
1227
+ </DragDrop>
1261
1228
  );
1262
1229
  };
1263
1230
  ```
@@ -9,6 +9,7 @@ interface DraggableItemPosition {
9
9
 
10
10
  export const DragDropContext = React.createContext({
11
11
  onDrag: (_source: DraggableItemPosition) => true as boolean,
12
+ onDragMove: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => {},
12
13
  onDrop: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => false as boolean
13
14
  });
14
15
 
@@ -17,6 +18,8 @@ interface DragDropProps {
17
18
  children?: React.ReactNode;
18
19
  /** Callback for drag event. Return true to allow drag, false to disallow. */
19
20
  onDrag?: (source: DraggableItemPosition) => boolean;
21
+ /** Callback on mouse move while dragging. */
22
+ onDragMove?: (source: DraggableItemPosition, dest?: DraggableItemPosition) => void;
20
23
  /** Callback for drop event. Return true to allow drop, false to disallow. */
21
24
  onDrop?: (source: DraggableItemPosition, dest?: DraggableItemPosition) => boolean;
22
25
  }
@@ -24,6 +27,9 @@ interface DragDropProps {
24
27
  export const DragDrop: React.FunctionComponent<DragDropProps> = ({
25
28
  children,
26
29
  onDrag = () => true,
30
+ onDragMove = () => {},
27
31
  onDrop = () => false
28
- }: DragDropProps) => <DragDropContext.Provider value={{ onDrag, onDrop }}>{children}</DragDropContext.Provider>;
32
+ }: DragDropProps) => (
33
+ <DragDropContext.Provider value={{ onDrag, onDragMove, onDrop }}>{children}</DragDropContext.Provider>
34
+ );
29
35
  DragDrop.displayName = 'DragDrop';
@@ -1,11 +1,12 @@
1
1
  import * as React from 'react';
2
- import { createPortal } from 'react-dom';
3
2
  import { DroppableContext } from './DroppableContext';
4
3
  import { DragDropContext } from './DragDrop';
5
4
 
6
5
  export interface DraggableProps extends React.HTMLProps<HTMLDivElement> {
7
6
  /** Content rendered inside DragDrop */
8
7
  children?: React.ReactNode;
8
+ /** Don't wrap the component in a div. Requires passing a single child. */
9
+ hasNoWrapper?: boolean;
9
10
  /** Class to add to outer div */
10
11
  className?: string;
11
12
  }
@@ -32,7 +33,7 @@ function getInheritedBackgroundColor(el: HTMLElement): string {
32
33
  return getInheritedBackgroundColor(el.parentElement);
33
34
  }
34
35
 
35
- function removeBlankDiv(node: HTMLDivElement) {
36
+ function removeBlankDiv(node: HTMLElement) {
36
37
  if (node.getAttribute('blankDiv') === 'true') {
37
38
  // eslint-disable-next-line @typescript-eslint/prefer-for-of
38
39
  for (let i = 0; i < node.children.length; i++) {
@@ -47,10 +48,10 @@ function removeBlankDiv(node: HTMLDivElement) {
47
48
  }
48
49
 
49
50
  interface DroppableItem {
50
- node: HTMLDivElement;
51
+ node: HTMLElement;
51
52
  rect: DOMRect;
52
53
  isDraggingHost: boolean;
53
- draggableNodes: HTMLDivElement[];
54
+ draggableNodes: HTMLElement[];
54
55
  draggableNodesRects: DOMRect[];
55
56
  }
56
57
 
@@ -74,7 +75,8 @@ function overlaps(ev: MouseEvent, rect: DOMRect) {
74
75
  export const Draggable: React.FunctionComponent<DraggableProps> = ({
75
76
  className,
76
77
  children,
77
- style: styleProp,
78
+ style: styleProp = {},
79
+ hasNoWrapper = false,
78
80
  ...props
79
81
  }: DraggableProps) => {
80
82
  /* eslint-disable prefer-const */
@@ -82,14 +84,13 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
82
84
  /* eslint-enable prefer-const */
83
85
  const [isDragging, setIsDragging] = React.useState(false);
84
86
  const { zone, droppableId } = React.useContext(DroppableContext);
85
- const { onDrag, onDrop } = React.useContext(DragDropContext);
86
- const ref = React.createRef<HTMLDivElement>();
87
+ const { onDrag, onDragMove, onDrop } = React.useContext(DragDropContext);
87
88
  // Some state is better just to leave as vars passed around between various callbacks
88
89
  // You can only drag around one item at a time anyways...
89
90
  let startX = 0;
90
91
  let startY = 0;
91
92
  let index: number = null; // Index of this draggable
92
- let hoveringDroppable: HTMLDivElement;
93
+ let hoveringDroppable: HTMLElement;
93
94
  let hoveringIndex: number = null;
94
95
  let mouseMoveListener: EventListener;
95
96
  let mouseUpListener: EventListener;
@@ -97,18 +98,14 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
97
98
  let startYOffset = 0;
98
99
 
99
100
  // After item returning to where it started animation completes
100
- const onTransitionEnd = (_ev: React.TransitionEvent<HTMLDivElement>) => {
101
+ const onTransitionEnd = (_ev: React.TransitionEvent<HTMLElement>) => {
101
102
  if (isDragging) {
102
103
  setIsDragging(false);
103
104
  setStyle(styleProp);
104
105
  }
105
106
  };
106
107
 
107
- const onMouseUpWhileDragging = (droppableItems: DroppableItem[]) => {
108
- droppableItems.forEach(resetDroppableItem);
109
- document.removeEventListener('mousemove', mouseMoveListener);
110
- document.removeEventListener('mouseup', mouseUpListener);
111
- document.removeEventListener('contextmenu', mouseUpListener);
108
+ function getSourceAndDest() {
112
109
  const hoveringDroppableId = hoveringDroppable ? hoveringDroppable.getAttribute('data-pf-droppableid') : null;
113
110
  const source = {
114
111
  droppableId,
@@ -121,6 +118,15 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
121
118
  index: hoveringIndex
122
119
  }
123
120
  : undefined;
121
+ return { source, dest, hoveringDroppableId };
122
+ }
123
+
124
+ const onMouseUpWhileDragging = (droppableItems: DroppableItem[]) => {
125
+ droppableItems.forEach(resetDroppableItem);
126
+ document.removeEventListener('mousemove', mouseMoveListener);
127
+ document.removeEventListener('mouseup', mouseUpListener);
128
+ document.removeEventListener('contextmenu', mouseUpListener);
129
+ const { source, dest, hoveringDroppableId } = getSourceAndDest();
124
130
  const consumerReordered = onDrop(source, dest);
125
131
  if (consumerReordered && droppableId === hoveringDroppableId) {
126
132
  setIsDragging(false);
@@ -215,9 +221,12 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
215
221
  lastTranslate = translateY;
216
222
  });
217
223
  }
224
+
225
+ const { source, dest } = getSourceAndDest();
226
+ onDragMove(source, dest);
218
227
  };
219
228
 
220
- const onDragStart = (ev: React.DragEvent<HTMLDivElement>) => {
229
+ const onDragStart = (ev: React.DragEvent<HTMLElement>) => {
221
230
  // Default HTML drag and drop doesn't allow us to change what the thing
222
231
  // being dragged looks like. Because of this we'll use prevent the default
223
232
  // and use `mouseMove` and `mouseUp` instead
@@ -228,19 +237,21 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
228
237
  }
229
238
 
230
239
  // Cache droppable and draggable nodes and their bounding rects
231
- const rect = ref.current.getBoundingClientRect();
232
- const droppableNodes = Array.from(document.querySelectorAll(`[data-pf-droppable="${zone}"]`)) as HTMLDivElement[];
240
+ const dragging = ev.target as HTMLElement;
241
+ const rect = dragging.getBoundingClientRect();
242
+ const droppableNodes = Array.from(document.querySelectorAll(`[data-pf-droppable="${zone}"]`)) as HTMLElement[];
233
243
  const droppableItems = droppableNodes.reduce((acc, cur) => {
234
- const draggableNodes = Array.from(cur.querySelectorAll(`[data-pf-draggable-zone="${zone}"]`)) as HTMLDivElement[];
235
- const isDraggingHost = cur.contains(ref.current);
244
+ const draggableNodes = Array.from(cur.querySelectorAll(`[data-pf-draggable-zone="${zone}"]`)) as HTMLElement[];
245
+ const isDraggingHost = cur.contains(dragging);
236
246
  if (isDraggingHost) {
237
- index = draggableNodes.indexOf(ref.current);
247
+ index = draggableNodes.indexOf(dragging);
238
248
  }
239
249
  const droppableItem = {
240
250
  node: cur,
241
251
  rect: cur.getBoundingClientRect(),
242
252
  isDraggingHost,
243
- draggableNodes,
253
+ // We don't want styles to apply to the left behind div in onMouseMoveWhileDragging
254
+ draggableNodes: draggableNodes.map(node => (node === dragging ? node.cloneNode(false) : node)),
244
255
  draggableNodesRects: draggableNodes.map(node => node.getBoundingClientRect())
245
256
  };
246
257
  acc.push(droppableItem);
@@ -260,7 +271,7 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
260
271
  left: rect.x,
261
272
  width: rect.width,
262
273
  height: rect.height,
263
- background: getInheritedBackgroundColor(ref.current),
274
+ background: getInheritedBackgroundColor(dragging),
264
275
  boxShadow: '0px 0px 0px 1px blue, 0px 2px 5px rgba(0, 0, 0, 0.2)',
265
276
  zIndex: 5000
266
277
  };
@@ -275,35 +286,32 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
275
286
  document.addEventListener('mousemove', mouseMoveListener);
276
287
  document.addEventListener('mouseup', mouseUpListener);
277
288
  // Comment out this line to debug while dragging by right clicking
278
- document.addEventListener('contextmenu', mouseUpListener);
289
+ // document.addEventListener('contextmenu', mouseUpListener);
279
290
  };
280
291
 
281
- const div = (
282
- <div
283
- data-pf-draggable-zone={isDragging ? null : zone}
284
- draggable
285
- role="button"
286
- className={className}
287
- onDragStart={onDragStart}
288
- onTransitionEnd={onTransitionEnd}
289
- style={style}
290
- ref={ref}
291
- {...props}
292
- >
293
- {children}
294
- </div>
295
- );
292
+ const childProps = {
293
+ 'data-pf-draggable-zone': isDragging ? null : zone,
294
+ draggable: true,
295
+ className,
296
+ onDragStart,
297
+ onTransitionEnd,
298
+ style,
299
+ ...props
300
+ };
296
301
 
297
302
  return (
298
303
  <React.Fragment>
299
304
  {/* Leave behind blank spot per-design */}
300
305
  {isDragging && (
301
- <div draggable role="button" {...props} style={{ ...styleProp, visibility: 'hidden' }}>
306
+ <div draggable {...props} style={{ ...styleProp, visibility: 'hidden' }}>
302
307
  {children}
303
308
  </div>
304
309
  )}
305
- {/* Move dragging part into portal to appear above top and side nav */}
306
- {isDragging ? createPortal(div, document.body) : div}
310
+ {hasNoWrapper ? (
311
+ React.cloneElement(children as React.ReactElement, childProps)
312
+ ) : (
313
+ <div {...childProps}>{children}</div>
314
+ )}
307
315
  </React.Fragment>
308
316
  );
309
317
  };
@@ -10,6 +10,8 @@ interface DroppableProps extends React.HTMLProps<HTMLDivElement> {
10
10
  zone?: string;
11
11
  /** Id to be passed back on drop events */
12
12
  droppableId?: string;
13
+ /** Don't wrap the component in a div. Requires passing a single child. */
14
+ hasNoWrapper?: boolean;
13
15
  }
14
16
 
15
17
  export const Droppable: React.FunctionComponent<DroppableProps> = ({
@@ -17,12 +19,24 @@ export const Droppable: React.FunctionComponent<DroppableProps> = ({
17
19
  children,
18
20
  zone = 'defaultZone',
19
21
  droppableId = 'defaultId',
22
+ hasNoWrapper = false,
20
23
  ...props
21
- }: DroppableProps) => (
22
- <DroppableContext.Provider value={{ zone, droppableId }}>
23
- <div data-pf-droppable={zone} data-pf-droppableid={droppableId} className={className} {...props}>
24
- {children}
25
- </div>
26
- </DroppableContext.Provider>
27
- );
24
+ }: DroppableProps) => {
25
+ const childProps = {
26
+ 'data-pf-droppable': zone,
27
+ 'data-pf-droppableid': droppableId,
28
+ className,
29
+ ...props
30
+ };
31
+
32
+ return (
33
+ <DroppableContext.Provider value={{ zone, droppableId }}>
34
+ {hasNoWrapper ? (
35
+ React.cloneElement(children as React.ReactElement, childProps)
36
+ ) : (
37
+ <div {...childProps}>{children}</div>
38
+ )}
39
+ </DroppableContext.Provider>
40
+ );
41
+ };
28
42
  Droppable.displayName = 'Droppable';
@@ -5,6 +5,7 @@ exports[`renders some divs 1`] = `
5
5
  value={
6
6
  Object {
7
7
  "onDrag": [Function],
8
+ "onDragMove": [Function],
8
9
  "onDrop": [Function],
9
10
  }
10
11
  }