Skip to content

Commit

Permalink
UnifiedPicker: Drop to either side of items (#16236)
Browse files Browse the repository at this point in the history
* working, not rtl tested yet

* rtl I think

* Change files
  • Loading branch information
elisabethcvs authored Dec 16, 2020
1 parent 1ea9d47 commit d512cd6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "UnifiedPicker drop to each side of item",
"packageName": "@fluentui/react-experiments",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-12-15T19:05:24.161Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useSelectedItems } from './hooks/useSelectedItems';
import { IFloatingSuggestionItemProps } from '../../FloatingSuggestionsComposite';
import { getTheme } from '@fluentui/react/lib/Styling';
import { mergeStyles } from '@fluentui/merge-styles';
import { getRTL } from '@fluentui/react/lib/Utilities';

export const UnifiedPicker = <T extends {}>(props: IUnifiedPickerProps<T>): JSX.Element => {
const getClassNames = classNamesFunction<IUnifiedPickerStyleProps, IUnifiedPickerStyles>();
Expand Down Expand Up @@ -180,6 +181,21 @@ export const UnifiedPicker = <T extends {}>(props: IUnifiedPickerProps<T>): JSX.
insertIndex = selectedItems.indexOf(item);
}

// If the drop is in the right half of the item, we want to drop at index+1
if (event && event.currentTarget) {
const targetElement = event.currentTarget as HTMLElement;
const halfwayPoint = targetElement.offsetLeft + targetElement.offsetWidth / 2;
if (getRTL()) {
if (event.pageX < halfwayPoint) {
insertIndex++;
}
} else {
if (event.pageX > halfwayPoint) {
insertIndex++;
}
}
}

event?.preventDefault();
_onDropInner(event?.dataTransfer !== null ? event?.dataTransfer : undefined);
};
Expand Down

0 comments on commit d512cd6

Please sign in to comment.