Skip to content

Commit 82f33e9

Browse files
committed
fix <select> scroll issue in chrome (win), fixes #5257
tweak sidebar scroller so as not to set the body class if it's not actually changing. this keeps chrome from repainting unnecessarily, which was the reason why the <select> kept jumping back to the first option every second. Change-Id: I1c42cf89ec0f68dca2b49f8e1564c0b8d682d9dc Reviewed-on: https://gerrit.instructure.com/6200 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Shaw <ryan@instructure.com>
1 parent 08a054f commit 82f33e9

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

public/javascripts/jquery.instructure_misc_helpers.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,15 @@ I18n.scoped('instructure', function(I18n) {
183183
notRightSideIsTallerThanRightSide = notRightSideHeight > rightSideHeight,
184184
rightSideBottomIsBelowMainBottom = ( headerHeight + $main.height() - windowScrollTop ) <= ( rightSideHeight + rightSideMarginBottom );
185185
}
186-
$body
187-
.toggleClass('with-scrolling-right-side', windowScrollIsBelowHeader && notRightSideIsTallerThanRightSide && !rightSideBottomIsBelowMainBottom)
188-
.toggleClass('with-sidebar-pinned-to-bottom', windowScrollIsBelowHeader && notRightSideIsTallerThanRightSide && rightSideBottomIsBelowMainBottom);
186+
// windows chrome repaints when you set the class, even if the classes
187+
// aren't truly changing, which wreaks havoc on open select elements.
188+
// so we only toggle if we really need to
189+
if ((windowScrollIsBelowHeader && notRightSideIsTallerThanRightSide && !rightSideBottomIsBelowMainBottom) ^ $body.hasClass('with-scrolling-right-side')) {
190+
$body.toggleClass('with-scrolling-right-side');
191+
}
192+
if ((windowScrollIsBelowHeader && notRightSideIsTallerThanRightSide && rightSideBottomIsBelowMainBottom) ^ $body.hasClass('with-sidebar-pinned-to-bottom')) {
193+
$body.toggleClass('with-sidebar-pinned-to-bottom');
194+
}
189195
}
190196
onScroll();
191197
$window.scroll(onScroll);

spec/selenium/layout_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/common')
2+
3+
describe "layout selenium tests" do
4+
it_should_behave_like "in-process server selenium tests"
5+
6+
7+
it "should auto-scroll the sidebar when $.scrollSidebar is called" do
8+
course_with_student_logged_in
9+
get "/"
10+
driver.execute_script('$("#not_right_side").height(10000)')
11+
driver.execute_script('$("#right-side-wrapper").height(5000)')
12+
driver.execute_script('$.scrollSidebar()')
13+
body = driver.find_element(:tag_name, 'body')
14+
body.attribute(:class).should_not match /with-scrolling-right-side/
15+
body.attribute(:class).should_not match /with-sidebar-pinned-to-bottom/
16+
17+
driver.find_element(:id, 'footer').location_once_scrolled_into_view
18+
body.attribute(:class).should_not match /with-scrolling-right-side/
19+
body.attribute(:class).should match /with-sidebar-pinned-to-bottom/
20+
21+
driver.find_element(:id, 'topic_list').location_once_scrolled_into_view
22+
body.attribute(:class).should match /with-scrolling-right-side/
23+
body.attribute(:class).should_not match /with-sidebar-pinned-to-bottom/
24+
25+
driver.find_element(:id, 'header').location_once_scrolled_into_view
26+
body.attribute(:class).should_not match /with-scrolling-right-side/
27+
body.attribute(:class).should_not match /with-sidebar-pinned-to-bottom/
28+
end
29+
end

0 commit comments

Comments
 (0)