Add sticky header and scrollbar-gutter to SearchView

- Add scrollbar-gutter: stable to prevent layout shift when content scrolls
- Create sticky header that activates on scroll with:
  - Compact search input (bottom border only, muted accent, smaller height)
  - Tabs and filters remain visible
  - Title hidden when scrolled to save space
  - Box-shadow for visual separation
This commit is contained in:
vicrodh committed 2026-01-28 18:19:14 -06:00
1 parent b21979180e
commit fe2bc4b726
1 file changed
+85 -14
+85 -14
View File
@@ -12,6 +12,8 @@
let searchInput: HTMLInputElement | null = null;
let albumsCarouselContainer: HTMLDivElement | null = null;
let artistsCarouselContainer: HTMLDivElement | null = null;
let scrollContainer: HTMLDivElement | null = null;
let isScrolled = $state(false);
let currentAlbumPage = $state(0);
let currentArtistPage = $state(0);
let albumsPerPage = $state(5);
@@ -35,6 +37,11 @@
return () => window.removeEventListener('resize', handleResize);
});
function handleScroll(event: Event) {
const target = event.target as HTMLDivElement;
isScrolled = target.scrollTop > 60;
}
function handleResize() {
calculateAlbumsPerPage();
calculateArtistsPerPage();
@@ -548,12 +555,18 @@
);
</script>
<div class="search-view">
<!-- Search Header -->
<div class="search-header">
<h1>{$t('search.title')}</h1>
<div class="search-input-container">
<Search size={20} class="search-icon" />
<div class="search-view" bind:this={scrollContainer} onscroll={handleScroll}>
<!-- Search Header - title only when not scrolled -->
{#if !isScrolled}
<div class="search-header">
<h1>{$t('search.title')}</h1>
</div>
{/if}
<!-- Sticky Header Container -->
<div class="sticky-header" class:scrolled={isScrolled}>
<div class="search-input-container" class:compact={isScrolled}>
<Search size={isScrolled ? 18 : 20} class="search-icon" />
<input
type="text"
placeholder={$t('search.placeholder')}
@@ -568,10 +581,9 @@
</button>
{/if}
</div>
</div>
<!-- Tabs and Filters Row -->
<div class="tabs-row">
<!-- Tabs and Filters Row -->
<div class="tabs-row">
<div class="tabs">
<button
class="tab"
@@ -667,6 +679,7 @@
</div>
{/if}
</div>
</div>
<!-- Results -->
<div class="results">
@@ -1180,6 +1193,7 @@
padding-right: 24px;
padding-bottom: 100px;
overflow-y: auto;
scrollbar-gutter: stable;
}
/* Custom scrollbar */
@@ -1201,18 +1215,45 @@
}
.search-header {
margin-bottom: 24px;
margin-bottom: 16px;
}
.search-header h1 {
font-size: 24px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 16px;
margin-bottom: 0;
}
/* Sticky header */
.sticky-header {
position: sticky;
top: -24px;
z-index: 100;
padding-top: 0;
margin-left: -18px;
margin-right: -24px;
padding-left: 18px;
padding-right: 24px;
transition: background-color 150ms ease, padding-top 150ms ease, box-shadow 150ms ease;
}
.sticky-header.scrolled {
top: 0;
background-color: var(--bg-primary);
padding-top: 16px;
padding-bottom: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.search-input-container {
position: relative;
margin-bottom: 16px;
transition: margin-bottom 150ms ease;
}
.search-input-container.compact {
margin-bottom: 12px;
}
.search-input-container :global(.search-icon) {
@@ -1233,7 +1274,7 @@
font-size: 16px;
color: var(--text-primary);
outline: none;
transition: border-color 150ms ease;
transition: all 150ms ease;
}
.search-input:focus {
@@ -1244,6 +1285,31 @@
color: var(--text-muted);
}
/* Compact search input when scrolled */
.search-input-container.compact .search-input {
height: 40px;
padding: 0 40px 0 40px;
background-color: transparent;
border: none;
border-bottom: 2px solid var(--text-muted);
border-radius: 0;
font-size: 15px;
}
.search-input-container.compact .search-input:focus {
border-bottom-color: var(--accent-muted, var(--text-secondary));
}
.search-input-container.compact :global(.search-icon) {
left: 8px;
}
.search-input-container.compact .search-clear {
right: 4px;
width: 28px;
height: 28px;
}
.search-clear {
position: absolute;
right: 12px;
@@ -1272,9 +1338,13 @@
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 24px;
margin-bottom: 0;
border-bottom: 1px solid var(--bg-tertiary);
padding-bottom: 16px;
padding-bottom: 12px;
}
.sticky-header:not(.scrolled) .tabs-row {
margin-bottom: 24px;
}
.tabs {
@@ -1366,6 +1436,7 @@
.results {
min-height: 300px;
padding-top: 16px;
}
.loading, .empty-state, .error, .no-results {