Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HorizontalScroll): adjust arrows visibility when component is ove… #4533

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/src/__examples__/HorizontalScroll/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@ export default {
{
name: "spacing",
type: "select",
options: ["none", "50", "100", "200", "300", "400", "600", "800", "1000"],
options: [
DSil marked this conversation as resolved.
Show resolved Hide resolved
"none",
"50",
"100",
"150",
"200",
"300",
"400",
"600",
"800",
"1000",
"1200",
"1600",
],
defaultValue: "none",
},
],
Expand Down
9 changes: 4 additions & 5 deletions packages/orbit-components/src/HorizontalScroll/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import ChevronBackward from "../icons/ChevronBackward";
import ChevronForward from "../icons/ChevronForward";
import type { Props, ScrollSnap } from "./types";

const TRIGGER_OFFSET = 20;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still curious why we added this in the first place and can't see any new glitch by removing it… So I guess it will have to work for now


const getSnap = (scrollSnap: ScrollSnap) => {
if (scrollSnap === "mandatory") return "x mandatory";
if (scrollSnap === "proximity") return "x proximity";
Expand Down Expand Up @@ -106,13 +104,14 @@ const HorizontalScroll = React.forwardRef<HTMLDivElement, Props>(
if (scrollEl) {
const scrollWidth = scrollEl.scrollWidth - scrollEl.clientWidth;
const { scrollLeft } = scrollEl;
if (scrollLeft - TRIGGER_OFFSET <= 0) {

if (scrollLeft === 0) {
setReachedStart(true);
} else {
setReachedStart(false);
}

if (scrollLeft + TRIGGER_OFFSET >= scrollWidth) {
if (scrollLeft >= scrollWidth) {
setReachedEnd(true);
} else {
setReachedEnd(false);
Expand All @@ -132,7 +131,7 @@ const HorizontalScroll = React.forwardRef<HTMLDivElement, Props>(
return () => {
window.removeEventListener("resize", handleResize);
};
}, [handleOverflow, handleResize]);
}, [handleOverflow, handleResize, scrollWrapperRef.current?.scrollWidth]);

return (
<div
Expand Down
Loading