Skip to content

Commit

Permalink
🐛 Timeline Period brakk ved bruk av JSODOM
Browse files Browse the repository at this point in the history
  • Loading branch information
KenAJoh committed Jun 17, 2023
1 parent 329119f commit 42b5af6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .changeset/cold-ears-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-css": patch
"@navikt/ds-react": patch
---

Fikset jsdom-problemer ved rendring av Timeline
4 changes: 4 additions & 0 deletions @navikt/core/css/timeline.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
list-style-type: none;
}

.navds-timeline__row-periods:focus {
outline: none;
}

.navds-timeline__period {
height: 100%;
border-radius: var(--a-border-radius-full);
Expand Down
31 changes: 6 additions & 25 deletions @navikt/core/react/src/timeline/Pin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ import {
useHover,
useInteractions,
} from "@floating-ui/react";
import { useEventListener, mergeRefs } from "../util";
import { format } from "date-fns";
import React, {
forwardRef,
useCallback,
useMemo,
useRef,
useState,
} from "react";
import React, { forwardRef, useMemo, useRef, useState } from "react";
import { mergeRefs } from "../util";
import { useTimelineContext } from "./hooks/useTimelineContext";
import { position } from "./utils/calc";
import { TimelineComponentTypes } from "./utils/types.internal";
Expand Down Expand Up @@ -83,23 +77,6 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
[ref, refs.setReference]
);

useEventListener(
"focusin",
useCallback(
(e: FocusEvent) => {
if (
![
refs.reference.current as HTMLButtonElement | null,
refs?.floating?.current,
].some((element) => element?.contains(e.target as Node))
) {
open && setOpen(false);
}
},
[open, refs.reference, refs?.floating]
)
);

const staticSide = {
top: "bottom",
right: "left",
Expand Down Expand Up @@ -140,6 +117,10 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
ref={refs.setFloating}
{...getFloatingProps({
tabIndex: -1,
onBlur: (e) =>
e.target.previousSibling !== document.activeElement &&
open &&
setOpen(false),
})}
style={{
...floatingStyles,
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/timeline/TimelineRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const TimelineRow = forwardRef<HTMLOListElement, TimelineRowProps>(
>
<ol
{...rest}
tabIndex={-1}
ref={ref}
aria-label={
periods.length === 0
Expand Down
25 changes: 6 additions & 19 deletions @navikt/core/react/src/timeline/period/ClickablePeriod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
useHover,
useInteractions,
} from "@floating-ui/react";
import { useEventListener, mergeRefs } from "../../util";
import cl from "clsx";
import React, { useCallback, useMemo, useRef, useState } from "react";
import React, { useMemo, useRef, useState } from "react";
import { mergeRefs } from "../../util";
import { usePeriodContext } from "../hooks/usePeriodContext";
import { useRowContext } from "../hooks/useRowContext";
import { useTimelineContext } from "../hooks/useTimelineContext";
Expand Down Expand Up @@ -85,23 +85,6 @@ const ClickablePeriod = React.memo(
[periodRef, refs.setReference]
);

useEventListener(
"focusin",
useCallback(
(e: FocusEvent) => {
if (
![
refs.reference.current as HTMLButtonElement | null,
refs?.floating?.current,
].some((element) => element?.contains(e.target as Node))
) {
open && setOpen(false);
}
},
[open, refs.reference, refs?.floating]
)
);

const staticSide = {
top: "bottom",
right: "left",
Expand Down Expand Up @@ -166,6 +149,10 @@ const ClickablePeriod = React.memo(
ref={refs.setFloating}
{...getFloatingProps({
tabIndex: -1,
onBlur: (e) =>
e.target.previousSibling !== document.activeElement &&
open &&
setOpen(false),
})}
style={{
...floatingStyles,
Expand Down

0 comments on commit 42b5af6

Please sign in to comment.