Skip to content

Commit

Permalink
i3438: allow autofocus on textareas in modals, not just inputs (#3439)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbergja committed Feb 28, 2023
1 parent d9d6a31 commit 0ea0afc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/javascript/orangelight/orangelight_ui_loader.es6
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class OrangelightUiLoader {

setup_modal_focus() {
$("body").on("shown.bs.modal", (event) => {
$(event.target).find('input[type!="hidden"]').first().focus();
$(event.target).find('input[type!="hidden"],textarea:enabled').first().focus();
})
}

Expand Down
16 changes: 16 additions & 0 deletions spec/javascript/orangelight/orangelight_ui_loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ describe('OrangelightUiLoader', function() {
expect(document.activeElement.id).toEqual('two')
})

test('Focus on first textarea', () => {
document.body.innerHTML =
'<div id="blacklight-modal">'+
'<input type="hidden" id="one">'+
'<textarea id="two-but-textarea"></textarea>'+
'<input type="text" id="three"></div>'
let l = new loader
l.setup_modal_focus()
expect(document.activeElement.id).toEqual('')

// trigger event
$("#blacklight-modal").trigger("shown.bs.modal")
// check for focus
expect(document.activeElement.id).toEqual('two-but-textarea')
})

test("Doesn't call Figgy if there's no IDs to call", () => {
document.body.innerHTML = ''
const spy = jest.spyOn(FiggyManifestManager, 'buildThumbnailSet')
Expand Down

0 comments on commit 0ea0afc

Please sign in to comment.