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

defaultPosition now allows strings #361

Merged
merged 5 commits into from Feb 27, 2019
Merged

Conversation

tnrich
Copy link
Contributor

@tnrich tnrich commented Sep 1, 2018

This is a copy of #271

but with the changes @STRML requested

… createSVGTransform to use calc with defaultPosition, adding a test for the new functionality
@tnrich
Copy link
Contributor Author

tnrich commented Sep 1, 2018

@STRML @eric-burel I fixed a couple issues in the commit I just made. Linting and tests now pass and I added a test for the new use case.

@tnrich
Copy link
Contributor Author

tnrich commented Sep 1, 2018

@bokuweb when this PR gets merged this issue bokuweb/react-rnd#437 will no longer be relevant. I should just be able to pass "50%" for both x and y defaultPositions

@tnrich
Copy link
Contributor Author

tnrich commented Sep 1, 2018

@STRML any idea why this would be failing only on IE?

That's the new spec I added:
IE 11.0.0 (Windows 8.1 0.0.0) react-draggable props should render with defaultPosition set as string transform and handle subsequent translate() for DOM nodes FAILED
AssertionError: # specs\draggable.spec.jsx:255

  assert(style.indexOf('translate(calc(10% + 100px), calc(10% + 100px));') >= 0)
         |     |                                                           |    
         |     -1                                                          false
         "touch-action: none;"                                                  
  
   at fail (specs/main.js:27336:3)
   at ok (specs/main.js:27356:15)
   at Decorator.prototype._callFunc (specs/main.js:30707:9)
   at Decorator.prototype.concreteAssert (specs/main.js:30700:5)
   at decoratedAssert (specs/main.js:31011:13)
   at powerAssert (specs/main.js:4743:13)
   at Anonymous function (specs/main.js:6344:7)

@tnrich
Copy link
Contributor Author

tnrich commented Sep 1, 2018

hmm looks like it is related to this:
image

I'm not sure if there is some way around this..?

@eric-burel
Copy link

Hi @tnrich thanks a lot for your work on this. I only used react-draggable once last year, I already work on other open source projects and I am not a CSS export so I can not help much :/
I guess the solution is to detect that we are using IE11 and using JS to handle position in this case.

…tes instead of a calc function do to IE incompatibility; updating spec to reflect changes
@tnrich
Copy link
Contributor Author

tnrich commented Sep 3, 2018

Okay found a solution based on this stackoverflow answer: https://stackoverflow.com/questions/21142923/ie-10-11-css-transitions-with-calc-do-not-work

this commit fixes it and tests should now pass :)
cf6979a

updating createCSSTransform and createSVGTransform to use two translates instead of a calc function do to IE incompatibility; updating spec to reflect changes

@tnrich
Copy link
Contributor Author

tnrich commented Sep 5, 2018

@STRML bump :)

@tnrich
Copy link
Contributor Author

tnrich commented Sep 10, 2018

@mzabriskie @STRML any thoughts?

@tnrich
Copy link
Contributor Author

tnrich commented Sep 17, 2018

bumping. @STRML is this project still active?

@tnrich
Copy link
Contributor Author

tnrich commented Oct 8, 2018

@STRML bump

@@ -109,13 +109,23 @@ export function offsetXYFromParent(evt: {clientX: number, clientY: number}, offs
return {x, y};
}

export function createCSSTransform({x, y}: {x: number, y: number}): Object {
export function createCSSTransform({x, y}: {x: number, y: number}, defaultPosition: {x: number | string, y: number | string }): Object {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You create a DefaultControlPosition type above but then don't use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now use it here

const defaultY = (typeof defaultPosition.y === 'string') ? defaultPosition.y : defaultPosition.y + 'px';
const translation = (defaultPosition && defaultPosition.x !== 0 && defaultPosition.y !== 0)
? `translate(${defaultX}, ${defaultY}) translate(${x}px,${y}px)`
: 'translate(' + x + 'px,' + y + 'px)';
// Replace unitless items with px
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment no longer makes sense with the changes above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comment

@@ -109,13 +109,23 @@ export function offsetXYFromParent(evt: {clientX: number, clientY: number}, offs
return {x, y};
}

export function createCSSTransform({x, y}: {x: number, y: number}): Object {
export function createCSSTransform({x, y}: {x: number, y: number}, defaultPosition: {x: number | string, y: number | string }): Object {
const defaultX = (typeof defaultPosition.x === 'string') ? defaultPosition.x : defaultPosition.x + 'px';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really difficult to read. You create these two consts, defaultX and defaultY, but they're only actually used if and only if a defaultPosition is actually present.

You then use that just to prepend what is being returned as a second translate.

This is a lot of logic in what was previously a simple function and should be refactored such that the caller prepends the default translate if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked this to hopefully be more clear

const defaultY = (typeof defaultPosition.y === 'string') ? defaultPosition.y : defaultPosition.y + 'px';
const translation = (defaultPosition && defaultPosition.x !== 0 && defaultPosition.y !== 0)
? `translate(${defaultX}, ${defaultY}) translate(${x}px,${y}px)`
: 'translate(' + x + 'px,' + y + 'px)';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no template string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added template strings everywhere I could

const defaultX = (typeof defaultPosition.x === 'string') ? defaultPosition.x : defaultPosition.x + 'px';
const defaultY = (typeof defaultPosition.y === 'string') ? defaultPosition.y : defaultPosition.y + 'px';
const translation = (defaultPosition && defaultPosition.x !== 0 && defaultPosition.y !== 0)
? `translate(${defaultX}, ${defaultY}) translate(${x}px,${y}px)`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, svg transforms shouldn't have px.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer have px in it

@tnrich
Copy link
Contributor Author

tnrich commented Nov 27, 2018

@STRML let me know if there is anything else I can change to get this PR accepted and merged? Thanks!

@pavog
Copy link

pavog commented Feb 26, 2019

Any updates on this? @tnrich @STRML

@tnrich
Copy link
Contributor Author

tnrich commented Feb 26, 2019

@pavog I believe I made all the changes @STRML requested the first time around. We're just waiting on him?

@pavog
Copy link

pavog commented Feb 27, 2019

@tnrich Yep, I believe that too. @STRML is still active (see #389) in this repository but seems to not want to review your changes again.

@STRML STRML merged commit aa0a6b4 into react-grid-layout:master Feb 27, 2019
@pavog
Copy link

pavog commented Feb 27, 2019

@STRML Thank you very much 👍

STRML added a commit that referenced this pull request Mar 1, 2019
tnrich added a commit to tnrich/react-draggable that referenced this pull request Mar 1, 2019
@eric-burel
Copy link

Awesome, thanks all for finishing this PR and merging !

@tnrich
Copy link
Contributor Author

tnrich commented Mar 15, 2019

@eric-burel @STRML had to revert the changes due to unexpected breakages. I've made a new PR that hopefully solves those issues by introducing a new property initialPosition

#393

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants