Skip to content

Commit

Permalink
Focus nearby Remove button in storage manager when hitting Remove
Browse files Browse the repository at this point in the history
The window shouldn't lose focus when you press Remove.
  • Loading branch information
1j01 committed Feb 14, 2023
1 parent eee7179 commit 12a90c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/manage-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
const $message = $(E("p")).appendTo($storage_manager.$main).html(
"Any images you've saved to your computer with <b>File > Save</b> will not be affected."
);
$storage_manager.$Button("Close", () => {
const $close = $storage_manager.$Button("Close", () => {
$storage_manager.close();
});

Expand All @@ -63,6 +63,12 @@
$(E("td")).append($remove).appendTo($tr);

$remove.on("click", () => {
// Focus the next or previous row's remove button, or the close button if there are no more rows.
// Try focusing controls in reverse order of priority, so the highest priority control gets focus.
$close.focus();
$tr.prev().find(".remove-button").focus();
$tr.next().find(".remove-button").focus();

localStorage.removeItem(k);
$tr.remove();
if ($table.find("tr").length == 0) {
Expand Down

0 comments on commit 12a90c6

Please sign in to comment.