Show focus rings only during keyboard navigation
Automatic dialog focus, Escape, Delete and mouse clicks no longer draw focus outlines; Tab and arrow keys inside menus enable them. Text fields keep a neutral border instead of the blue glow. Informational text is no longer selectable while inputs, logs, links and error details stay copyable. Adds a shared fixed-position info tooltip.
This commit is contained in:
1 parent
0a2c75fd8b
commit
b52339cc94
2 files changed
+122
-13
No files matched your search
+100
@@ -58,6 +58,106 @@ const HOSTER_ADD_OPTIONS = [
|
||||
{ value: 'clouddrop.cc', label: 'Clouddrop (API)', hoster: 'clouddrop.cc', authType: 'api' }
|
||||
];
|
||||
|
||||
const KEYBOARD_NAVIGATION_ARROW_KEYS = new Set(['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End']);
|
||||
const KEYBOARD_NAVIGATION_CONTAINERS = '[role="menu"], [role="menubar"], [role="listbox"], [role="tablist"], [role="radiogroup"], .menu-dropdown, .menu-submenu-dropdown, .context-menu';
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.ctrlKey || event.altKey || event.metaKey) return;
|
||||
const navigatesByArrow = KEYBOARD_NAVIGATION_ARROW_KEYS.has(event.key) && event.target instanceof window.Element && event.target.closest(KEYBOARD_NAVIGATION_CONTAINERS);
|
||||
if (event.key === 'Tab' || navigatesByArrow) document.documentElement.classList.add('keyboard-navigation');
|
||||
}, true);
|
||||
|
||||
document.addEventListener('pointerdown', () => {
|
||||
document.documentElement.classList.remove('keyboard-navigation');
|
||||
}, true);
|
||||
|
||||
{
|
||||
let tooltip = null;
|
||||
let anchor = null;
|
||||
let pinned = false;
|
||||
const ensureTooltip = () => {
|
||||
if (!tooltip) {
|
||||
tooltip = document.createElement('div');
|
||||
tooltip.id = 'infoTooltip';
|
||||
tooltip.className = 'info-tooltip';
|
||||
tooltip.setAttribute('role', 'tooltip');
|
||||
document.body.append(tooltip);
|
||||
}
|
||||
return tooltip;
|
||||
};
|
||||
const positionTooltip = () => {
|
||||
if (!anchor || !tooltip) return;
|
||||
const margin = 12;
|
||||
const anchorRect = anchor.getBoundingClientRect();
|
||||
const tooltipRect = tooltip.getBoundingClientRect();
|
||||
const left = Math.max(margin, Math.min(anchorRect.left + anchorRect.width / 2 - tooltipRect.width / 2, window.innerWidth - tooltipRect.width - margin));
|
||||
let top = anchorRect.bottom + 8;
|
||||
if (top + tooltipRect.height > window.innerHeight - margin) top = Math.max(margin, anchorRect.top - tooltipRect.height - 8);
|
||||
tooltip.style.left = `${Math.round(left)}px`;
|
||||
tooltip.style.top = `${Math.round(top)}px`;
|
||||
};
|
||||
const hideTooltip = () => {
|
||||
if (!tooltip) return;
|
||||
tooltip.classList.remove('is-visible');
|
||||
anchor?.removeAttribute('aria-describedby');
|
||||
anchor = null;
|
||||
pinned = false;
|
||||
};
|
||||
let followGeneration = 0;
|
||||
const followAnchor = (generation) => {
|
||||
if (generation !== followGeneration || !anchor) return;
|
||||
if (!anchor.isConnected || anchor.getClientRects().length === 0) {
|
||||
hideTooltip();
|
||||
return;
|
||||
}
|
||||
positionTooltip();
|
||||
window.requestAnimationFrame(() => followAnchor(generation));
|
||||
};
|
||||
const showTooltip = (target, pin) => {
|
||||
if (anchor && anchor !== target) hideTooltip();
|
||||
const element = ensureTooltip();
|
||||
anchor = target;
|
||||
pinned = pin;
|
||||
element.textContent = target.getAttribute('data-tooltip') || '';
|
||||
target.setAttribute('aria-describedby', element.id);
|
||||
element.classList.add('is-visible');
|
||||
positionTooltip();
|
||||
const generation = ++followGeneration;
|
||||
window.requestAnimationFrame(() => followAnchor(generation));
|
||||
};
|
||||
const infoTipFrom = (node) => (node instanceof window.Element ? node.closest('.info-tip') : null);
|
||||
document.addEventListener('mouseover', (event) => {
|
||||
const target = infoTipFrom(event.target);
|
||||
if (target && !pinned && target !== anchor) showTooltip(target, false);
|
||||
});
|
||||
document.addEventListener('mouseout', (event) => {
|
||||
const target = infoTipFrom(event.target);
|
||||
if (target && target === anchor && !pinned && !target.contains(event.relatedTarget)) hideTooltip();
|
||||
});
|
||||
document.addEventListener('click', (event) => {
|
||||
const target = infoTipFrom(event.target);
|
||||
if (target) {
|
||||
event.preventDefault();
|
||||
if (target === anchor && pinned) hideTooltip();
|
||||
else showTooltip(target, true);
|
||||
} else if (pinned) {
|
||||
hideTooltip();
|
||||
}
|
||||
});
|
||||
document.addEventListener('focusin', (event) => {
|
||||
const target = infoTipFrom(event.target);
|
||||
if (target && document.documentElement.classList.contains('keyboard-navigation')) showTooltip(target, false);
|
||||
});
|
||||
document.addEventListener('focusout', (event) => {
|
||||
if (event.target === anchor && !pinned) hideTooltip();
|
||||
});
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape' && anchor) hideTooltip();
|
||||
}, true);
|
||||
window.addEventListener('scroll', () => { if (anchor) hideTooltip(); }, true);
|
||||
window.addEventListener('resize', () => { if (anchor) hideTooltip(); });
|
||||
}
|
||||
|
||||
// --- State ---
|
||||
let selectedFiles = []; // { path, name, size }
|
||||
let selectedUploadHosters = [];
|
||||
|
||||
+22
-13
@@ -36,11 +36,11 @@ body {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
:where(button, select, option, label, .app-header, .menu-bar, .view-sidebar, .settings-sidebar, .queue-table th, .recent-files-table th, .history-table th, .resize-handle, .context-menu, .modal-header, .modal-footer, .account-card-drag-handle, .account-hoster-group-header, .account-hoster-settings-header, .status-badge, .status-badge *) {
|
||||
:where(body, button, select, option, label, .app-header, .menu-bar, .view-sidebar, .settings-sidebar, .queue-table th, .recent-files-table th, .history-table th, .resize-handle, .context-menu, .modal-header, .modal-footer, .account-card-drag-handle, .account-hoster-group-header, .account-hoster-settings-header, .status-badge, .status-badge *) {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
:where(.health-badge, .account-status, .panel-status, .account-modal-status, .online-backup-status, .health-check-results, .account-hoster-group-meta.error, .recent-file-row.error, .history-row.error, .log-file-path-row .key-input, .log-paths-list, .log-paths-list *, #jobLogBody, .update-release-notes, .update-release-notes *, .history-link-text, .copy-toast) {
|
||||
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, [contenteditable="true"], code, .account-status, .account-modal-status, .health-check-results, .account-hoster-group-meta.error, .recent-file-row.error, .history-row.error, .log-file-path-row .key-input, .log-paths-list, .log-paths-list *, #jobLogBody, .update-release-notes, .update-release-notes *, .history-link-text) {
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
@@ -1018,7 +1018,7 @@ body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-sel
|
||||
#settingsSearchInput::placeholder { color: var(--text-dim); }
|
||||
#settingsSearchInput::-webkit-search-decoration { display: none; }
|
||||
#settingsSearchInput:placeholder-shown::-webkit-search-cancel-button { display: none; }
|
||||
#settingsSearchInput:focus { border-color: var(--accent); outline: none; }
|
||||
#settingsSearchInput:focus { border-color: var(--border-hover); outline: none; }
|
||||
.settings-navigation {
|
||||
position: relative;
|
||||
isolation: isolate;
|
||||
@@ -1204,7 +1204,7 @@ body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-sel
|
||||
background: none;
|
||||
border: none;
|
||||
}
|
||||
.key-input:focus, .hs-input:focus { border-color: var(--accent); outline: none; }
|
||||
.key-input:focus, .hs-input:focus { border-color: var(--border-hover); outline: none; }
|
||||
.hs-input { max-width: 100px; }
|
||||
select.hs-input { max-width: none; width: auto; min-width: 140px; }
|
||||
.hint { font-size: 10px; color: var(--text-dim); }
|
||||
@@ -1944,7 +1944,7 @@ select.hs-input { max-width: none; width: auto; min-width: 140px; }
|
||||
cursor: pointer;
|
||||
}
|
||||
.history-copy-link:hover,
|
||||
.history-copy-link:focus-visible {
|
||||
:where(html.keyboard-navigation) .history-copy-link:focus-visible {
|
||||
color: var(--text);
|
||||
border-color: var(--accent);
|
||||
background: var(--bg-hover);
|
||||
@@ -2041,18 +2041,22 @@ select.hs-input { max-width: none; width: auto; min-width: 140px; }
|
||||
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }
|
||||
|
||||
:where(button, input, select, textarea, [tabindex]):focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
:where(html.keyboard-navigation) :where(button, input, select, textarea, [tabindex]):focus-visible {
|
||||
outline: 2px solid var(--accent-end);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.key-input:focus-visible,
|
||||
.hs-input:focus-visible {
|
||||
:where(html.keyboard-navigation) .key-input:focus-visible,
|
||||
:where(html.keyboard-navigation) .hs-input:focus-visible {
|
||||
border-color: var(--accent);
|
||||
outline: 2px solid rgba(101, 216, 255, 0.45);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.menu-spinner input[type="text"]:focus-visible {
|
||||
:where(html.keyboard-navigation) .menu-spinner input[type="text"]:focus-visible {
|
||||
outline: 2px solid var(--accent-end);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
@@ -2315,6 +2319,11 @@ select.hs-input { max-width: none; width: auto; min-width: 140px; }
|
||||
}
|
||||
|
||||
.online-backup-retention-select select:focus {
|
||||
border-color: var(--border-hover);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
:where(html.keyboard-navigation) .online-backup-retention-select select:focus-visible {
|
||||
border-color: var(--accent);
|
||||
outline: 2px solid color-mix(in srgb, var(--accent) 32%, transparent);
|
||||
outline-offset: 1px;
|
||||
@@ -2679,7 +2688,7 @@ select.hs-input { max-width: none; width: auto; min-width: 140px; }
|
||||
}
|
||||
|
||||
.header-update-button:hover::after,
|
||||
.header-update-button:focus-visible::after {
|
||||
:where(html.keyboard-navigation) .header-update-button:focus-visible::after {
|
||||
opacity: 1;
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
@@ -3719,8 +3728,8 @@ select.hs-input { max-width: none; width: auto; min-width: 140px; }
|
||||
.key-input:focus,
|
||||
.hs-input:not([type="checkbox"]):focus,
|
||||
#settingsSearchInput:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(186, 208, 252, .12);
|
||||
border-color: var(--border-hover);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
@@ -3900,7 +3909,7 @@ input[type="checkbox"] {
|
||||
color: var(--accent-ink);
|
||||
}
|
||||
|
||||
.language-option:focus-visible {
|
||||
:where(html.keyboard-navigation) .language-option:focus-visible {
|
||||
outline: 2px solid var(--accent-end);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
@@ -4469,7 +4478,7 @@ input[type="checkbox"] {
|
||||
background: #5c5c5c;
|
||||
}
|
||||
|
||||
:where(button, input, select, textarea, [tabindex]):focus-visible {
|
||||
:where(html.keyboard-navigation) :where(button, input, select, textarea, [tabindex]):focus-visible {
|
||||
outline-color: var(--accent);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user