Defocus buttons after pressing

Fixes #89.
This commit is contained in:
Florine W. Dekker 2020-08-17 13:10:49 +02:00
parent 71d61a8916
commit ae49acda9e
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
5 changed files with 23 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "minesweeper",
"version": "0.81.5",
"version": "0.81.6",
"description": "Just Minesweeper!",
"author": "Felix W. Dekker",
"browser": "dist/bundle.js",

View File

@ -7,11 +7,7 @@ form {
display: inline;
}
form button:focus:not(:hover) {
background-color: var(--fwdekker-theme-color);
}
form button.cancel, form button.cancel:focus, form button.cancel:hover {
form button.cancel {
background-color: #606c76;
border-color: #606c76;
}

View File

@ -20,6 +20,14 @@ export function shuffleArrayInPlace(array: any[], seed: number): any[] {
return array;
}
/**
* Blurs the currently active element, if possible.
*/
export function blurActiveElement(): void {
// @ts-ignore
document.activeElement?.blur?.();
}
/**
* Slices `array` into chunks of `chunkSize` elements each.
*

View File

@ -2,7 +2,7 @@
import {$} from "@fwdekker/template";
// @ts-ignore
import alea from "alea";
import {stringToHash} from "./Common";
import {blurActiveElement, stringToHash} from "./Common";
import {customDifficulty, defaultDifficulty, difficulties} from "./Difficulty";
import {BasicIconFont, Display, ForkAwesomeFont} from "./Display";
import {Field} from "./Field";
@ -140,6 +140,7 @@ export class Game {
event.preventDefault();
this.initNewField(this.field?.width, this.field?.height, this.field?.mineCount, this.field?.isSolvable);
blurActiveElement();
}
);
@ -151,6 +152,7 @@ export class Game {
event.preventDefault();
this.field?.undo(); // Undoes all
blurActiveElement();
}
);
@ -190,6 +192,7 @@ export class Game {
event.preventDefault();
this.field?.undo(1);
blurActiveElement();
}
);
@ -201,6 +204,7 @@ export class Game {
event.preventDefault();
this.field?.redo(1);
blurActiveElement();
}
);
@ -215,6 +219,7 @@ export class Game {
this.statistics.hintsRequested++;
this.display.hintSquare = (new Solver()).getHint(this.field);
}
blurActiveElement();
}
);
@ -229,6 +234,7 @@ export class Game {
this.statistics.solverUsages++;
(new Solver()).solve(this.field);
}
blurActiveElement();
}
);
@ -242,6 +248,7 @@ export class Game {
this.enableMarksInput.checked = preferences.marksEnabled;
this.preferencesOverlay.show();
blurActiveElement();
}
);
this.preferencesOverlay = new Overlay(
@ -260,6 +267,7 @@ export class Game {
event.preventDefault();
this.statisticsOverlay.show();
blurActiveElement();
}
);
this.statisticsOverlay = new Overlay(

View File

@ -1,3 +1,6 @@
import {blurActiveElement} from "./Common";
/**
* An overlay displayed in HTML.
*/
@ -72,6 +75,7 @@ export class Overlay {
*/
hide(): void {
this.overlay.style.visibility = "hidden";
blurActiveElement();
}
/**