on master help sign in
Fix so that focus is still handled by the browser, not Elm.

This resolves the issue observed by Max and me in which focus always jumped to the first text field on the page. https://groups.google.com/forum/#!topic/elm-discuss/du9x7E9AkDE

commit284438d49498b4a888bfda9181f8f876a3da8b27 authorEvan Czaplicki <info@elm-lang.org> dateTue 4 Mar 2014, 07:56 (13 years ago) parentcbf7a86
1 file changed+11−6
libraries/Native/Graphics/Input.js+11−6
libraries/Native/Graphics/Input.js+11−6
@@ -268,9 +268,6 @@ Elm.Native.Graphics.Input.make = function(elm) {
268268 field.type = model.type;
269269 field.placeholder = JS.fromString(model.placeHolder);
270270 field.value = JS.fromString(model.content.string);
271− var selection = model.content.selection;
272− var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
273− setRange(field, selection.start, selection.end, direction);
274271
275272 field.elm_signal = model.signal;
276273 field.elm_handler = model.handler;
@@ -340,6 +337,12 @@ Elm.Native.Graphics.Input.make = function(elm) {
340337 field.addEventListener('keypress', keyUpdate);
341338 field.addEventListener('input', inputUpdate);
342339 field.addEventListener('mousedown', mousedown);
340+ field.addEventListener('focus', function() {
341+ field.elm_hasFocus = true;
342+ });
343+ field.addEventListener('blur', function() {
344+ field.elm_hasFocus = false;
345+ });
343346
344347 return field;
345348 }
@@ -356,9 +359,11 @@ Elm.Native.Graphics.Input.make = function(elm) {
356359 var value = JS.fromString(newModel.content.string);
357360 field.value = value;
358361 field.elm_old_value = value;
359− var selection = newModel.content.selection;
360− var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
361− setRange(field, selection.start, selection.end, direction);
362+ if (field.elm_hasFocus) {
363+ var selection = newModel.content.selection;
364+ var direction = selection.direction.ctor === 'Forward' ? 'forward' : 'backward';
365+ setRange(field, selection.start, selection.end, direction);
366+ }
362367 }
363368
364369 function mkField(type) {