@loomhq/lens 10.43.5 → 10.43.8
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/README.md +1 -1
- package/dist/components/select/select.js +19 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ navigate to: http://localhost:3000
|
|
|
62
62
|
|
|
63
63
|
### Use conventional commits
|
|
64
64
|
|
|
65
|
-
Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) to kick off publishing a new version of Lens when PR is merged. To upgrade Lens to the latest published version in the [main Loom repo](http://github.com/loomhq/loom), `cd
|
|
65
|
+
Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) to kick off publishing a new version of Lens when PR is merged. To upgrade Lens to the latest published version in the [main Loom repo](http://github.com/loomhq/loom), `cd projects/webapp-client` and `pnpm up @loomhq/lens`.
|
|
66
66
|
|
|
67
67
|
### Add an icon to the icon set
|
|
68
68
|
|
|
@@ -137,15 +137,26 @@ const CustomHeader = ({ selectedOptionValue, selectedItem, trigger, getToggleBut
|
|
|
137
137
|
};
|
|
138
138
|
return trigger(triggerContent, buttonProps());
|
|
139
139
|
};
|
|
140
|
+
const getSelectedOption = (value, options) => options.find(o => o.value === value);
|
|
141
|
+
const didSelectedOptionValueChange = (selectedOptionValue, prevSelectedItem) => {
|
|
142
|
+
return Boolean(prevSelectedItem && selectedOptionValue !== prevSelectedItem.value);
|
|
143
|
+
};
|
|
140
144
|
const Select = (_a) => {
|
|
141
145
|
var { container, onChange, menuZIndex = 1100, menuMaxWidth, menuMaxHeight = 34, selectedOptionValue, onOuterClick, options, placeholder, isDisabled, onOpenChange, trigger } = _a, props = __rest(_a, ["container", "onChange", "menuZIndex", "menuMaxWidth", "menuMaxHeight", "selectedOptionValue", "onOuterClick", "options", "placeholder", "isDisabled", "onOpenChange", "trigger"]);
|
|
142
146
|
const environment = getDownshiftEnvironment(container);
|
|
143
147
|
const [downshiftIsOpen, setDownshiftIsOpen] = useState(false);
|
|
148
|
+
const [prevSelectedItem, setPrevSelectedItem] = useState(getSelectedOption(selectedOptionValue, options));
|
|
149
|
+
const [selectedItem, setSelectedItem] = useState(prevSelectedItem);
|
|
150
|
+
const onDownshiftChange = item => {
|
|
151
|
+
setSelectedItem(item);
|
|
152
|
+
onChange && onChange(item ? item : '');
|
|
153
|
+
};
|
|
144
154
|
const downshiftProps = {
|
|
145
155
|
itemToString: item => (item ? item.value : ''),
|
|
146
|
-
onChange:
|
|
156
|
+
onChange: onDownshiftChange,
|
|
147
157
|
onOuterClick,
|
|
148
158
|
environment,
|
|
159
|
+
selectedItem,
|
|
149
160
|
};
|
|
150
161
|
if (environment) {
|
|
151
162
|
downshiftProps.environment = environment;
|
|
@@ -158,6 +169,13 @@ const Select = (_a) => {
|
|
|
158
169
|
auto: true,
|
|
159
170
|
snap: true,
|
|
160
171
|
});
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (didSelectedOptionValueChange(selectedOptionValue, prevSelectedItem)) {
|
|
174
|
+
const selectedItem = getSelectedOption(selectedOptionValue, options);
|
|
175
|
+
setPrevSelectedItem(selectedItem);
|
|
176
|
+
setSelectedItem(selectedItem);
|
|
177
|
+
}
|
|
178
|
+
}, [selectedOptionValue, options, prevSelectedItem]);
|
|
161
179
|
useEffect(() => {
|
|
162
180
|
onOpenChange && onOpenChange(downshiftIsOpen);
|
|
163
181
|
}, [downshiftIsOpen, onOpenChange]);
|