@homebound/beam 2.333.0 → 2.333.1

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.
@@ -115,13 +115,26 @@ function TreeSelectFieldBase(props) {
115
115
  return areAllSelected;
116
116
  }
117
117
  initialOptions.forEach(areAllChildrenSelected);
118
+ // Given a child option, determine if the parent is selected.
119
+ const isParentSelected = (option) => {
120
+ var _a;
121
+ const parents = (_a = (0, utils_1.findOption)(initialOptions, (0, Value_1.valueToKey)(getOptionValue(option)), getOptionValue)) === null || _a === void 0 ? void 0 : _a.parents;
122
+ if (!parents)
123
+ return false;
124
+ return parents.some((parent) => selectedKeys.includes((0, Value_1.valueToKey)(getOptionValue(parent))));
125
+ };
118
126
  return {
119
127
  selectedKeys,
120
128
  inputValue: selectedOptions.length === 1
121
129
  ? getOptionLabel(selectedOptions[0])
122
- : selectedOptions.length === 0
123
- ? nothingSelectedText
124
- : "",
130
+ : isReadOnly && selectedOptions.length > 0
131
+ ? selectedOptions
132
+ .filter((o) => !isParentSelected(o))
133
+ .map(getOptionLabel)
134
+ .join(", ")
135
+ : selectedOptions.length === 0
136
+ ? nothingSelectedText
137
+ : "",
125
138
  filteredOptions,
126
139
  selectedOptions,
127
140
  allOptions: initialOptions,
@@ -56,7 +56,7 @@ function ComboBoxBase(props) {
56
56
  // Do a one-time initialize of fieldState
57
57
  const [fieldState, setFieldState] = (0, react_1.useState)(() => {
58
58
  return {
59
- inputValue: getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText),
59
+ inputValue: getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly),
60
60
  searchValue: undefined,
61
61
  optionsLoading: false,
62
62
  };
@@ -179,10 +179,10 @@ function ComboBoxBase(props) {
179
179
  else {
180
180
  setFieldState((prevState) => ({
181
181
  ...prevState,
182
- inputValue: getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText),
182
+ inputValue: getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly),
183
183
  }));
184
184
  }
185
- }, [state.isOpen, selectedOptions, getOptionLabel, multiselect, nothingSelectedText]);
185
+ }, [state.isOpen, selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly]);
186
186
  // For the most part, the returned props contain `aria-*` and `id` attributes for accessibility purposes.
187
187
  const { buttonProps: triggerProps, inputProps, listBoxProps, labelProps, } = (0, react_aria_1.useComboBox)({
188
188
  ...comboBoxProps,
@@ -213,12 +213,14 @@ function ComboBoxBase(props) {
213
213
  return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.fdc.w100.maxw(fieldMaxWidth).if(labelStyle === "left").maxw100.$, ref: comboBoxRef, children: [(0, jsx_runtime_1.jsx)(ComboBoxInput_1.ComboBoxInput, { ...otherProps, fullWidth: fullWidth, buttonProps: buttonProps, buttonRef: triggerRef, inputProps: inputProps, inputRef: inputRef, inputWrapRef: inputWrapRef, listBoxRef: listBoxRef, state: state, labelProps: labelProps, selectedOptions: selectedOptions, getOptionValue: getOptionValue, getOptionLabel: getOptionLabel, contrast: contrast, nothingSelectedText: nothingSelectedText, borderless: borderless, tooltip: (0, components_1.resolveTooltip)(disabled, undefined, readOnly), resetField: resetField }), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, { triggerRef: triggerRef, popoverRef: popoverRef, positionProps: positionProps, onClose: () => state.close(), isOpen: state.isOpen, minWidth: 200, children: (0, jsx_runtime_1.jsx)(ListBox_1.ListBox, { ...listBoxProps, positionProps: positionProps, state: state, listBoxRef: listBoxRef, selectedOptions: selectedOptions, getOptionLabel: getOptionLabel, getOptionValue: (o) => (0, Value_1.valueToKey)(getOptionValue(o)), contrast: contrast, horizontalLayout: labelStyle === "left", loading: fieldState.optionsLoading, disabledOptionsWithReasons: disabledOptionsWithReasons }) }))] }));
214
214
  }
215
215
  exports.ComboBoxBase = ComboBoxBase;
216
- function getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText) {
216
+ function getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, readOnly) {
217
217
  return selectedOptions.length === 1
218
218
  ? getOptionLabel(selectedOptions[0])
219
- : multiselect && selectedOptions.length === 0
220
- ? nothingSelectedText
221
- : "";
219
+ : readOnly && selectedOptions.length > 0
220
+ ? selectedOptions.map(getOptionLabel).join(", ")
221
+ : multiselect && selectedOptions.length === 0
222
+ ? nothingSelectedText
223
+ : "";
222
224
  }
223
225
  /** Transforms/simplifies `optionsOrLoad` into just options, with unsetLabel maybe added. */
224
226
  function initializeOptions(optionsOrLoad, getOptionValue, unsetLabel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.333.0",
3
+ "version": "2.333.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",