Close client instructions panel on outside click
This commit is contained in:
@@ -97,6 +97,8 @@ export function ClientOverviewPage({
|
||||
const subscriptionInputRef = useRef(null);
|
||||
const subscriptionRef = 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 gatewayAddress = isGateway ? window.location.hostname : '127.0.0.1';
|
||||
const proxyUrls = localProxyUrls(state?.proxyPort, gatewayAddress);
|
||||
@@ -210,6 +212,17 @@ export function ClientOverviewPage({
|
||||
return () => document.removeEventListener('keydown', closeOnEscape);
|
||||
}, [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() {
|
||||
const action = connectionAction({ connected, selectedTag, configExists: state?.configExists });
|
||||
if (action?.type === 'stop') return onStop();
|
||||
@@ -278,6 +291,7 @@ export function ClientOverviewPage({
|
||||
return (
|
||||
<div className="client-shell">
|
||||
{hasSubscription && <button
|
||||
ref={instructionsToggleRef}
|
||||
className={`client-instructions-toggle${instructionsOpen ? ' is-open' : ''}`}
|
||||
type="button"
|
||||
aria-expanded={instructionsOpen}
|
||||
@@ -542,6 +556,7 @@ export function ClientOverviewPage({
|
||||
</main>
|
||||
|
||||
{hasSubscription && <aside
|
||||
ref={instructionsPanelRef}
|
||||
id="client-instructions"
|
||||
className={`client-instructions${instructionsOpen ? ' is-open' : ''}`}
|
||||
aria-labelledby="instructions-title"
|
||||
|
||||
Reference in New Issue
Block a user