Skip to content

Commit

Permalink
chore(merge): merge latest changes from the main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
masoudmanson committed Nov 26, 2024
1 parent bfb134e commit 1c3d574
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ export const NavigationJumpToDemo = (props: Args): JSX.Element => {
{ elementRef: sectionRef3, title: "Section 4" },
{ elementRef: sectionRef4, title: "Section 5" },
]}
onChange={(value, type, event) => {
console.log("On Change");
console.log(value, type, event);
}}
/>
</Box>
<Box
Expand Down
21 changes: 14 additions & 7 deletions packages/components/src/core/NavigationJumpTo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export interface NavigationJumpToProps extends NavigationJumpToExtraProps {
offsetTop?: number;
onChange?: (
value: number,
type?: "click" | "scroll",
event?: React.SyntheticEvent
event?: React.SyntheticEvent,
type?: "click" | "scroll"
) => void;
}

Expand Down Expand Up @@ -63,12 +63,12 @@ const NavigationJumpTo = forwardRef<HTMLDivElement, NavigationJumpToProps>(
// Emit changes only once
const handleOnChange = useCallback(
(
event: React.SyntheticEvent,
value: number,
event: React.SyntheticEvent,
type: "click" | "scroll"
) => {
if (value !== emittedValue) {
onChange?.(value, type, event);
onChange?.(value, event, type);
setEmittedValue(value);
}
},
Expand Down Expand Up @@ -102,7 +102,7 @@ const NavigationJumpTo = forwardRef<HTMLDivElement, NavigationJumpToProps>(
setFirstTabIndexInview(newValue);

// Invoke the custom onChange prop
handleOnChange(event, newValue, "click");
handleOnChange(newValue, event, "click");
};

// Observe changes in the sectionIsInView object to update the tabs value
Expand All @@ -120,9 +120,16 @@ const NavigationJumpTo = forwardRef<HTMLDivElement, NavigationJumpToProps>(
setFirstTabIndexInview(sectionInView);

// Invoke the custom onChange prop
handleOnChange({} as React.SyntheticEvent, sectionInView, "scroll");
handleOnChange(
sectionInView,
{
target: items[sectionInView],
type: "scroll",
} as unknown as React.SyntheticEvent,
"scroll"
);
}
}, [handleOnChange, navItemClicked, sectionIsInView]);
}, [handleOnChange, items, navItemClicked, sectionIsInView]);

// Set navItemClicked to false to re-enable the option
// to update the tab value based on scroll.
Expand Down

0 comments on commit 1c3d574

Please sign in to comment.