diff --git a/src/gui/src/helpers/shareRecipientPicker.js b/src/gui/src/helpers/shareRecipientPicker.js index 16223703e..b7271ee4a 100644 --- a/src/gui/src/helpers/shareRecipientPicker.js +++ b/src/gui/src/helpers/shareRecipientPicker.js @@ -76,8 +76,13 @@ export default function shareRecipientPicker ({ const list_id = `share-suggest-list-${++picker_seq}`; const $field = $('
'); + // Both dialogs focus this field as they open, and an element that leaves + // the document — which is what moving it into the wrapper does — takes its + // focus with it. Put it back rather than leaving the caller to notice. + const had_focus = document.activeElement === $input.get(0); $input.before($field); $field.append($input); + if ( had_focus ) $input.get(0)?.focus({ preventScroll: true }); const $clear = $(``); $field.append($clear); diff --git a/src/gui/src/helpers/shareRecipientPicker.test.js b/src/gui/src/helpers/shareRecipientPicker.test.js index 761cac1cd..4160d35b5 100644 --- a/src/gui/src/helpers/shareRecipientPicker.test.js +++ b/src/gui/src/helpers/shareRecipientPicker.test.js @@ -38,7 +38,7 @@ beforeAll(async () => { let mounted = []; /** Renders the markup both dialogs share and attaches a picker to it. */ -const mount = (opts = {}) => { +const mount = ({ focus_first = false, ...opts } = {}) => { document.body.innerHTML = `