Tram-One / tram-one

🚋 Legacy View Framework For Vanilla Javascript
http://tram-one.io/
MIT License
36 stars 8 forks source link

Fix input focus on re-ordered elements #164

Closed JRJurman closed 3 years ago

JRJurman commented 3 years ago

Summary

Fixes an issue where if the elements were re-ordered or changed significantly, we wouldn't be able to re-attach focus. Worse so, we never check if the element exists before trying to focus it, so we would get an error!

This PR also fixes an error where the scroll position would be reset when typing in an input.

Screenshots (Before)

When interacting with an input that has <span>-</span> for every letter in the input. This is what happens when typing and then deleting (this is the integration test app, which can be run locally with npm run test:app): image The first set of errors is because we are trying to setSelectionRange on a <span>, the second error is because after deleting no element exists at the index that the <input> was on.

Screenshots (After)

No errors :tada: image

Checklist

JRJurman commented 3 years ago

Looks good, a few questions, and can you provide any examples of it failing before/ success after?

Summary has been updated :+1: