Put shift in focus after change to state

Moving focus before letting the sticky JS set the
position of sticky elements means focus is shifted
to them when they are still in the page. This
causes the browser to scroll so the focused
elements are visible.

This moves when focus is set to after the sticky
JS has set position therefore avoiding the issue.
This commit is contained in:
Tom Byers
2019-02-08 15:22:13 +00:00
parent 693ddadbc4
commit 4c477d08a6

View File

@@ -170,8 +170,6 @@
state => (state.key === this.currentState ? this.$stickyBottom.append(state.$el) : state.$el.detach())
);
if (currentStateObj && ('setFocus' in currentStateObj)) { currentStateObj.setFocus(); }
// use dialog mode for states which contain more than one form control
if (['move-to-existing-folder', 'add-new-template'].indexOf(this.currentState) !== -1) {
mode = 'dialog';
@@ -179,6 +177,8 @@
GOVUK.stickAtBottomWhenScrolling.setMode(mode);
// make sticky JS recalculate its cache of the element's position
GOVUK.stickAtBottomWhenScrolling.recalculate();
if (currentStateObj && ('setFocus' in currentStateObj)) { currentStateObj.setFocus(); }
};
this.nothingSelectedButtons = $(`