Skip to content

defaultPosition now allows strings - #361

Merged
STRML merged 5 commits into
react-grid-layout:masterfrom
tnrich:master
Feb 27, 2019
Merged

defaultPosition now allows strings#361
STRML merged 5 commits into
react-grid-layout:masterfrom
tnrich:master

Conversation

@tnrich

@tnrich tnrich commented Sep 1, 2018

Copy link
Copy Markdown
Contributor

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

tnrich commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

@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

tnrich commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

@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

tnrich commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

@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

tnrich commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

hmm looks like it is related to this:
image

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

@eric-burel

Copy link
Copy Markdown

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

tnrich commented Sep 3, 2018

Copy link
Copy Markdown
Contributor Author

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

tnrich commented Sep 5, 2018

Copy link
Copy Markdown
Contributor Author

@STRML bump :)

@tnrich

tnrich commented Sep 10, 2018

Copy link
Copy Markdown
Contributor Author

@mzabriskie @STRML any thoughts?

@tnrich

tnrich commented Sep 17, 2018

Copy link
Copy Markdown
Contributor Author

bumping. @STRML is this project still active?

@tnrich

tnrich commented Oct 8, 2018

Copy link
Copy Markdown
Contributor Author

@STRML bump

Comment thread lib/utils/domFns.js Outdated
}

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
Copy Markdown
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
Copy Markdown
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

Comment thread lib/utils/domFns.js Outdated
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
Copy Markdown
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
Copy Markdown
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

Comment thread lib/utils/domFns.js Outdated

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
Copy Markdown
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
Copy Markdown
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

Comment thread lib/utils/domFns.js Outdated
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
Copy Markdown
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
Copy Markdown
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

Comment thread lib/utils/domFns.js Outdated
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
Copy Markdown
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
Copy Markdown
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

tnrich commented Nov 27, 2018

Copy link
Copy Markdown
Contributor Author

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

@pavog

pavog commented Feb 26, 2019

Copy link
Copy Markdown

Any updates on this? @tnrich @STRML

@tnrich

tnrich commented Feb 26, 2019

Copy link
Copy Markdown
Contributor Author

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

@pavog

pavog commented Feb 27, 2019

Copy link
Copy Markdown

@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

pavog commented Feb 27, 2019

Copy link
Copy Markdown

@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
Copy Markdown

Awesome, thanks all for finishing this PR and merging !

@tnrich

tnrich commented Mar 15, 2019

Copy link
Copy Markdown
Contributor Author

@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.

4 participants