Skip to content
Snippets Groups Projects
Verified Commit ac502a3b authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

fix: wrong UX for keyboard focus and fullscreen

parent 1d1f54f2
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
* Arrow keys usage for on-screen gamepad * Arrow keys usage for on-screen gamepad
* Wrong UX for keyboard focus and fullscreen
## [0.4.1] - 2022-11-06 ## [0.4.1] - 2022-11-06
......
...@@ -21,7 +21,7 @@ export const Button: FC<ButtonProps> = ({ ...@@ -21,7 +21,7 @@ export const Button: FC<ButtonProps> = ({
image, image,
imageAlt, imageAlt,
enabled = false, enabled = false,
focusable = false, focusable = true,
file = false, file = false,
accept = ".txt", accept = ".txt",
size = "small", size = "small",
......
...@@ -100,5 +100,11 @@ ...@@ -100,5 +100,11 @@
} }
.display > .display-frame > .display-canvas { .display > .display-frame > .display-canvas {
outline: none;
-o-outline: none;
-ms-outline: none;
-moz-outline: none;
-khtml-outline: none;
-webkit-outline: none;
width: 100%; width: 100%;
} }
...@@ -88,6 +88,7 @@ export const Display: FC<DisplayProps> = ({ ...@@ -88,6 +88,7 @@ export const Display: FC<DisplayProps> = ({
useEffect(() => { useEffect(() => {
if (fullscreen) { if (fullscreen) {
canvasRef.current?.focus();
resizeRef.current(); resizeRef.current();
document.getElementsByTagName("body")[0].style.overflow = "hidden"; document.getElementsByTagName("body")[0].style.overflow = "hidden";
window.addEventListener("resize", resizeRef.current); window.addEventListener("resize", resizeRef.current);
...@@ -139,6 +140,7 @@ export const Display: FC<DisplayProps> = ({ ...@@ -139,6 +140,7 @@ export const Display: FC<DisplayProps> = ({
> >
<canvas <canvas
ref={canvasRef} ref={canvasRef}
tabIndex={-1}
className="display-canvas" className="display-canvas"
width={options.width * options.scale} width={options.width * options.scale}
height={options.height * options.scale} height={options.height * options.scale}
......
...@@ -67,8 +67,8 @@ ...@@ -67,8 +67,8 @@
.keyboard-gb > .dpad .key { .keyboard-gb > .dpad .key {
border: none; border: none;
padding: 0px 0px 0px 0px;
font-size: 24px; font-size: 24px;
padding: 0px 0px 0px 0px;
} }
.keyboard-gb > .dpad .key.pressed { .keyboard-gb > .dpad .key.pressed {
...@@ -113,8 +113,8 @@ ...@@ -113,8 +113,8 @@
-webkit-border-radius: 0px 6px 6px 0px; -webkit-border-radius: 0px 6px 6px 0px;
border-right: 3px solid #ffffff; border-right: 3px solid #ffffff;
border-top: 3px solid #ffffff; border-top: 3px solid #ffffff;
margin-right: 0px;
margin-left: -3px; margin-left: -3px;
margin-right: 0px;
} }
.keyboard-gb > .dpad .key.center { .keyboard-gb > .dpad .key.center {
...@@ -155,10 +155,10 @@ ...@@ -155,10 +155,10 @@
-webkit-border-radius: 32px 32px 32px 32px; -webkit-border-radius: 32px 32px 32px 32px;
border-width: 3px; border-width: 3px;
font-size: 30px; font-size: 30px;
font-weight: 900;
height: 58px; height: 58px;
line-height: 52px; line-height: 52px;
width: 58px; width: 58px;
font-weight: 900;
} }
.keyboard-gb > .action > .key.a { .keyboard-gb > .action > .key.a {
...@@ -179,12 +179,12 @@ ...@@ -179,12 +179,12 @@
.keyboard-gb > .options > .key { .keyboard-gb > .options > .key {
font-size: 14px; font-size: 14px;
font-weight: 900;
height: 30px; height: 30px;
line-height: 26px; line-height: 26px;
margin-left: 16px; margin-left: 16px;
margin-right: 16px; margin-right: 16px;
min-width: 100px; min-width: 100px;
font-weight: 900;
} }
.keyboard-gb > .break { .keyboard-gb > .break {
......
...@@ -58,6 +58,12 @@ ...@@ -58,6 +58,12 @@
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.5); -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.5);
margin-top: 30px; margin-top: 30px;
max-width: 100%; max-width: 100%;
outline: none;
-o-outline: none;
-ms-outline: none;
-moz-outline: none;
-khtml-outline: none;
-webkit-outline: none;
padding: 24px 24px 24px 24px; padding: 24px 24px 24px 24px;
text-align: left; text-align: left;
transform: scale(0.96); transform: scale(0.96);
......
import React, { FC, useEffect } from "react"; import React, { FC, useEffect, useRef } from "react";
import Button from "../button/button"; import Button from "../button/button";
import "./modal.css"; import "./modal.css";
...@@ -26,6 +26,7 @@ export const Modal: FC<ModalProps> = ({ ...@@ -26,6 +26,7 @@ export const Modal: FC<ModalProps> = ({
}) => { }) => {
const classes = () => const classes = () =>
["modal", visible ? "visible" : "", ...style].join(" "); ["modal", visible ? "visible" : "", ...style].join(" ");
const modalRef = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => { const onKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") { if (event.key === "Escape") {
...@@ -37,6 +38,11 @@ export const Modal: FC<ModalProps> = ({ ...@@ -37,6 +38,11 @@ export const Modal: FC<ModalProps> = ({
document.removeEventListener("keydown", onKeyDown); document.removeEventListener("keydown", onKeyDown);
}; };
}, []); }, []);
useEffect(() => {
if (visible) {
modalRef.current?.focus();
}
}, [visible]);
const getTextHtml = (separator = /\n/g) => ({ const getTextHtml = (separator = /\n/g) => ({
__html: text.replace(separator, "<br/>") __html: text.replace(separator, "<br/>")
}); });
...@@ -48,7 +54,12 @@ export const Modal: FC<ModalProps> = ({ ...@@ -48,7 +54,12 @@ export const Modal: FC<ModalProps> = ({
}; };
return ( return (
<div className={classes()} onClick={onCancel}> <div className={classes()} onClick={onCancel}>
<div className="modal-window" onClick={onWindowClick}> <div
ref={modalRef}
className="modal-window"
onClick={onWindowClick}
tabIndex={-1}
>
<div className="modal-top-buttons"> <div className="modal-top-buttons">
<Button <Button
text={""} text={""}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment