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

Adding RTL support for DetailsList drag-drop to reorder columns #7267

Merged
merged 3 commits into from
Dec 3, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "DetailsList: Adding support for column drag-drop in RTL",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ export class DetailsHeaderBase extends BaseComponent<IDetailsHeaderBaseProps, ID
}
};

private _liesBetween(target: number, left: number, right: number): boolean {
return getRTL() ? target <= left && target >= right : target >= left && target <= right;
}
private _isBefore(a: number, b: number): boolean {
return getRTL() ? a >= b : a <= b;
}
private _isAfter(a: number, b: number): boolean {
return getRTL() ? a <= b : a >= b;
}

/**
* Based on the given cursor position, finds the nearest drop hint and updates the state to make it visible
*
Expand All @@ -476,8 +486,11 @@ export class DetailsHeaderBase extends BaseComponent<IDetailsHeaderBaseProps, ID
const currentDropHintIndex = this._currentDropHintIndex!;
if (this._isValidCurrentDropHintIndex()) {
if (
eventXRelativePosition >= this._dropHintDetails[currentDropHintIndex!].startX &&
eventXRelativePosition <= this._dropHintDetails[currentDropHintIndex!].endX
this._liesBetween(
eventXRelativePosition,
this._dropHintDetails[currentDropHintIndex!].startX,
this._dropHintDetails[currentDropHintIndex!].endX
)
) {
return;
}
Expand All @@ -492,21 +505,27 @@ export class DetailsHeaderBase extends BaseComponent<IDetailsHeaderBaseProps, ID
const currentIndex: number = frozenColumnCountFromStart!;
const lastValidColumn = columns.length - frozenColumnCountFromEnd!;
let indexToUpdate = -1;
if (eventXRelativePosition <= this._dropHintDetails[currentIndex].endX) {
if (this._isBefore(eventXRelativePosition, this._dropHintDetails[currentIndex].endX)) {
indexToUpdate = currentIndex;
} else if (eventXRelativePosition >= this._dropHintDetails[lastValidColumn].startX) {
} else if (this._isAfter(eventXRelativePosition, this._dropHintDetails[lastValidColumn].startX)) {
indexToUpdate = lastValidColumn;
} else if (this._isValidCurrentDropHintIndex()) {
if (
this._dropHintDetails[currentDropHintIndex! + 1] &&
eventXRelativePosition >= this._dropHintDetails[currentDropHintIndex! + 1].startX &&
eventXRelativePosition <= this._dropHintDetails[currentDropHintIndex! + 1].endX
this._liesBetween(
eventXRelativePosition,
this._dropHintDetails[currentDropHintIndex! + 1].startX,
this._dropHintDetails[currentDropHintIndex! + 1].endX
)
) {
indexToUpdate = currentDropHintIndex! + 1;
} else if (
this._dropHintDetails[currentDropHintIndex! - 1] &&
eventXRelativePosition >= this._dropHintDetails[currentDropHintIndex! - 1].startX &&
eventXRelativePosition <= this._dropHintDetails[currentDropHintIndex! - 1].endX
this._liesBetween(
eventXRelativePosition,
this._dropHintDetails[currentDropHintIndex! - 1].startX,
this._dropHintDetails[currentDropHintIndex! - 1].endX
)
) {
indexToUpdate = currentDropHintIndex! - 1;
}
Expand All @@ -517,14 +536,13 @@ export class DetailsHeaderBase extends BaseComponent<IDetailsHeaderBaseProps, ID
while (startIndex < endIndex) {
const middleIndex = Math.ceil((endIndex + startIndex!) / 2);
if (
eventXRelativePosition >= this._dropHintDetails[middleIndex].startX &&
eventXRelativePosition <= this._dropHintDetails[middleIndex].endX
this._liesBetween(eventXRelativePosition, this._dropHintDetails[middleIndex].startX, this._dropHintDetails[middleIndex].endX)
) {
indexToUpdate = middleIndex;
break;
} else if (eventXRelativePosition < this._dropHintDetails[middleIndex].originX) {
} else if (this._isBefore(eventXRelativePosition, this._dropHintDetails[middleIndex].originX)) {
endIndex = middleIndex;
} else if (eventXRelativePosition > this._dropHintDetails[middleIndex].originX) {
KevinTCoughlin marked this conversation as resolved.
Show resolved Hide resolved
} else if (this._isAfter(eventXRelativePosition, this._dropHintDetails[middleIndex].originX)) {
startIndex = middleIndex;
}
}
Expand Down