@bbl-digital/snorre 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,6 +57,11 @@ const useAutocomplete = props => {
57
57
  }
58
58
  };
59
59
 
60
+ const onFuzzyFocus = () => {
61
+ setValueChanged('');
62
+ if (props.values?.length) setShowValues(true);
63
+ };
64
+
60
65
  const renderedValues = useMemo(() => {
61
66
  if (!props.values?.length) return [];
62
67
 
@@ -226,6 +231,7 @@ const useAutocomplete = props => {
226
231
  handleCustomOnKeyDown,
227
232
  handleOnInputClick,
228
233
  onFuzzyBlur,
234
+ onFuzzyFocus,
229
235
  value,
230
236
  highlightedIndex,
231
237
  showValues,
@@ -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,
@@ -33,7 +37,8 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
33
37
  handleOnKeyDown,
34
38
  handleValueClick,
35
39
  onInputChange,
36
- onFuzzyBlur
40
+ onFuzzyBlur,
41
+ onFuzzyFocus
37
42
  } = useAutocomplete(props);
38
43
  useEffect(() => {
39
44
  const handleClickOutside = e => {
@@ -54,6 +59,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
54
59
  }, [showValues, valuesRef]);
55
60
  return _jsxs(_Fragment, {
56
61
  children: [_jsxs("label", {
62
+ ref: inputWrapperRef,
57
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],
58
64
  onClick: props.onLabelClick ? e => e.preventDefault() : undefined,
59
65
  children: [_jsxs("span", {
@@ -77,7 +83,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
77
83
  disabled: props.disabled,
78
84
  autoFocus: props.focus,
79
85
  onBlur: props.fuzzy ? onFuzzyBlur : props.onBlur,
80
- onFocus: props.onFocus,
86
+ onFocus: props.fuzzy ? onFuzzyFocus : props.onFocus,
81
87
  onChange: onInputChange,
82
88
  onKeyDown: props.onKeyDown ? handleCustomOnKeyDown : handleOnKeyDown,
83
89
  onClick: handleOnInputClick,
@@ -113,7 +119,7 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(({
113
119
  })]
114
120
  }), (Boolean(props.values?.length) || props.renderCustomValueInput) && !props.loading && showValues && _jsxs("div", {
115
121
  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)],
122
+ 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
123
  children: [Boolean(renderedValues?.length) && _jsx("ul", {
118
124
  css: theme => [styles.list(theme)],
119
125
  children: renderedValues.map((item, index) => {