Skip to content

Commit 4b8d026

Browse files
committed
Selectable: proper handling of inner scrolling
Fixes #13359
1 parent 4d7c123 commit 4b8d026

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

ui/widgets/selectable.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ return $.widget( "ui.selectable", $.ui.mouse, {
5757

5858
// Cache selectee children based on filter
5959
this.refresh = function() {
60+
that.elementPos = $( that.element[0] ).offset();
6061
that.selectees = $( that.options.filter, that.element[ 0 ] );
6162
that._addClass( that.selectees, "ui-selectee" );
6263
that.selectees.each( function() {
6364
var $this = $( this ),
64-
pos = $this.offset();
65+
selecteeOffset = $this.offset(),
66+
pos = {
67+
left: selecteeOffset.left - that.elementPos.left,
68+
top: selecteeOffset.top - that.elementPos.top
69+
};
6570
$.data( this, "selectable-item", {
6671
element: this,
6772
$element: $this,
@@ -94,6 +99,7 @@ return $.widget( "ui.selectable", $.ui.mouse, {
9499
options = this.options;
95100

96101
this.opos = [ event.pageX, event.pageY ];
102+
this.elementPos = $(this.element[0]).offset();
97103

98104
if ( this.options.disabled ) {
99105
return;
@@ -182,17 +188,23 @@ return $.widget( "ui.selectable", $.ui.mouse, {
182188

183189
this.selectees.each( function() {
184190
var selectee = $.data( this, "selectable-item" ),
185-
hit = false;
191+
hit = false,
192+
offset = {};
186193

187194
//prevent helper from being selected if appendTo: selectable
188195
if ( !selectee || selectee.element === that.element[ 0 ] ) {
189196
return;
190197
}
191198

199+
offset.left = selectee.left + that.elementPos.left;
200+
offset.right = selectee.right + that.elementPos.left;
201+
offset.top = selectee.top + that.elementPos.top;
202+
offset.bottom = selectee.bottom + that.elementPos.top;
203+
192204
if ( options.tolerance === "touch" ) {
193-
hit = ( !( selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1 ) );
194-
} else if ( options.tolerance === "fit" ) {
195-
hit = ( selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2 );
205+
hit = !( offset.left > x2 || offset.right < x1 || offset.top > y2 || offset.bottom < y1 );
206+
} else if (options.tolerance === "fit") {
207+
hit = ( offset.left > x1 && offset.right < x2 && offset.top > y1 && offset.bottom < y2 );
196208
}
197209

198210
if ( hit ) {

0 commit comments

Comments
 (0)