Skip to content

Commit

Permalink
Avoid issues with <li> offest when using different positions (#314)
Browse files Browse the repository at this point in the history
* add position to heghts list

* filter toasts and heights by position
  • Loading branch information
mmalomo authored Jan 24, 2024
1 parent 35bb910 commit f437029
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const Toast = (props: ToastProps) => {
setHeights((heights) => {
const alreadyExists = heights.find((height) => height.toastId === toast.id);
if (!alreadyExists) {
return [{ toastId: toast.id, height: newHeight }, ...heights];
return [{ toastId: toast.id, height: newHeight, position: toast.position }, ...heights];
} else {
return heights.map((height) => (height.toastId === toast.id ? { ...height, height: newHeight } : height));
}
Expand Down Expand Up @@ -184,7 +184,7 @@ const Toast = (props: ToastProps) => {

// Add toast height tot heights array after the toast is mounted
setInitialHeight(height);
setHeights((h) => [{ toastId: toast.id, height }, ...h]);
setHeights((h) => [{ toastId: toast.id, height, position: toast.position }, ...h]);

return () => setHeights((h) => h.filter((height) => height.toastId !== toast.id));
}
Expand Down Expand Up @@ -641,8 +641,8 @@ const Toaster = (props: ToasterProps) => {
cancelButtonStyle={toastOptions?.cancelButtonStyle}
actionButtonStyle={toastOptions?.actionButtonStyle}
removeToast={removeToast}
toasts={toasts}
heights={heights}
toasts={toasts.filter(t => t.position == toast.position)}
heights={heights.filter(h => h.position == toast.position)}
setHeights={setHeights}
expandByDefault={expand}
gap={gap}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type Position = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
export interface HeightT {
height: number;
toastId: number | string;
position: Position;
}

interface ToastOptions {
Expand Down

1 comment on commit f437029

@vercel
Copy link

@vercel vercel bot commented on f437029 Jan 24, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.