diff --git a/app/assets/javascripts/autofocus.js b/app/assets/javascripts/autofocus.js index 2d276953f..299914e4b 100644 --- a/app/assets/javascripts/autofocus.js +++ b/app/assets/javascripts/autofocus.js @@ -2,9 +2,14 @@ "use strict"; Modules.Autofocus = function() { - this.start = function(component) { + this.start = function($component) { + var forceFocus = $component.data('forceFocus'); - $('input, textarea, select', component).eq(0).trigger('focus'); + // if the page loads with a scroll position, we can't assume the item to focus onload + // is still where users intend to start + if (($(window).scrollTop() > 0) && !forceFocus) { return; } + + $('input, textarea, select', $component).eq(0).trigger('focus'); }; }; diff --git a/app/templates/views/send-test.html b/app/templates/views/send-test.html index c84c5fbce..967f72a08 100644 --- a/app/templates/views/send-test.html +++ b/app/templates/views/send-test.html @@ -16,7 +16,8 @@ {% call form_wrapper( class='js-stick-at-top-when-scrolling send-one-off-form' if template.template_type != 'sms' else 'send-one-off-form', - module="autofocus" + module="autofocus", + data_kwargs={'forceFocus': True} ) %}