Skip to content

Draggable: Improve detection for when to blur the active element #1548

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

Closed
wants to merge 1 commit into from

Conversation

scottgonzalez
Copy link
Member

@scottgonzalez scottgonzalez commented May 5, 2015

Fixes #12472

I'd like to start a discussion about how we want to handle this. @tjvantoll and @mikesherov previously worked on this problem for http://bugs.jqueryui.com/ticket/10527. This expands on that solution to fix http://bugs.jqueryui.com/ticket/12472. However, the problem comes from mouse, but the fix is inside draggable. This means that every other interaction has this problem as well. There's actually an old ticket that's properly categorized as being a mouse issue: http://bugs.jqueryui.com/ticket/6642. So the question is, should we just fix the root cause now or just handle this in the interaction rewrite?

Also, how many and which test cases do we want to write? The DOM structures that exist are:

  • active element is the handle
    • e.g., a draggable div which can gain focus
  • active element is a descendant of the handle
    • e.g., an input inside a draggable that doesn't specify a handle (not great UX)
  • active element is an ancestor of the handle
    • e.g., a draggable element inside a dialog
  • active element is not associated with the handle
    • e.g., an input in another part of the document

We also have to consider which element the user is interacting with, as they can be interacting with the handle itself or a descendant of the handle. So it's possible that the active element is a descendant of the handle and the user is interacting with a descendant of the handle, but the active element and event target are siblings/cousins.

@tjvantoll
Copy link
Member

So the question is, should we just fix the root cause now or just handle this in the interaction rewrite?

I don't see any reason not to handle it now. The interaction rewrite is going to have the same problem.

The code here looks fine to me. My one suggestion would be to add tests to cover the new cases you're adding—especially “active element is not associated with the handle”. There's already a test that handles this method.

@lepolt
Copy link

lepolt commented Jun 11, 2015

Any updates on this issue? Will get get pulled into jquery:master?

@scottgonzalez
Copy link
Member Author

I need to rewrite this.

@workmanw
Copy link

👍. This has definitely caused a few issues in our app.

@lepolt
Copy link

lepolt commented Sep 10, 2015

Is this still in progress with a chance to make it to jquery:master? This might not be a common use case, but it's definitely a pain point for users in our app...

Any suggested workaround? Thanks.

@jzaefferer
Copy link
Member

Rewrite it!

@dcherman
Copy link

👍 Has there been any more consideration here? We recently encountered this in several applications as well.

@scottgonzalez
Copy link
Member Author

After giving this much thought yesterday, I think the generic solution is way too complicated for us to implement now prior to the rewrite (it may even be too complicated to write with the rewrite). I'm going to write some tests for this and land just the draggable fix. I want to make sure this gets into 1.12.0.

@scottgonzalez
Copy link
Member Author

@dcherman Just to confirm, this patch does fix bug 14905 for you, right?

@workmanw
Copy link

@scottgonzalez I've confirmed that this patch does fix the issue in our app!

Additionally, we did some other basic testing with this patch (again in our app) and did not discover any issues introduced by it.

👍

@dcherman
Copy link

@scottgonzalez Seems like it, I replaced my patch with this one locally and the bug I was running into still looks to be fixed. Thanks!

// 1) within the draggable handle
// 2) but not within the currently focused element
// See #10527, #12472
if ( !target.closest( this.handleElement ).length ||

Choose a reason for hiding this comment

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

I think it'd be a good idea to change this condition to

if ( this._getHandle(event) && target.closest( activeElement ).length )

While this patch works, it still duplicates the logic of "did this event occur within a handle" which opens the possibility of future bugs if the two different implementations aren't kept in sync

@scottgonzalez
Copy link
Member Author

I've incorporated @dcherman's suggestion, added a test, and rebased (this sure was old).

This does regress on https://bugs.jqueryui.com/ticket/10527, but that only affects IE8.

@scottgonzalez scottgonzalez changed the title [WIP] Draggable: Improve detection for when to blur the active element Draggable: Improve detection for when to blur the active element Feb 9, 2016
@arschmitz
Copy link
Member

LGTM

var element = $( "#draggable2" ).draggable( { handle: "span" } ),

// The handle is a descendant, but we also want to grab a descendant of the handle
handle = element.find( "span em" ),
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use onevar anymore.

Copy link

@adawit adawit Aug 17, 2016

Choose a reason for hiding this comment

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

This does regress on https://bugs.jqueryui.com/ticket/10527, but that only affects IE8.

This is not entirely correct. This change also regresses #10527 on the latest version of Chrome for me, Mac - El Capitan with Chrome version 52.0.2743.116 (64-bit) as well as FireFox 48.0 .

If you create a draggable bootstrap dialog with a text area and click inside of the text area, a blur event is fired even when the text area has the focus and the handle for Draggable is set to the header of the dialog.

Only solution for me was to downgrade to jquery-ui 1.11.4 where the _blurActiveElement method's behavior is different.

@scottgonzalez scottgonzalez deleted the draggable-blur branch February 9, 2016 18:38
@JoolsCaesar
Copy link

Is there any setting or easy way to disable this new behaviour? This broke an app I'm working on when we made the 1.12 upgrade. We use draggable for interface splitters and it's really annoying that a control loses focus when you're just trying to resize it by moving a sibling splitter. Before the update we explicitly prevented this behaviour by calling preventDefault on any splitter mousedowns, but these changes just ignore that.

@scottgonzalez
Copy link
Member Author

No. You could replace the method with your own logic if you really want to, but it's not a public method, so it can change at any time without notice.

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

Successfully merging this pull request may close these issues.

10 participants