@rolster/react-components 18.15.12 → 18.15.14

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/dist/es/index.js CHANGED
@@ -2073,7 +2073,6 @@ function useListControl({ suggestions, formControl }) {
2073
2073
  });
2074
2074
  const collection = useRef(new ListCollection([]));
2075
2075
  const position = useRef(0);
2076
- const changeInternal = useRef(false);
2077
2076
  const protectedValue = useRef();
2078
2077
  useEffect(() => {
2079
2078
  function onCloseSuggestions({ target }) {
@@ -2086,17 +2085,12 @@ function useListControl({ suggestions, formControl }) {
2086
2085
  };
2087
2086
  }, []);
2088
2087
  useEffect(() => {
2089
- formControl?.touch();
2090
2088
  setState((state) => ({
2091
2089
  ...state,
2092
2090
  higher: locationListCanTop(contentRef.current, listRef.current)
2093
2091
  }));
2094
2092
  }, [state.visible]);
2095
2093
  useEffect(() => {
2096
- if (changeInternal.current) {
2097
- changeInternal.current = false;
2098
- return;
2099
- }
2100
2094
  collection.current = new ListCollection(suggestions);
2101
2095
  refresh(collection.current, formControl?.value);
2102
2096
  }, [suggestions, formControl?.value]);
@@ -2106,12 +2100,13 @@ function useListControl({ suggestions, formControl }) {
2106
2100
  }
2107
2101
  const element = collection.find(state);
2108
2102
  if (element) {
2103
+ protectedValue.current = undefined;
2109
2104
  return setValue(element.description);
2110
2105
  }
2111
2106
  if (!refreshProtected(collection)) {
2112
2107
  protectedValue.current = state;
2113
2108
  setValue('');
2114
- setFormState(undefined);
2109
+ setFormValue(undefined);
2115
2110
  }
2116
2111
  }
2117
2112
  function refreshProtected(collection) {
@@ -2131,14 +2126,12 @@ function useListControl({ suggestions, formControl }) {
2131
2126
  function setValue(value) {
2132
2127
  setState((state) => ({ ...state, value }));
2133
2128
  }
2134
- function setFormState(value) {
2135
- if (formControl) {
2136
- changeInternal.current = true;
2137
- formControl.setValue(value);
2138
- }
2129
+ function setFormValue(value) {
2130
+ formControl?.setValue(value);
2139
2131
  }
2140
2132
  function setVisible(visible) {
2141
2133
  setState((state) => ({ ...state, visible }));
2134
+ !visible && formControl?.touch();
2142
2135
  }
2143
2136
  function navigationInput(event) {
2144
2137
  if (state.visible) {
@@ -2167,7 +2160,7 @@ function useListControl({ suggestions, formControl }) {
2167
2160
  navigationElement,
2168
2161
  navigationInput,
2169
2162
  setFocused,
2170
- setFormState,
2163
+ setFormValue,
2171
2164
  setValue,
2172
2165
  setVisible
2173
2166
  };
@@ -2184,7 +2177,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2184
2177
  previous: null
2185
2178
  });
2186
2179
  const listControl = useListControl({ suggestions, formControl });
2187
- const { inputRef, navigationElement, navigationInput, setFocused, setFormState, setValue, setVisible } = listControl;
2180
+ const { inputRef, navigationElement, navigationInput, setFocused, setFormValue, setValue, setVisible } = listControl;
2188
2181
  useEffect(() => {
2189
2182
  refreshCoincidences(pattern, true);
2190
2183
  }, [suggestions]);
@@ -2219,7 +2212,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2219
2212
  function onClickAction() {
2220
2213
  setVisible(false);
2221
2214
  setValue('');
2222
- setFormState(undefined);
2215
+ setFormValue(undefined);
2223
2216
  onValue && onValue(undefined);
2224
2217
  }
2225
2218
  function onClickBackdrop() {
@@ -2241,7 +2234,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2241
2234
  onSelect(value);
2242
2235
  }
2243
2236
  else {
2244
- setFormState(value);
2237
+ setFormValue(value);
2245
2238
  setValue(description);
2246
2239
  }
2247
2240
  onValue && onValue(value);
@@ -2272,17 +2265,13 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2272
2265
  };
2273
2266
  }
2274
2267
 
2275
- function RlsFieldAutocompleteTemplate({ render, suggestions, children, disabled, formControl, hiddenIcon, onSearch, onSelect, onValue, placeholder, rlsTheme, searching }) {
2276
- const fieldAutocomplete = useFieldAutocomplete({
2277
- suggestions,
2278
- disabled,
2279
- formControl,
2280
- onSelect,
2281
- onValue
2282
- });
2268
+ function RlsFieldAutocompleteTemplate(props) {
2269
+ const fieldAutocomplete = useFieldAutocomplete(props);
2270
+ const { render, children, disabled, formControl, hiddenIcon, onSearch, placeholder, rlsTheme, searching } = props;
2283
2271
  return (jsxRuntimeExports.jsxs("div", { ref: fieldAutocomplete.listControl.contentRef, className: renderClassStatus('rls-field-box', {
2284
2272
  disabled,
2285
2273
  focused: fieldAutocomplete.listControl.focused,
2274
+ error: formControl?.wrong,
2286
2275
  selected: !!fieldAutocomplete.listControl.value
2287
2276
  }, 'rls-field-list rls-field-autocomplete'), "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("label", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: fieldAutocomplete.listControl.value, onClick: fieldAutocomplete.onClickControl }), !hiddenIcon && fieldAutocomplete.listControl.value && (jsxRuntimeExports.jsx("button", { className: "rls-field-list__action", disabled: disabled, onClick: fieldAutocomplete.onClickAction, children: jsxRuntimeExports.jsx(RlsIcon, { value: "trash-2" }) }))] }) }), jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }), jsxRuntimeExports.jsxs("div", { className: renderClassStatus('rls-field-list__suggestions', {
2288
2277
  visible: fieldAutocomplete.listControl.visible,
@@ -2488,7 +2477,7 @@ function RlsFieldDateRange({ children, date: datePicker, disabled, formControl,
2488
2477
 
2489
2478
  function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2490
2479
  const listControl = useListControl({ suggestions, formControl });
2491
- const { inputRef, visible, navigationElement, navigationInput, setFocused, setFormState, setValue, setVisible } = listControl;
2480
+ const { inputRef, visible, navigationElement, navigationInput, setFocused, setFormValue, setValue, setVisible } = listControl;
2492
2481
  function onFocusInput() {
2493
2482
  setFocused(true);
2494
2483
  }
@@ -2537,7 +2526,7 @@ function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2537
2526
  onSelect(value);
2538
2527
  }
2539
2528
  else {
2540
- setFormState(value);
2529
+ setFormValue(value);
2541
2530
  setValue(description);
2542
2531
  }
2543
2532
  onValue && onValue(value);
@@ -2555,15 +2544,14 @@ function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2555
2544
  };
2556
2545
  }
2557
2546
 
2558
- function RlsFieldSelectTemplate({ render, suggestions, children, disabled, formControl, onSelect, onValue, placeholder, rlsTheme }) {
2559
- const fieldSelect = useFieldSelect({
2560
- suggestions,
2561
- disabled,
2562
- formControl,
2563
- onSelect,
2564
- onValue
2565
- });
2566
- return (jsxRuntimeExports.jsxs("div", { ref: fieldSelect.listControl.contentRef, className: renderClassStatus('rls-field-box', { focused: fieldSelect.listControl.focused, disabled }, 'rls-field-list rls-field-select'), "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("label", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { ref: fieldSelect.listControl.inputRef, className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: fieldSelect.listControl.value, onFocus: fieldSelect.onFocusInput, onBlur: fieldSelect.onBlurInput, onClick: fieldSelect.onClickInput, onKeyDown: fieldSelect.onKeydownInput }), jsxRuntimeExports.jsx("button", { className: renderClassStatus('rls-field-list__action', {
2547
+ function RlsFieldSelectTemplate(props) {
2548
+ const fieldSelect = useFieldSelect(props);
2549
+ const { render, suggestions, children, disabled, formControl, placeholder, rlsTheme } = props;
2550
+ return (jsxRuntimeExports.jsxs("div", { ref: fieldSelect.listControl.contentRef, className: renderClassStatus('rls-field-box', {
2551
+ focused: fieldSelect.listControl.focused,
2552
+ error: formControl?.wrong,
2553
+ disabled
2554
+ }, 'rls-field-list rls-field-select'), "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("label", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { ref: fieldSelect.listControl.inputRef, className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: fieldSelect.listControl.value, onFocus: fieldSelect.onFocusInput, onBlur: fieldSelect.onBlurInput, onClick: fieldSelect.onClickInput, onKeyDown: fieldSelect.onKeydownInput }), jsxRuntimeExports.jsx("button", { className: renderClassStatus('rls-field-list__action', {
2567
2555
  visible: fieldSelect.listControl.visible
2568
2556
  }), disabled: disabled, onClick: fieldSelect.onClickAction, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-down" }) })] }) }), jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }), jsxRuntimeExports.jsxs("div", { className: renderClassStatus('rls-field-list__suggestions', {
2569
2557
  visible: fieldSelect.listControl.visible,