@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/cjs/index.js CHANGED
@@ -2075,7 +2075,6 @@ function useListControl({ suggestions, formControl }) {
2075
2075
  });
2076
2076
  const collection = require$$0.useRef(new components.ListCollection([]));
2077
2077
  const position = require$$0.useRef(0);
2078
- const changeInternal = require$$0.useRef(false);
2079
2078
  const protectedValue = require$$0.useRef();
2080
2079
  require$$0.useEffect(() => {
2081
2080
  function onCloseSuggestions({ target }) {
@@ -2088,17 +2087,12 @@ function useListControl({ suggestions, formControl }) {
2088
2087
  };
2089
2088
  }, []);
2090
2089
  require$$0.useEffect(() => {
2091
- formControl?.touch();
2092
2090
  setState((state) => ({
2093
2091
  ...state,
2094
2092
  higher: components.locationListCanTop(contentRef.current, listRef.current)
2095
2093
  }));
2096
2094
  }, [state.visible]);
2097
2095
  require$$0.useEffect(() => {
2098
- if (changeInternal.current) {
2099
- changeInternal.current = false;
2100
- return;
2101
- }
2102
2096
  collection.current = new components.ListCollection(suggestions);
2103
2097
  refresh(collection.current, formControl?.value);
2104
2098
  }, [suggestions, formControl?.value]);
@@ -2108,12 +2102,13 @@ function useListControl({ suggestions, formControl }) {
2108
2102
  }
2109
2103
  const element = collection.find(state);
2110
2104
  if (element) {
2105
+ protectedValue.current = undefined;
2111
2106
  return setValue(element.description);
2112
2107
  }
2113
2108
  if (!refreshProtected(collection)) {
2114
2109
  protectedValue.current = state;
2115
2110
  setValue('');
2116
- setFormState(undefined);
2111
+ setFormValue(undefined);
2117
2112
  }
2118
2113
  }
2119
2114
  function refreshProtected(collection) {
@@ -2133,14 +2128,12 @@ function useListControl({ suggestions, formControl }) {
2133
2128
  function setValue(value) {
2134
2129
  setState((state) => ({ ...state, value }));
2135
2130
  }
2136
- function setFormState(value) {
2137
- if (formControl) {
2138
- changeInternal.current = true;
2139
- formControl.setValue(value);
2140
- }
2131
+ function setFormValue(value) {
2132
+ formControl?.setValue(value);
2141
2133
  }
2142
2134
  function setVisible(visible) {
2143
2135
  setState((state) => ({ ...state, visible }));
2136
+ !visible && formControl?.touch();
2144
2137
  }
2145
2138
  function navigationInput(event) {
2146
2139
  if (state.visible) {
@@ -2169,7 +2162,7 @@ function useListControl({ suggestions, formControl }) {
2169
2162
  navigationElement,
2170
2163
  navigationInput,
2171
2164
  setFocused,
2172
- setFormState,
2165
+ setFormValue,
2173
2166
  setValue,
2174
2167
  setVisible
2175
2168
  };
@@ -2186,7 +2179,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2186
2179
  previous: null
2187
2180
  });
2188
2181
  const listControl = useListControl({ suggestions, formControl });
2189
- const { inputRef, navigationElement, navigationInput, setFocused, setFormState, setValue, setVisible } = listControl;
2182
+ const { inputRef, navigationElement, navigationInput, setFocused, setFormValue, setValue, setVisible } = listControl;
2190
2183
  require$$0.useEffect(() => {
2191
2184
  refreshCoincidences(pattern, true);
2192
2185
  }, [suggestions]);
@@ -2221,7 +2214,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2221
2214
  function onClickAction() {
2222
2215
  setVisible(false);
2223
2216
  setValue('');
2224
- setFormState(undefined);
2217
+ setFormValue(undefined);
2225
2218
  onValue && onValue(undefined);
2226
2219
  }
2227
2220
  function onClickBackdrop() {
@@ -2243,7 +2236,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2243
2236
  onSelect(value);
2244
2237
  }
2245
2238
  else {
2246
- setFormState(value);
2239
+ setFormValue(value);
2247
2240
  setValue(description);
2248
2241
  }
2249
2242
  onValue && onValue(value);
@@ -2274,17 +2267,13 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2274
2267
  };
2275
2268
  }
2276
2269
 
2277
- function RlsFieldAutocompleteTemplate({ render, suggestions, children, disabled, formControl, hiddenIcon, onSearch, onSelect, onValue, placeholder, rlsTheme, searching }) {
2278
- const fieldAutocomplete = useFieldAutocomplete({
2279
- suggestions,
2280
- disabled,
2281
- formControl,
2282
- onSelect,
2283
- onValue
2284
- });
2270
+ function RlsFieldAutocompleteTemplate(props) {
2271
+ const fieldAutocomplete = useFieldAutocomplete(props);
2272
+ const { render, children, disabled, formControl, hiddenIcon, onSearch, placeholder, rlsTheme, searching } = props;
2285
2273
  return (jsxRuntimeExports.jsxs("div", { ref: fieldAutocomplete.listControl.contentRef, className: renderClassStatus('rls-field-box', {
2286
2274
  disabled,
2287
2275
  focused: fieldAutocomplete.listControl.focused,
2276
+ error: formControl?.wrong,
2288
2277
  selected: !!fieldAutocomplete.listControl.value
2289
2278
  }, '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', {
2290
2279
  visible: fieldAutocomplete.listControl.visible,
@@ -2490,7 +2479,7 @@ function RlsFieldDateRange({ children, date: datePicker, disabled, formControl,
2490
2479
 
2491
2480
  function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2492
2481
  const listControl = useListControl({ suggestions, formControl });
2493
- const { inputRef, visible, navigationElement, navigationInput, setFocused, setFormState, setValue, setVisible } = listControl;
2482
+ const { inputRef, visible, navigationElement, navigationInput, setFocused, setFormValue, setValue, setVisible } = listControl;
2494
2483
  function onFocusInput() {
2495
2484
  setFocused(true);
2496
2485
  }
@@ -2539,7 +2528,7 @@ function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2539
2528
  onSelect(value);
2540
2529
  }
2541
2530
  else {
2542
- setFormState(value);
2531
+ setFormValue(value);
2543
2532
  setValue(description);
2544
2533
  }
2545
2534
  onValue && onValue(value);
@@ -2557,15 +2546,14 @@ function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2557
2546
  };
2558
2547
  }
2559
2548
 
2560
- function RlsFieldSelectTemplate({ render, suggestions, children, disabled, formControl, onSelect, onValue, placeholder, rlsTheme }) {
2561
- const fieldSelect = useFieldSelect({
2562
- suggestions,
2563
- disabled,
2564
- formControl,
2565
- onSelect,
2566
- onValue
2567
- });
2568
- 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', {
2549
+ function RlsFieldSelectTemplate(props) {
2550
+ const fieldSelect = useFieldSelect(props);
2551
+ const { render, suggestions, children, disabled, formControl, placeholder, rlsTheme } = props;
2552
+ return (jsxRuntimeExports.jsxs("div", { ref: fieldSelect.listControl.contentRef, className: renderClassStatus('rls-field-box', {
2553
+ focused: fieldSelect.listControl.focused,
2554
+ error: formControl?.wrong,
2555
+ disabled
2556
+ }, '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', {
2569
2557
  visible: fieldSelect.listControl.visible
2570
2558
  }), 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', {
2571
2559
  visible: fieldSelect.listControl.visible,