diff --git a/app/assets/javascripts/templateFolderForm.js b/app/assets/javascripts/templateFolderForm.js index 1b81776c2..2c25398d4 100644 --- a/app/assets/javascripts/templateFolderForm.js +++ b/app/assets/javascripts/templateFolderForm.js @@ -19,10 +19,10 @@ this.states = [ {key: 'nothing-selected-buttons', $el: this.$form.find('#nothing_selected'), cancellable: false}, {key: 'items-selected-buttons', $el: this.$form.find('#items_selected'), cancellable: false}, - {key: 'move-to-existing-folder', $el: this.$form.find('#move_to_folder_radios'), cancellable: true}, - {key: 'move-to-new-folder', $el: this.$form.find('#move_to_new_folder_form'), cancellable: true}, - {key: 'add-new-folder', $el: this.$form.find('#add_new_folder_form'), cancellable: true}, - {key: 'add-new-template', $el: this.$form.find('#add_new_template_form'), cancellable: true} + {key: 'move-to-existing-folder', $el: this.$form.find('#move_to_folder_radios'), cancellable: true, setFocus: this.getFocusRoutine('#move_to_folder_radios fieldset', true)}, + {key: 'move-to-new-folder', $el: this.$form.find('#move_to_new_folder_form'), cancellable: true, setFocus: this.getFocusRoutine('#move_to_new_folder_name', false)}, + {key: 'add-new-folder', $el: this.$form.find('#add_new_folder_form'), cancellable: true, setFocus: this.getFocusRoutine('#add_new_folder_name', false)}, + {key: 'add-new-template', $el: this.$form.find('#add_new_template_form'), cancellable: true, setFocus: this.getFocusRoutine('#add_new_template_form fieldset', true)} ]; // cancel/clear buttons only relevant if JS enabled, so @@ -44,6 +44,18 @@ this.$form.on('change', 'input[type=checkbox]', () => this.templateFolderCheckboxChanged()); }; + this.getFocusRoutine = function (selector, setTabindex) { + return function () { + let $el = $(selector); + + if (setTabindex) { + $el.attr('tabindex', '-1'); + } + + $el.focus(); + }; + }; + this.activateStickyElements = function() { var oldClass = 'js-will-stick-at-bottom-when-scrolling'; var newClass = 'js-stick-at-bottom-when-scrolling'; @@ -139,13 +151,16 @@ }; this.render = function() { - var mode = 'default'; + let mode = 'default'; + let currentStateObj = this.states.filter(state => { return (state.key === this.currentState); })[0]; // detach everything, unless they are the currentState this.states.forEach( 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'; diff --git a/app/assets/stylesheets/components/stick-at-top-when-scrolling.scss b/app/assets/stylesheets/components/stick-at-top-when-scrolling.scss index 1c0b85cf7..44f21d426 100644 --- a/app/assets/stylesheets/components/stick-at-top-when-scrolling.scss +++ b/app/assets/stylesheets/components/stick-at-top-when-scrolling.scss @@ -4,11 +4,16 @@ .js-stick-at-top-when-scrolling, .js-stick-at-bottom-when-scrolling { - overflow: hidden; + @extend %contain-floats; margin-left: -$gutter-half; padding: 10px 0 0 $gutter-half; position: relative; + fieldset:focus { + outline: solid 3px $focus-colour; + outline-offset: $gutter-half; + } + .form-group { margin-bottom: 20px; }