@xqmsg/ui-core 0.16.2 → 0.16.4

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.16.2",
2
+ "version": "0.16.4",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -47,6 +47,7 @@ const StackedMultiSelect = React.forwardRef<
47
47
  const scrollRef = useRef<HTMLDivElement>(null);
48
48
  const inputRef = useRef<HTMLInputElement>(null);
49
49
 
50
+ const [isInit, setIsInit] = useState(false);
50
51
  const [localValues, setLocalValues] = useState<FieldOptions>([]);
51
52
  const [localOptions, setLocalOptions] = useState<FieldOptions>(options);
52
53
  const [isFocussed, setIsFocussed] = useState(false);
@@ -75,6 +76,7 @@ const StackedMultiSelect = React.forwardRef<
75
76
  useEffect(() => {
76
77
  if (watchedValue !== undefined && !watchedValue.length) {
77
78
  setLocalValues([]);
79
+ setIsInit(true);
78
80
  }
79
81
 
80
82
  if (watchedValue !== undefined && watchedValue?.length) {
@@ -86,6 +88,8 @@ const StackedMultiSelect = React.forwardRef<
86
88
  setShouldSideScroll(false);
87
89
  }
88
90
 
91
+ if (isInit) return;
92
+
89
93
  setLocalValues(
90
94
  watchedValue
91
95
  .split(',')
@@ -94,8 +98,30 @@ const StackedMultiSelect = React.forwardRef<
94
98
  options.find(option => option.value === value)
95
99
  )
96
100
  );
101
+ // Filter out options that are already selected
102
+ setLocalOptions(prevLocalOptions =>
103
+ prevLocalOptions.filter(
104
+ localOption =>
105
+ !watchedValue
106
+ .split(',')
107
+ .filter(Boolean)
108
+ .map((value: string) =>
109
+ options.find(option => option.value === value)
110
+ )
111
+ .includes(localOption)
112
+ )
113
+ );
114
+
115
+ setIsInit(true);
97
116
  }
98
- }, [options, shouldSideScroll, watchedValue]);
117
+ }, [
118
+ isInit,
119
+ localOptions,
120
+ localValues,
121
+ options,
122
+ shouldSideScroll,
123
+ watchedValue,
124
+ ]);
99
125
 
100
126
  const handleChange = (option: FieldOption) => {
101
127
  setShouldSideScroll(true);