Skip to content

Commit

Permalink
fix: legend scroll (#1093)
Browse files Browse the repository at this point in the history
* fix legend scroll

---------

Co-authored-by: Maxime BAUCHET <[email protected]>
  • Loading branch information
mbauchet and Maxime BAUCHET committed Jun 22, 2024
1 parent 5b69166 commit 0328ca0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/text-elements/Legend/Legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
...other
} = props;
const scrollableRef = React.useRef<HTMLInputElement>(null);
const scrollButtonsRef = React.useRef<HTMLDivElement>(null);

const [hasScroll, setHasScroll] = React.useState<HasScrollProps | null>(null);
const [isKeyDowned, setIsKeyDowned] = React.useState<string | null>(null);
const intervalRef = React.useRef<NodeJS.Timeout | null>(null);
Expand All @@ -170,11 +172,16 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
const scrollToTest = useCallback(
(direction: "left" | "right") => {
const element = scrollableRef?.current;
const scrollButtons = scrollButtonsRef?.current;
const width = element?.clientWidth ?? 0;
const scrollButtonsWith = scrollButtons?.clientWidth ?? 0;

if (element && enableLegendSlider) {
element.scrollTo({
left: direction === "left" ? element.scrollLeft - width : element.scrollLeft + width,
left:
direction === "left"
? element.scrollLeft - width + scrollButtonsWith
: element.scrollLeft + width - scrollButtonsWith,
behavior: "smooth",
});
setTimeout(() => {
Expand Down Expand Up @@ -273,6 +280,7 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
// common
"absolute flex top-0 pr-1 bottom-0 right-0 items-center justify-center h-full",
)}
ref={scrollButtonsRef}
>
<ScrollButton
icon={ChevronLeftFill}
Expand Down

0 comments on commit 0328ca0

Please sign in to comment.