Skip to content

Commit f9e8a46

Browse files
committed
prevent slide cta from disappearing on scroll
1 parent a5857c8 commit f9e8a46

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/assets/App.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ a {
107107
overflow-y: hidden;
108108
justify-content: space-between;
109109
scroll-snap-type: x mandatory;
110-
scroll-padding-left: 12px;
111110
padding-top: 2vh;
112111
height: 87vh;
113112
}
@@ -862,7 +861,6 @@ Producthunt item
862861
border: none;
863862
position: absolute;
864863
top: 45%;
865-
margin: 0 1%;
866864
background-color: var(--card-action-button-background);
867865
color: var(--card-action-button-color);
868866
opacity: 0.8;

src/components/Layout/ScrollCardsNavigator.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ import { useUserPreferences } from 'src/stores/preferences'
66

77
export const ScrollCardsNavigator = () => {
88
const { cards } = useUserPreferences()
9-
const [leftButtonVisible, setLeftButtonVisible] = useState(true)
10-
const [rightButtonVisible, setRightButtonVisible] = useState(true)
9+
const [leftButtonVisible, setLeftButtonVisible] = useState(false)
10+
const [rightButtonVisible, setRightButtonVisible] = useState(false)
1111
const scrollBarContainer = useRef<HTMLElement | null>(null)
12+
const CARDS = 'Cards'
1213

1314
const handleScroll = (e: Event) => {
15+
const target = e.target as HTMLElement
16+
17+
// Prevent scrolling conflicts between CARDS and children
18+
if (!target.classList.contains(CARDS)) {
19+
return
20+
}
21+
1422
if (cards.length <= maxCardsPerRow) {
1523
setLeftButtonVisible(false)
1624
setRightButtonVisible(false)
1725
} else {
18-
const { scrollLeft, scrollWidth, offsetWidth } = e.target as HTMLElement
26+
const { scrollLeft, scrollWidth, offsetWidth } = target
1927
setLeftButtonVisible(scrollLeft > 100)
2028
const scrollRight = scrollWidth - offsetWidth - Math.abs(scrollLeft)
2129
setRightButtonVisible(scrollRight > 100)
@@ -34,8 +42,7 @@ export const ScrollCardsNavigator = () => {
3442
}, [])
3543

3644
useLayoutEffect(() => {
37-
setLeftButtonVisible(false)
38-
scrollBarContainer.current = document.querySelector('.Cards')
45+
scrollBarContainer.current = document.querySelector(`.${CARDS}`)
3946
}, [])
4047

4148
useEffect(() => {
@@ -70,12 +77,20 @@ export const ScrollCardsNavigator = () => {
7077
return (
7178
<div className="scrollCardsNavigator">
7279
{leftButtonVisible && (
73-
<button onClick={() => scrollTo('left')} className="scrollButton" style={{ left: 0 }}>
80+
<button
81+
aria-label="Previous cards"
82+
className="scrollButton"
83+
onClick={() => scrollTo('left')}
84+
style={{ left: 0 }}>
7485
<FiChevronLeft size={32} />
7586
</button>
7687
)}
7788
{rightButtonVisible && (
78-
<button onClick={() => scrollTo('right')} className="scrollButton" style={{ right: 0 }}>
89+
<button
90+
aria-label="Next cards"
91+
className="scrollButton"
92+
onClick={() => scrollTo('right')}
93+
style={{ right: 0 }}>
7994
<FiChevronRight size={32} />
8095
</button>
8196
)}

0 commit comments

Comments
 (0)