Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Tweak browser extension UI to make scrollbar appear as overlay (#2455)

Leendert de Borstc75fde37e2f8
diff --git a/apps/browser-extension/src/entrypoints/popup/App.tsx b/apps/browser-extension/src/entrypoints/popup/App.tsx
index 57b11875f..bf1408c2b 100644
--- a/apps/browser-extension/src/entrypoints/popup/App.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/App.tsx
@@ -1,10 +1,11 @@
import { CapabilityKeys } from '@aliasvault/models/webapi';
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { HashRouter as Router, Routes, Route, useLocation } from 'react-router-dom';
import DefaultLayout from '@/entrypoints/popup/components/Layout/DefaultLayout';
import Header from '@/entrypoints/popup/components/Layout/Header';
+import OverlayScrollbar from '@/entrypoints/popup/components/Layout/OverlayScrollbar';
import PasskeyLayout from '@/entrypoints/popup/components/Layout/PasskeyLayout';
import LoadingSpinner from '@/entrypoints/popup/components/LoadingSpinner';
import { useApp } from '@/entrypoints/popup/context/AppContext';
@@ -85,6 +86,7 @@ const AppContent: React.FC<{
headerButtons: React.ReactNode;
}> = ({ routes, isLoading, message, headerButtons }) => {
const location = useLocation();
+ const authMainRef = useRef<HTMLElement>(null);
// Find the current route configuration
const currentRoute = routes.find(route => {
@@ -140,7 +142,8 @@ const AppContent: React.FC<{
rightButtons={headerButtons}
/>
<main
- className="flex-1 overflow-y-auto bg-gray-100 dark:bg-gray-900"
+ ref={authMainRef}
+ className="flex-1 overflow-y-auto no-scrollbar bg-gray-100 dark:bg-gray-900"
style={{
paddingTop: '64px',
height: '100%',
@@ -153,6 +156,7 @@ const AppContent: React.FC<{
)}
{routesComponent}
</main>
+ <OverlayScrollbar targetRef={authMainRef} />
</div>
);
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/BottomNav.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/BottomNav.tsx
index e59a3ed33..dadc110ff 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/BottomNav.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/BottomNav.tsx
@@ -57,7 +57,7 @@ const BottomNav: React.FC = () => {
}
return (
- <div className="fixed bottom-0 left-0 right-0 bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700">
+ <div data-bottom-nav className="fixed bottom-0 left-0 right-0 bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700">
<div className="flex justify-around items-center h-14">
<button
onClick={() => handleTabChange('items')}
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx
index 6fafaa3b8..93b7ec769 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/DefaultLayout.tsx
@@ -6,6 +6,7 @@ import { ClipboardCountdownBar } from '@/entrypoints/popup/components/ClipboardC
import Modal from '@/entrypoints/popup/components/Dialogs/Modal';
import BottomNav from '@/entrypoints/popup/components/Layout/BottomNav';
import Header from '@/entrypoints/popup/components/Layout/Header';
+import OverlayScrollbar from '@/entrypoints/popup/components/Layout/OverlayScrollbar';
import { useDb } from '@/entrypoints/popup/context/DbContext';
/**
@@ -56,7 +57,7 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ routes, headerButtons, me
<main
ref={mainRef}
- className="flex-1 overflow-y-auto bg-gray-100 dark:bg-gray-900"
+ className="flex-1 overflow-y-auto no-scrollbar bg-gray-100 dark:bg-gray-900"
style={{
paddingTop: '64px',
height: 'calc(100% - 120px)',
@@ -79,6 +80,7 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ routes, headerButtons, me
)}
</div>
</main>
+ <OverlayScrollbar targetRef={mainRef} />
<BottomNav />
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/OverlayScrollbar.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/OverlayScrollbar.tsx
new file mode 100644
index 000000000..3eb736bc9
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/OverlayScrollbar.tsx
@@ -0,0 +1,139 @@
+import React, { useCallback, useEffect, useRef, useState } from 'react';
+
+type OverlayScrollbarProps = {
+ targetRef: React.RefObject<HTMLElement | null>;
+};
+
+type ThumbGeometry = {
+ top: number;
+ right: number;
+ height: number;
+};
+
+const HIDE_DELAY_MS = 1000;
+const MIN_THUMB_HEIGHT = 24;
+
+/**
+ * The part of the container not covered by the fixed popup header and bottom nav.
+ */
+const getTrack = (el: HTMLElement): { top: number; height: number } => {
+ const rect = el.getBoundingClientRect();
+ const header = document.querySelector('header');
+ const bottomNav = document.querySelector('[data-bottom-nav]');
+ const top = Math.max(rect.top, header?.getBoundingClientRect().bottom ?? rect.top);
+ const bottom = Math.min(rect.bottom, window.innerHeight, bottomNav?.getBoundingClientRect().top ?? rect.bottom);
+ return { top, height: bottom - top };
+};
+
+/**
+ * Scroll thumb drawn over the content, so it takes no width away from the popup. Shown while scrolling, hovered or dragged.
+ */
+const OverlayScrollbar: React.FC<OverlayScrollbarProps> = ({ targetRef }) => {
+ const [geometry, setGeometry] = useState<ThumbGeometry | null>(null);
+ const [isScrolling, setIsScrolling] = useState(false);
+ const [isHovered, setIsHovered] = useState(false);
+ const [isDragging, setIsDragging] = useState(false);
+ const hideTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const dragRef = useRef<{ startY: number; startScrollTop: number; scrollPerPixel: number } | null>(null);
+
+ /**
+ * Measure the container and place the thumb, or drop it when nothing scrolls.
+ */
+ const measure = useCallback((): void => {
+ const el = targetRef.current;
+ if (!el || el.scrollHeight <= el.clientHeight + 1) {
+ setGeometry(null);
+ return;
+ }
+ const track = getTrack(el);
+ const height = Math.max(MIN_THUMB_HEIGHT, track.height * (el.clientHeight / el.scrollHeight));
+ const progress = el.scrollTop / (el.scrollHeight - el.clientHeight);
+ setGeometry({ top: track.top + (track.height - height) * progress, right: window.innerWidth - el.getBoundingClientRect().right + 2, height });
+ }, [targetRef]);
+
+ useEffect(() => {
+ const el = targetRef.current;
+ if (!el) {
+ return;
+ }
+
+ /**
+ * Show the thumb and hide it again once scrolling stops.
+ */
+ const onScroll = (): void => {
+ measure();
+ setIsScrolling(true);
+ if (hideTimerRef.current) {
+ clearTimeout(hideTimerRef.current);
+ }
+ hideTimerRef.current = setTimeout(() => setIsScrolling(false), HIDE_DELAY_MS);
+ };
+
+ el.addEventListener('scroll', onScroll, { passive: true });
+ return (): void => {
+ el.removeEventListener('scroll', onScroll);
+ if (hideTimerRef.current) {
+ clearTimeout(hideTimerRef.current);
+ }
+ };
+ }, [targetRef, measure]);
+
+ /**
+ * Start dragging the thumb.
+ */
+ const onPointerDown = (e: React.PointerEvent<HTMLDivElement>): void => {
+ const el = targetRef.current;
+ if (!el || !geometry) {
+ return;
+ }
+ const freeTrack = getTrack(el).height - geometry.height;
+ dragRef.current = { startY: e.clientY, startScrollTop: el.scrollTop, scrollPerPixel: freeTrack > 0 ? (el.scrollHeight - el.clientHeight) / freeTrack : 0 };
+ e.currentTarget.setPointerCapture(e.pointerId);
+ setIsDragging(true);
+ e.preventDefault();
+ };
+
+ /**
+ * Scroll the container along with the dragged thumb.
+ */
+ const onPointerMove = (e: React.PointerEvent<HTMLDivElement>): void => {
+ const el = targetRef.current;
+ const drag = dragRef.current;
+ if (!el || !drag) {
+ return;
+ }
+ el.scrollTop = drag.startScrollTop + (e.clientY - drag.startY) * drag.scrollPerPixel;
+ };
+
+ /**
+ * Stop dragging the thumb.
+ */
+ const onPointerUp = (e: React.PointerEvent<HTMLDivElement>): void => {
+ dragRef.current = null;
+ e.currentTarget.releasePointerCapture(e.pointerId);
+ setIsDragging(false);
+ };
+
+ if (!geometry) {
+ return null;
+ }
+
+ const isVisible = isScrolling || isHovered || isDragging;
+ return (
+ <div
+ aria-hidden="true"
+ className={`fixed z-20 w-2.5 flex justify-center transition-opacity duration-300 ${isVisible ? 'opacity-100' : 'opacity-0 pointer-events-none'}`}
+ style={{ top: geometry.top, right: geometry.right, height: geometry.height }}
+ onPointerDown={onPointerDown}
+ onPointerMove={onPointerMove}
+ onPointerUp={onPointerUp}
+ onPointerCancel={onPointerUp}
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
+ >
+ <div className={`h-full rounded-full transition-all ${isHovered || isDragging ? 'w-2 bg-gray-500/70 dark:bg-gray-400/70' : 'w-1.5 bg-gray-500/50 dark:bg-gray-400/50'}`} />
+ </div>
+ );
+};
+
+export default OverlayScrollbar;
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Layout/PasskeyLayout.tsx b/apps/browser-extension/src/entrypoints/popup/components/Layout/PasskeyLayout.tsx
index 4b9648571..6dfa7640e 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Layout/PasskeyLayout.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Layout/PasskeyLayout.tsx
@@ -1,5 +1,6 @@
-import React from 'react';
+import React, { useRef } from 'react';
+import OverlayScrollbar from '@/entrypoints/popup/components/Layout/OverlayScrollbar';
import Logo from '@/entrypoints/popup/components/Logo';
/**
@@ -7,6 +8,8 @@ import Logo from '@/entrypoints/popup/components/Logo';
* Shows only the AliasVault logo header, no navigation, no footer.
*/
const PasskeyLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
+ const mainRef = useRef<HTMLElement>(null);
+
return (
<div className="min-h-screen min-w-[350px] bg-white dark:bg-gray-900 flex flex-col max-h-[600px]">
{/* Minimal header with just logo */}
@@ -27,7 +30,8 @@ const PasskeyLayout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
{/* Main content without footer padding */}
<main
- className="flex-1 overflow-y-auto bg-gray-100 dark:bg-gray-900"
+ ref={mainRef}
+ className="flex-1 overflow-y-auto no-scrollbar bg-gray-100 dark:bg-gray-900"
style={{
paddingTop: '64px',
}}
@@ -36,6 +40,7 @@ const PasskeyLayout: React.FC<{ children: React.ReactNode }> = ({ children }) =>
{children}
</div>
</main>
+ <OverlayScrollbar targetRef={mainRef} />
</div>
);
};
diff --git a/apps/browser-extension/src/entrypoints/popup/style.css b/apps/browser-extension/src/entrypoints/popup/style.css
index 05b4042ea..0b020033e 100644
--- a/apps/browser-extension/src/entrypoints/popup/style.css
+++ b/apps/browser-extension/src/entrypoints/popup/style.css
@@ -5,3 +5,52 @@ html {
body {
font-size: 100%;
}
+
+html {
+ color-scheme: light;
+}
+
+html.dark {
+ color-scheme: dark;
+}
+
+/** Scrollbar customization */
+@supports not selector(::-webkit-scrollbar) {
+ * {
+ scrollbar-width: thin;
+ scrollbar-color: rgb(156 163 175 / 0.5) transparent;
+ }
+
+ html.dark * {
+ scrollbar-color: rgb(107 114 128 / 0.6) transparent;
+ }
+}
+
+::-webkit-scrollbar {
+ width: 8px;
+ height: 8px;
+}
+
+::-webkit-scrollbar-track,
+::-webkit-scrollbar-corner {
+ background: transparent;
+}
+
+::-webkit-scrollbar-thumb {
+ background-color: rgb(156 163 175 / 0.5);
+ border: 2px solid transparent;
+ border-radius: 9999px;
+ background-clip: padding-box;
+}
+
+::-webkit-scrollbar-thumb:hover {
+ background-color: rgb(107 114 128 / 0.8);
+}
+
+html.dark ::-webkit-scrollbar-thumb {
+ background-color: rgb(107 114 128 / 0.5);
+}
+
+html.dark ::-webkit-scrollbar-thumb:hover {
+ background-color: rgb(156 163 175 / 0.7);
+}