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

Add drop to the end of the list to UPP, fix minor bugs #15428

Merged
merged 21 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
basic drop over input, still bugs
  • Loading branch information
elisabethcvs committed Sep 25, 2020
commit 0422bc7bb44ee0122485870980e5b13e4ad34670
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ const UnifiedPeoplePickerExample = (): JSX.Element => {
updatedItems.push(item);
}
}
if (insertIndex === currentItems.length) {
newItems.forEach(draggedItem => {
updatedItems.push(draggedItem);
});
}
setPeopleSelectedItems(updatedItems);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export const UnifiedPeoplePickerExample = (): JSX.Element => {
updatedItems.push(item);
}
}
if (insertIndex === currentItems.length) {
newItems.forEach(draggedItem => {
updatedItems.push(draggedItem);
});
}
setPeopleSelectedItems(updatedItems);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export const UnifiedPeoplePickerWithEditExample = (): JSX.Element => {
updatedItems.push(item);
}
}
if (insertIndex === currentItems.length) {
newItems.forEach(draggedItem => {
updatedItems.push(draggedItem);
});
}
setPeopleSelectedItems(updatedItems);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,17 @@ export const UnifiedPicker = <T extends {}>(props: IUnifiedPickerProps<T>): JSX.
return !focusedItemIndices.includes(dropContext!.index);
};

const _onDrop = (item?: any, event?: DragEvent): void => {
const _onDropAutoFill = (event?: DragEvent) => {
insertIndex = selectedItems.length;
_onDropInner(event);
};

const _onDropList = (item?: any, event?: DragEvent): void => {
insertIndex = selectedItems.indexOf(item);
_onDropInner(event);
};

const _onDropInner = (event?: DragEvent): void => {
let isDropHandled = false;
if (event?.dataTransfer) {
event.preventDefault();
Expand Down Expand Up @@ -175,12 +184,16 @@ export const UnifiedPicker = <T extends {}>(props: IUnifiedPickerProps<T>): JSX.
setDraggedIndex(-1);
};

const _onDragOver = (event?: React.DragEvent<HTMLDivElement>) => {
event?.preventDefault();
};

const defaultDragDropEvents: IDragDropEvents = {
canDrop: _canDrop,
canDrag: () => true,
onDragEnter: _onDragEnter,
onDragLeave: () => undefined,
onDrop: _onDrop,
onDrop: _onDropList,
onDragStart: _onDragStart,
onDragEnd: _onDragEnd,
};
Expand Down Expand Up @@ -364,6 +377,8 @@ export const UnifiedPicker = <T extends {}>(props: IUnifiedPickerProps<T>): JSX.
aria-haspopup="listbox"
role="combobox"
className={css('ms-BasePicker-div', classNames.pickerDiv)}
onDrop={_onDropAutoFill}
onDragOver={_onDragOver}
>
<Autofill
{...(inputProps as IInputProps)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export const useSelectedItems = <T extends {}>(
updatedItems.push(item);
}
}
// if the insert index is at the end, add them now
if (insertIndex === currentItems.length) {
itemsToAdd.forEach(draggedItem => {
updatedItems.push(draggedItem);
});
}
setSelectedItems(updatedItems);
selection.setItems(updatedItems);
};
Expand Down