Skip to content

fix(cdk/drag-drop): element not draggable when has initial transform … #22458

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

Merged
merged 2 commits into from
Jul 28, 2021

Conversation

laiseng
Copy link
Contributor

@laiseng laiseng commented Apr 12, 2021

existing cdkDrag will concat current transform value with what's calculated by cdkDrag.
cdkDrag broken when initial transform value is none because transform: none is valid css but transform: none translate3d(x, y, x) is not.

i've added test cases to test cdkDrag that has initial transform: none value

@laiseng laiseng requested a review from crisbeto as a code owner April 12, 2021 06:57
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 12, 2021
@@ -347,6 +347,51 @@ describe('CdkDrag', () => {
}));
});

describe('mouse dragging when initial transform is none', () => {
it('should drag an element freely to a particular position', fakeAsync(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I think that we only really need this test, the rest can be removed.

// 'none' is valid css transform value but none + translate3d(x, y, z) is invalid.
// Note that we apply our own transform before the user's, because things like
// rotation can affect which direction the element will be translated towards.
this._rootElement.style.transform = this._initialTransform
Copy link
Member

Choose a reason for hiding this comment

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

Rather than checking here, it might be easier to check inside _applyRootElementTransform before saving the value to _initialTransform. That way we don't have to account for it again if we add any new places that read from _initialTransform.

</div>
`
})
class StandaloneDraggableWithInitialTransformNone {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than creating a new fixture, you should be able to reuse the StandaloneDraggable and adjust the test. E.g. something like:

const fixture = createComponent(StandaloneDraggable);
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;

dragElement.style.transform = 'none';
dragElementViaMouse(fixture, dragElement, 50, 100);
expect(dragElement.style.transform).toBe('translate3d(50px, 100px, 0px)');

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Apr 13, 2021
@mmalerba mmalerba force-pushed the fix/cdk-drag-tranform-none-issue branch 2 times, most recently from 4eaab40 to 845154c Compare July 27, 2021 03:20
@mmalerba mmalerba force-pushed the fix/cdk-drag-tranform-none-issue branch from 845154c to 101e3ff Compare July 27, 2021 03:21
@mmalerba mmalerba merged commit 83d82b9 into angular:master Jul 28, 2021
mmalerba pushed a commit that referenced this pull request Jul 28, 2021
#22458)

* fix(cdk/drag-drop): element not draggable when has initial transform none

* fix(cdk/drag-drop): fix for recommended changes to code and tests cases

(cherry picked from commit 83d82b9)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants