@bbl-digital/snorre 3.0.6 → 3.0.9

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.
@@ -38,8 +38,6 @@ const useAutocomplete = props => {
38
38
  const onFuzzyBlur = e => {
39
39
  // If the value of the input is changed, and does not match the value of the values array,
40
40
  // we should revert back the input value to the original value
41
- //What
42
- // if (!e.target.value.length) clearSelectedItem()
43
41
  if (e.target.value === props.value) return; // If target value is the same as a value from the values array, we should set the value for the user
44
42
 
45
43
  if (inputValues?.length) {
@@ -0,0 +1,19 @@
1
+ import { createRef, useEffect, useState } from 'react';
2
+
3
+ const useHandleDimentions = () => {
4
+ const [height, setHeight] = useState(0);
5
+ const [width, setWidth] = useState(0);
6
+ const dimentionsRef = /*#__PURE__*/createRef();
7
+ useEffect(() => {
8
+ const rect = dimentionsRef.current?.getBoundingClientRect();
9
+ setHeight(rect?.height || 0);
10
+ setWidth(rect?.width || 0); // eslint-disable-next-line react-hooks/exhaustive-deps
11
+ }, [dimentionsRef.current]);
12
+ return {
13
+ height,
14
+ width,
15
+ dimentionsRef
16
+ };
17
+ };
18
+
19
+ export default useHandleDimentions;
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,7 @@ import { styles, ErrorMessage, Clear } from './styles';
4
4
  import { useEffect } from 'react';
5
5
  import IconErrorOutline from '../../icons/General/IconErrorOutline';
6
6
  import Spinner from '../Spinner';
7
- import useHandleOptionsHeight from './utils/useHandleOptionsHeight';
7
+ import useHandleDimentions from './hooks/useHandleDimentions';
8
8
  import Link from '../Link';
9
9
  import IconClose from '../../icons/General/IconClose';
10
10
  import useAutocomplete from './hooks/useAutocomplete';
@@ -18,9 +18,13 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
18
18
  }, ref) => {
19
19
  const valuesRef = /*#__PURE__*/createRef();
20
20
  const {
21
- optionsHeight,
22
- optionsRef
23
- } = useHandleOptionsHeight();
21
+ height: optionsHeight,
22
+ dimentionsRef: optionsRef
23
+ } = useHandleDimentions();
24
+ const {
25
+ width: inputWrapperWidth,
26
+ dimentionsRef: inputWrapperRef
27
+ } = useHandleDimentions();
24
28
  const {
25
29
  value,
26
30
  highlightedIndex,
@@ -54,8 +58,9 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
54
58
  }, [showValues, valuesRef]);
55
59
  return _jsxs(_Fragment, {
56
60
  children: [_jsxs("label", {
57
- css: theme => [styles.default(theme), (props.invalid || props.invalidMessage) && styles.invalid(theme), props.validation && styles.validation, props.onLabelClick && styles.clickableLabel, height && styles.height(height), css && css],
61
+ ref: inputWrapperRef,
58
62
  onClick: props.onLabelClick ? e => e.preventDefault() : undefined,
63
+ css: theme => [styles.default(theme), (props.invalid || props.invalidMessage) && styles.invalid(theme), props.validation && styles.validation, props.onLabelClick && styles.clickableLabel, height && styles.height(height), css && css],
59
64
  children: [_jsxs("span", {
60
65
  css: styles.label,
61
66
  children: [props.label && (props.onLabelClick ? _jsx(Link, {
@@ -113,7 +118,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
113
118
  })]
114
119
  }), (Boolean(props.values?.length) || props.renderCustomValueInput) && !props.loading && showValues && _jsxs("div", {
115
120
  ref: valuesRef,
116
- css: () => [!props.renderCustomValueInput && styles.listWrapper, props.dynamicallyPlaceInput && Boolean(optionsHeight) && styles.listWrapperTopPosition(optionsHeight), props.dynamicallyPlaceInput && Boolean(optionsHeight) && props.invalidMessage && styles.listWrapperTopPosition(optionsHeight + 30), props.inputValuesMaxWidth && styles.listWrapperMaxWidth(props.inputValuesMaxWidth)],
121
+ css: () => [!props.renderCustomValueInput && styles.listWrapper(inputWrapperWidth), props.dynamicallyPlaceInput && Boolean(optionsHeight) && styles.listWrapperTopPosition(optionsHeight), props.dynamicallyPlaceInput && Boolean(optionsHeight) && props.invalidMessage && styles.listWrapperTopPosition(optionsHeight + 30), props.inputValuesMaxWidth && styles.listWrapperMaxWidth(props.inputValuesMaxWidth)],
117
122
  children: [Boolean(renderedValues?.length) && _jsx("ul", {
118
123
  css: theme => [styles.list(theme)],
119
124
  children: renderedValues.map((item, index) => {