@ultraviolet/ui 1.27.1 → 1.27.3

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.
@@ -403,12 +403,6 @@ const Checkbox = /*#__PURE__*/forwardRef((_ref64, ref) => {
403
403
  if (!progress) onChange?.(event);
404
404
  setState(current => current === 'indeterminate' ? false : event.target.checked);
405
405
  }, [onChange, progress, setState]);
406
- const onKeyDown = useCallback(event => {
407
- if (event.key.charCodeAt(0) === 32) {
408
- event.preventDefault();
409
- setState(current => !current);
410
- }
411
- }, []);
412
406
  return jsx(Tooltip, {
413
407
  text: tooltip,
414
408
  children: jsxs(CheckboxContainer, {
@@ -433,7 +427,6 @@ const Checkbox = /*#__PURE__*/forwardRef((_ref64, ref) => {
433
427
  checked: state === 'indeterminate' ? false : state,
434
428
  size: size,
435
429
  onChange: onLocalChange,
436
- onKeyDown: onKeyDown,
437
430
  onFocus: onFocus,
438
431
  onBlur: onBlur,
439
432
  disabled: disabled,
@@ -1,6 +1,7 @@
1
1
  import _styled from '@emotion/styled/base';
2
- import { useState, useRef, useEffect } from 'react';
2
+ import { useRef } from 'react';
3
3
  import recursivelyGetChildrenString from '../../helpers/recursivelyGetChildrenString.js';
4
+ import { useIsOverflowing } from '../../hooks/useIsOverflowing.js';
4
5
  import capitalize from '../../utils/capitalize.js';
5
6
  import { Tooltip } from '../Tooltip/index.js';
6
7
  import { jsx } from '@emotion/react/jsx-runtime';
@@ -79,20 +80,11 @@ const Text = _ref2 => {
79
80
  'data-testid': dataTestId
80
81
  } = _ref2;
81
82
  const computedSentiment = sentiment ?? color;
82
- const [isTruncated, setIsTruncated] = useState(false);
83
83
  const elementRef = useRef(null);
84
+ const isOverflowing = useIsOverflowing(elementRef);
84
85
  const finalStringChildren = recursivelyGetChildrenString(children);
85
- useEffect(() => {
86
- if (oneLine && elementRef?.current) {
87
- const {
88
- offsetWidth,
89
- scrollWidth
90
- } = elementRef.current;
91
- setIsTruncated(offsetWidth < scrollWidth);
92
- }
93
- }, [oneLine]);
94
86
  return jsx(Tooltip, {
95
- text: oneLine && isTruncated ? finalStringChildren : '',
87
+ text: oneLine && isOverflowing ? finalStringChildren : '',
96
88
  children: jsx(StyledText, {
97
89
  ref: elementRef,
98
90
  as: as,
@@ -0,0 +1,34 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ /**
4
+ * This hook checks if the element has overflow based on the offsetWidth and scrollWidth of the element.
5
+ */
6
+ const useIsOverflowing = (ref, callback) => {
7
+ const [isOverflowing, setIsOverflowing] = useState(false);
8
+ useEffect(() => {
9
+ const handleResize = () => {
10
+ if (!ref.current) {
11
+ return;
12
+ }
13
+ const element = ref.current;
14
+ const hasOverflow = element.clientWidth < element.scrollWidth;
15
+ setIsOverflowing(hasOverflow);
16
+ if (callback) callback(hasOverflow);
17
+ };
18
+
19
+ // This will add the function into the browser event queue after the DOM is painted
20
+ // which is needed to get the correct offsetWidth and scrollWidth
21
+ setTimeout(() => handleResize(), 0);
22
+
23
+ // Listen for resize events
24
+ window.addEventListener('resize', handleResize);
25
+
26
+ // Cleanup the event listener
27
+ return () => {
28
+ window.removeEventListener('resize', handleResize);
29
+ };
30
+ }, [ref, callback]);
31
+ return isOverflowing;
32
+ };
33
+
34
+ export { useIsOverflowing };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.27.1",
3
+ "version": "1.27.3",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -67,7 +67,7 @@
67
67
  "react-use-clipboard": "1.0.9",
68
68
  "reakit": "1.3.11",
69
69
  "@ultraviolet/themes": "1.5.0",
70
- "@ultraviolet/icons": "2.5.5"
70
+ "@ultraviolet/icons": "2.6.0"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "rollup -c ../../rollup.config.mjs"