@box/blueprint-web 7.0.0 → 7.0.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.
@@ -72,7 +72,7 @@ const ChipsGroup = props => {
72
72
  // it is not the case for the Chips Group as per the a11y pattern. In this case, the error is false positive.
73
73
  __checkInteractivity: false,
74
74
  "aria-hidden": true,
75
- content: childElement.props.label,
75
+ content: childElement.props.tooltip ?? childElement.props.label,
76
76
  children: /*#__PURE__*/React__default.cloneElement(childElement, {
77
77
  // Register the InputChip reference
78
78
  ref: node => {
@@ -16,6 +16,14 @@ import styles from './combobox.module.js';
16
16
 
17
17
  const getOptionValue = option => typeof option === 'string' ? option : option.value;
18
18
  const getOptionFromValue = (value, options) => options.find(option => typeof option === 'string' ? option === value : option.value === value);
19
+ const getDisplayValueFromOptionValue = (optionValue, options, displayValue) => {
20
+ const option = getOptionFromValue(optionValue, options);
21
+ return displayValue && option ? displayValue(option) : optionValue;
22
+ };
23
+ const getTooltipValueFromOptionValue = (optionValue, options, displayTooltip) => {
24
+ const option = getOptionFromValue(optionValue, options);
25
+ return displayTooltip && option ? displayTooltip(option) : undefined;
26
+ };
19
27
  const RootInner = ({
20
28
  as = 'input',
21
29
  ...props
@@ -43,6 +51,7 @@ const RootInner = ({
43
51
  onValueChange,
44
52
  displayValue,
45
53
  displayAvatar,
54
+ displayTooltip,
46
55
  renderOption,
47
56
  options,
48
57
  filterFn,
@@ -129,12 +138,6 @@ const RootInner = ({
129
138
  }
130
139
  return visibleOptions.filter(option => !selectedValue.includes(getOptionValue(option)));
131
140
  }, [filterFn, options, hideSelectedOptions, inputValue, selectedValue]);
132
- const getDisplayValueFromOptionValue = useCallback(optionValue => {
133
- const option = getOptionFromValue(optionValue, options);
134
- return displayValue && option ? displayValue(option) : optionValue;
135
- },
136
- // eslint-disable-next-line react-hooks/exhaustive-deps
137
- [displayValue]);
138
141
  const getDisplayAvatarFromOptionValue = useCallback(optionValue => {
139
142
  const option = getOptionFromValue(optionValue, options);
140
143
  return displayAvatar && option ? displayAvatar(option) : undefined;
@@ -161,11 +164,13 @@ const RootInner = ({
161
164
  if (Array.isArray(selectedValueMemoized)) {
162
165
  setInputValue('');
163
166
  } else if (selectedValueMemoized) {
164
- setInputValue(getDisplayValueFromOptionValue(selectedValueMemoized));
167
+ setInputValue(getDisplayValueFromOptionValue(selectedValueMemoized, options, displayValue));
165
168
  // Also focus input for single-select variant
166
169
  focusInput();
167
170
  }
168
- }, [selectedValueMemoized, getDisplayValueFromOptionValue, setInputValue, focusInput]);
171
+ },
172
+ // eslint-disable-next-line react-hooks/exhaustive-deps
173
+ [selectedValueMemoized, setInputValue, focusInput]);
169
174
  const handleKeyDown = useCallback(event => {
170
175
  // Close menu
171
176
  if (event.key === 'Enter' || event.key === 'Tab') {
@@ -190,8 +195,10 @@ const RootInner = ({
190
195
  if (!clearOnBlur || isOpen) {
191
196
  return;
192
197
  }
193
- setInputValue(Array.isArray(selectedValue) ? '' : getDisplayValueFromOptionValue(selectedValue));
194
- }, [clearOnBlur, getDisplayValueFromOptionValue, isOpen, selectedValue, setInputValue]);
198
+ setInputValue(Array.isArray(selectedValue) ? '' : getDisplayValueFromOptionValue(selectedValue, options, displayValue));
199
+ },
200
+ // eslint-disable-next-line react-hooks/exhaustive-deps
201
+ [clearOnBlur, isOpen, selectedValue, setInputValue]);
195
202
  const removeInputChip = id => {
196
203
  // For multi-select variant only
197
204
  selectStore.setValue(prev => {
@@ -230,8 +237,9 @@ const RootInner = ({
230
237
  children: [showChipsGroup && jsx(ChipsGroup, {
231
238
  children: selectedValue.map(selected => jsx(InputChip, {
232
239
  avatar: getDisplayAvatarFromOptionValue(selected),
233
- label: getDisplayValueFromOptionValue(selected),
234
- onDelete: () => removeInputChip(selected)
240
+ label: getDisplayValueFromOptionValue(selected, options, displayValue),
241
+ onDelete: () => removeInputChip(selected),
242
+ tooltip: getTooltipValueFromOptionValue(selected, options, displayTooltip)
235
243
  }, selected))
236
244
  }), jsx("div", {
237
245
  className: styles.textInputWrapper,
@@ -86,6 +86,10 @@ export interface ComboboxBaseProps<Multiple extends boolean, FreeInput extends b
86
86
  * If not provided `displayValue()` is used to render select option item with a checkmark.
87
87
  */
88
88
  displayAvatar?: (option: T) => React.ReactElement | undefined;
89
+ /**
90
+ * Return a string representation of a tooltip displayed on hover of an Input Chip in Combobox.
91
+ */
92
+ displayTooltip?: (option: T) => string;
89
93
  /**
90
94
  * Return a JSX representations of an option displayed in Combobox dropdown
91
95
  * If not provided `displayValue()` is used to render select option item with a checkmark.
@@ -4,6 +4,10 @@ export interface InputChipProps extends HTMLAttributes<HTMLElement> {
4
4
  * Text content inside the Chip.
5
5
  * */
6
6
  label: string;
7
+ /**
8
+ * Custom tooltip for the Chip.
9
+ */
10
+ tooltip?: string;
7
11
  /**
8
12
  * The Avatar element to display.
9
13
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/blueprint-web",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -58,7 +58,7 @@
58
58
  "@box/storybook-utils": "^0.1.0",
59
59
  "react-stately": "^3.31.1"
60
60
  },
61
- "gitHead": "faa94f4accac0a35b3bda6c6fdd1cce21bf65b65",
61
+ "gitHead": "5bb69c3c599276bf63d8b23de555782344294ad0",
62
62
  "module": "lib-esm/index.js",
63
63
  "main": "lib-esm/index.js",
64
64
  "exports": {