Skip to content

Commit

Permalink
fix(ui): fix popover positioning on open (#499)
Browse files Browse the repository at this point in the history
* fix(ui): fix popover positioning on open

* fix(ui): avoid inconsistent min and max date log firing in the wrong scenarios

---------

Co-authored-by: luzzifoss <fedeluzzi00@gmail.com>
  • Loading branch information
luzzif and luzzifoss authored Nov 3, 2023
1 parent ba55748 commit 2026c97
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/rude-penguins-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@carrot-kpi/ui": patch
---

Do not fire inconsistent min and max date log if both min and max dates are not
specified.
5 changes: 5 additions & 0 deletions .changeset/shaggy-spoons-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@carrot-kpi/ui": patch
---

Force popover position update on open.
6 changes: 5 additions & 1 deletion packages/ui/src/components/date-time-input/picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export const DateTimePicker = ({
setMin(updatedMin);
setMax(updatedMax);

if (dayjs(updatedMin).isAfter(dayjs(updatedMax))) {
if (
updatedMin &&
updatedMax &&
dayjs(updatedMin).isAfter(dayjs(updatedMax))
) {
setMin(updatedMax);
console.warn("inconsistent min and max values", {
min: updatedMin?.toISOString(),
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/components/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
type ReactElement,
type ReactNode,
useState,
useEffect,
} from "react";
import { usePopper } from "react-popper";
import { type Placement } from "@popperjs/core";
Expand Down Expand Up @@ -54,7 +55,7 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
): ReactElement {
const [popper, setPopper] = useState<HTMLDivElement | null>(null);

const { styles, attributes } = usePopper(anchor, popper, {
const { styles, attributes, update } = usePopper(anchor, popper, {
placement,
modifiers: [
{
Expand All @@ -64,6 +65,10 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
],
});

useEffect(() => {
if (open && update) update();
}, [open, update]);

return (
<div
ref={(element) => {
Expand Down

0 comments on commit 2026c97

Please sign in to comment.