Skip to content

Core: provide "includeHidden" parameter in $.ui.scrollParent, needed for a draggable fix #1307

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 5 commits into from

Conversation

mikesherov
Copy link
Member

Even though the user is unable to scroll via the UI, authors
may have custom scrollbars that programmatically set scrollTop.
Therefore, overflow:hidden must be considered scrollable.

@@ -56,7 +56,7 @@ $.fn.extend({
if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
return false;
}
return (/(auto|scroll)/).test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
return (/(auto|scroll|hidden)/).test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
Copy link
Member

Choose a reason for hiding this comment

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

It seems a little odd to consider an overflow: hidden element as a “scrollParent”, but I think I get why you're doing this here. I worry a bit about this having adverse in other cases.

@tjvantoll
Copy link
Member

There's some weird behavior in the test case with this patch applied: http://jsbin.com/ralivifo/11/edit. If you drag the red box around the edges of the container the interaction gets choppy. Not sure what's up or if this is related.

@mikesherov
Copy link
Member Author

@tjvantoll, what's happening now is that it's scrolling inside the parent because of the scroll: true option. :-\

@mikesherov
Copy link
Member Author

OK, so the problem here is that if we treat overflow: hidden as a scrollParent, then scroll: true will attempt to scroll when it hits the edge of an overflow: hidden container.

While this may be the correct behavior, it might be counterintuitive. Should I have scroll: true ignore scrollParent's that are hidden? Or should we change this behvaior here so that scroll: true will scroll an overflow: hidden?

@mikesherov
Copy link
Member Author

/cc @jzaefferer @scottgonzalez

@tjvantoll
Copy link
Member

Or should we change this behavior here so that scroll: true will scroll an overflow: hidden?

I don't like scrolling overflow: hidden containers, even when the scroll option is set. I agree that it probably should, but I think it'll catch a lot of people by surprise—especially when the default is true.

Should I have scroll: true ignore scrollParent's that are hidden?

And by hidden you mean overflow: hidden right? In that case yeah, at least I can't think of a better way of doing this.

@mikesherov
Copy link
Member Author

The other way to fix the draggable bug is to not modify the scrollParent method but rather check to see if the immediate parent of the draggable is different from the scrollParent but still happened to have a non-zero scrollTop/Left, and if so, add that in. This would preserve the correct behavior without having to account for shenanigans in scroll:true with overflow hidden.

@tjvantoll
Copy link
Member

That seems reasonable to me.

Even though the user is unable to scroll via the UI, authors
may have custom scrollbars that programmatically set scrollTop.
Therefore, overflow:hidden can be considered a scrollParent.
Developers can programmatically set scrollTop/Left on
draggable containers that are overflow:hidden. They must
be considered for positioning.

Fixes #10147
@mikesherov mikesherov changed the title Core: Treat overflow:hidden as scrollable in $.ui.scrollParent Core: provide "includeHidden" parameter in $.ui.scrollParent, needed for a draggable fix Aug 10, 2014
@mikesherov
Copy link
Member Author

@tjvantoll can you rereview. I took the approach of adding a param to $.ui.scrollParent() that also it to either consider or not consider overflow:hidden. This way, for the main draggable functionality, I can consider overflow:hidden as scrollable, and in the auto scroll fuctionality, not consider overflow:hidden elements at all.

Also, by providing a parameter, I can keep the existing behavior of scrollParent and not introduce any backCompat issues. The default, with no arguments, retains the old behavior.

/cc @scottgonzalez @jzaefferer

While it is true that overflow:hidden elements can be scrolled
programatically, this breaks user expectation. Therefore, do not
 scroll inside an overflow:hidden container.
@tjvantoll
Copy link
Member

This does fix the issue (http://jsbin.com/ralivifo/17/edit), but don't like the idea of adding a boolean parameter to .scrollParent(). That being said I don't have a better suggestion for how to implement this. I'd like at least one other opinion from @scottgonzalez or @jzaefferer before moving forward though.

Note that if we do move forward with this we would have to update the API docs too (http://api.jqueryui.com/scrollParent/).

@mikesherov
Copy link
Member Author

Only reason I made it public was because there exists a ticket or two where this question is open for debate.

Four ways to tackle this:

  1. Just don't document the parameter. Core has several undocumented params intended only for internal use.
  2. Move that function to $.ui._scrollParent, and make $.ui.scrollParent expose a version that is always called with false, a bit more formal.
  3. See if we can figure out how to move it into the closure, and make $.ui.scrollParent expose a version that is always called with false, truly protected.
  4. Actually document the parameter. 

    Sent from Mailbox

On Sun, Aug 10, 2014 at 1:44 PM, TJ VanToll notifications@github.com
wrote:

This does fix the issue (http://jsbin.com/ralivifo/17/edit), but don't like the idea of adding a boolean parameter to .scrollParent(). That being said I don't have a better suggestion for how to implement this. I'd like at least one other opinion from @scottgonzalez or @jzaefferer before moving forward though.

Note that if we do move forward with this we would have to update the API docs too (http://api.jqueryui.com/scrollParent/).

Reply to this email directly or view it on GitHub:
#1307 (comment)

@tjvantoll
Copy link
Member

I think it's fine to be public, and my vote would be to not document it.

@jzaefferer
Copy link
Member

I think it's fine to be public, and my vote would be to not document it.

Agreed. With the perspective of wiping this all away at some point in the future, eh?

@mikesherov
Copy link
Member Author

@jzaefferer scrollParent is already publicly documented. It's just this parameter that wouldn't be.

@jzaefferer
Copy link
Member

Sounds fine.

@mikesherov
Copy link
Member Author

Ok great! Then I'm going to land these changes.

@mikesherov
Copy link
Member Author

These are all now landed.

@mikesherov mikesherov closed this Aug 13, 2014
@mikesherov mikesherov deleted the t10147 branch August 19, 2014 00:21
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.

3 participants