Tabs: strzałki wewnątrz ciemnego kontenera, widoczne i zajmujące miejsce tylko przy przepełnieniu/przewijaniu

This commit is contained in:
tisachi
2026-09-05 00:25:47 +02:00
parent e0f70ffa58
commit 741e833945

View File

@@ -216,7 +216,6 @@ export function Tabs({
onChange: (id: string) => void;
}) {
const scrollRef = useRef<HTMLDivElement>(null);
const [overflow, setOverflow] = useState(false);
const [canPrev, setCanPrev] = useState(false);
const [canNext, setCanNext] = useState(false);
@@ -224,7 +223,6 @@ export function Tabs({
const el = scrollRef.current;
if (!el) return;
const over = el.scrollWidth > el.clientWidth + 2;
setOverflow(over);
setCanPrev(over && el.scrollLeft > 2);
setCanNext(over && el.scrollLeft + el.clientWidth < el.scrollWidth - 2);
};
@@ -254,25 +252,25 @@ export function Tabs({
};
return (
<div data-slot="tabs" className="flex items-center gap-1.5">
{/* strzałki poza scrollem — nigdy nie nachodzą na zakładki; miejsce zarezerwowane,
żeby layout nie skakał przy przewijaniu */}
<div className={cn('shrink-0', overflow ? 'w-7' : 'w-0')}>
{canPrev && (
<button
type="button"
aria-label="Poprzednie zakładki"
onClick={() => scrollByGroup(-1)}
className="grid h-7 w-7 cursor-pointer place-items-center rounded-full border border-line bg-card text-dim shadow-card transition-colors hover:text-ink"
>
<ChevronLeft className="h-4 w-4" />
</button>
)}
</div>
<div
data-slot="tabs"
className="flex items-center gap-1 p-1 bg-input rounded-[10px] border border-line"
>
{/* strzałki wewnątrz kontenera, tylko gdy trzeba — zajmują miejsce tylko wtedy */}
{canPrev && (
<button
type="button"
aria-label="Poprzednie zakładki"
onClick={() => scrollByGroup(-1)}
className="grid h-7 w-7 shrink-0 cursor-pointer place-items-center rounded-full border border-line bg-card text-dim shadow-card transition-colors hover:text-ink"
>
<ChevronLeft className="h-4 w-4" />
</button>
)}
<div
ref={scrollRef}
onScroll={updateArrows}
className="flex min-w-0 flex-1 gap-1 p-1 bg-input rounded-[10px] border border-line overflow-x-auto [scroll-snap-type:x_mandatory] [scroll-padding-inline:4px] [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden"
className="flex min-w-0 flex-1 gap-1 overflow-x-auto [scroll-snap-type:x_mandatory] [scroll-padding-inline:4px] [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden"
>
{tabs.map((t) => (
<button
@@ -289,18 +287,16 @@ export function Tabs({
</button>
))}
</div>
<div className={cn('shrink-0', overflow ? 'w-7' : 'w-0')}>
{canNext && (
<button
type="button"
aria-label="Następne zakładki"
onClick={() => scrollByGroup(1)}
className="grid h-7 w-7 cursor-pointer place-items-center rounded-full border border-line bg-card text-dim shadow-card transition-colors hover:text-ink"
>
<ChevronRight className="h-4 w-4" />
</button>
)}
</div>
{canNext && (
<button
type="button"
aria-label="Następne zakładki"
onClick={() => scrollByGroup(1)}
className="grid h-7 w-7 shrink-0 cursor-pointer place-items-center rounded-full border border-line bg-card text-dim shadow-card transition-colors hover:text-ink"
>
<ChevronRight className="h-4 w-4" />
</button>
)}
</div>
);
}