Close client instructions panel on outside click
This commit is contained in:
@@ -97,6 +97,8 @@ export function ClientOverviewPage({
|
|||||||
const subscriptionInputRef = useRef(null);
|
const subscriptionInputRef = useRef(null);
|
||||||
const subscriptionRef = useRef(null);
|
const subscriptionRef = useRef(null);
|
||||||
const copyTimerRef = useRef(null);
|
const copyTimerRef = useRef(null);
|
||||||
|
const instructionsPanelRef = useRef(null);
|
||||||
|
const instructionsToggleRef = useRef(null);
|
||||||
const serverKey = servers.map((server) => `${server.tag}:${server.server}:${server.server_port}`).join('|');
|
const serverKey = servers.map((server) => `${server.tag}:${server.server}:${server.server_port}`).join('|');
|
||||||
const gatewayAddress = isGateway ? window.location.hostname : '127.0.0.1';
|
const gatewayAddress = isGateway ? window.location.hostname : '127.0.0.1';
|
||||||
const proxyUrls = localProxyUrls(state?.proxyPort, gatewayAddress);
|
const proxyUrls = localProxyUrls(state?.proxyPort, gatewayAddress);
|
||||||
@@ -210,6 +212,17 @@ export function ClientOverviewPage({
|
|||||||
return () => document.removeEventListener('keydown', closeOnEscape);
|
return () => document.removeEventListener('keydown', closeOnEscape);
|
||||||
}, [instructionsOpen]);
|
}, [instructionsOpen]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!instructionsOpen) return undefined;
|
||||||
|
const closeInstructionsOutside = (event) => {
|
||||||
|
if (instructionsPanelRef.current?.contains(event.target)) return;
|
||||||
|
if (instructionsToggleRef.current?.contains(event.target)) return;
|
||||||
|
setInstructionsOpen(false);
|
||||||
|
};
|
||||||
|
document.addEventListener('pointerdown', closeInstructionsOutside);
|
||||||
|
return () => document.removeEventListener('pointerdown', closeInstructionsOutside);
|
||||||
|
}, [instructionsOpen]);
|
||||||
|
|
||||||
async function toggleConnection() {
|
async function toggleConnection() {
|
||||||
const action = connectionAction({ connected, selectedTag, configExists: state?.configExists });
|
const action = connectionAction({ connected, selectedTag, configExists: state?.configExists });
|
||||||
if (action?.type === 'stop') return onStop();
|
if (action?.type === 'stop') return onStop();
|
||||||
@@ -278,6 +291,7 @@ export function ClientOverviewPage({
|
|||||||
return (
|
return (
|
||||||
<div className="client-shell">
|
<div className="client-shell">
|
||||||
{hasSubscription && <button
|
{hasSubscription && <button
|
||||||
|
ref={instructionsToggleRef}
|
||||||
className={`client-instructions-toggle${instructionsOpen ? ' is-open' : ''}`}
|
className={`client-instructions-toggle${instructionsOpen ? ' is-open' : ''}`}
|
||||||
type="button"
|
type="button"
|
||||||
aria-expanded={instructionsOpen}
|
aria-expanded={instructionsOpen}
|
||||||
@@ -542,6 +556,7 @@ export function ClientOverviewPage({
|
|||||||
</main>
|
</main>
|
||||||
|
|
||||||
{hasSubscription && <aside
|
{hasSubscription && <aside
|
||||||
|
ref={instructionsPanelRef}
|
||||||
id="client-instructions"
|
id="client-instructions"
|
||||||
className={`client-instructions${instructionsOpen ? ' is-open' : ''}`}
|
className={`client-instructions${instructionsOpen ? ' is-open' : ''}`}
|
||||||
aria-labelledby="instructions-title"
|
aria-labelledby="instructions-title"
|
||||||
|
|||||||
Reference in New Issue
Block a user