Files
immich-folio/components/ScrollToTop.tsx
ralksta c0740f0db5 a11y: remove ScrollToTop from tab order and hide from screen readers when not visible
- Added tabIndex={-1} when button is hidden to remove from keyboard tab order
- Added aria-hidden when not visible to hide from screen readers
- Added title attribute for tooltip text

Closes #6
2026-03-11 23:33:51 +01:00

41 lines
949 B
TypeScript

/**
* ScrollToTop — fixed ↑ button that appears after scrolling down.
* Smooth-scrolls back to the top when clicked.
*/
'use client';
import { useState, useEffect } from 'react';
const SHOW_THRESHOLD = 300;
export function ScrollToTop() {
const [visible, setVisible] = useState(false);
useEffect(() => {
const onScroll = () => {
setVisible(window.scrollY > SHOW_THRESHOLD);
};
window.addEventListener('scroll', onScroll, { passive: true });
return () => window.removeEventListener('scroll', onScroll);
}, []);
const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
return (
<button
className={`scroll-to-top ${visible ? 'scroll-to-top--visible' : ''}`}
onClick={scrollToTop}
aria-label="Scroll to top"
title="Scroll to top"
type="button"
tabIndex={visible ? 0 : -1}
aria-hidden={!visible}
>
↑
</button>
);
}