@aarhus-university/au-lib-react-components 12.4.2 → 12.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": true,
3
3
  "name": "@aarhus-university/au-lib-react-components",
4
- "version": "12.4.2",
4
+ "version": "12.4.4",
5
5
  "description": "Library for shared React components for various applications on au.dk",
6
6
  "scripts": {
7
7
  "test": "jest",
@@ -64,7 +64,7 @@
64
64
  "wicg-inert": "^3.1.2"
65
65
  },
66
66
  "dependencies": {
67
- "@aarhus-university/au-designsystem-delphinus": "^1.7.8",
67
+ "@aarhus-university/au-designsystem-delphinus": "^1.9.12",
68
68
  "@aarhus-university/types": "^1.1.0",
69
69
  "@reduxjs/toolkit": "^1.9.5",
70
70
  "@storybook/react-webpack5": "^8.2.1",
@@ -15,6 +15,11 @@ type Props = {
15
15
  buttonChild: JSX.Element;
16
16
  };
17
17
 
18
+ let lastWidth = window.innerWidth;
19
+ let resizeTimeout;
20
+ let onResize;
21
+ let onFocus;
22
+
18
23
  const AUTruncatorComponent: FC<Props> = ({
19
24
  maxLines,
20
25
  header = undefined,
@@ -27,23 +32,31 @@ const AUTruncatorComponent: FC<Props> = ({
27
32
  const contentRef = useRef<HTMLDivElement>(null);
28
33
  const [expanded, setExpanded] = useState<boolean>(false);
29
34
  useEffect(() => {
35
+ window.removeEventListener('resize', onResize);
30
36
  if (expanded) {
31
37
  (expandRef.current as HTMLElement).removeAttribute('hidden');
32
38
  expandRef.current?.parentElement?.classList.add('truncator--no-truncation');
33
39
  }
34
40
  truncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement);
35
41
 
36
- const onResize = () => {
37
- expandRef.current?.setAttribute('hidden', 'hidden');
38
- expandRef.current?.parentElement?.classList.remove('truncator--no-truncation');
39
- truncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement);
42
+ onResize = () => {
43
+ clearTimeout(resizeTimeout);
44
+
45
+ resizeTimeout = setTimeout(() => {
46
+ if (window.innerWidth !== lastWidth) {
47
+ expandRef.current?.setAttribute('hidden', 'hidden');
48
+ expandRef.current?.parentElement?.classList.remove('truncator--no-truncation');
49
+ lastWidth = window.innerWidth;
50
+ setExpanded(false);
51
+ }
52
+ }, 200);
40
53
  };
41
54
 
42
55
  window.addEventListener('resize', onResize);
43
56
 
44
57
  const focusElements = contentRef.current?.querySelectorAll(focusableSelector);
45
58
 
46
- const onFocus = (event: Event) => {
59
+ onFocus = (event: Event) => {
47
60
  if (overflowsY(event.target as HTMLElement)) {
48
61
  setExpanded(true);
49
62
  }
@@ -51,6 +64,7 @@ const AUTruncatorComponent: FC<Props> = ({
51
64
 
52
65
  if (focusElements) {
53
66
  focusElements.forEach((f) => {
67
+ f.removeEventListener('focus', onFocus);
54
68
  f.addEventListener('focus', onFocus);
55
69
  });
56
70
  }