@box/blueprint-web 10.1.0 → 10.2.0

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.
@@ -69,6 +69,7 @@ const RootInner = ({
69
69
  noResultMessage = '',
70
70
  clearOnBlur = !freeInput,
71
71
  clearOnEscape = false,
72
+ deleteChipOnBackspace = false,
72
73
  portalElement,
73
74
  hideSelectedOptions = false,
74
75
  unmountOnHide = false,
@@ -188,6 +189,23 @@ const RootInner = ({
188
189
  },
189
190
  // eslint-disable-next-line react-hooks/exhaustive-deps
190
191
  [selectedValueMemoized, setInputValue, focusInput]);
192
+ const removeMultiSelectInputChip = useCallback(id => {
193
+ // For multi-select variant only
194
+ selectStore.setValue(prev => {
195
+ if (Array.isArray(prev)) {
196
+ // unselect corresponding option
197
+ const remainingValues = prev.filter(val => val !== id);
198
+ // focus combobox input if no more input chips
199
+ if (remainingValues.length === 0) {
200
+ focusInput();
201
+ }
202
+ // update state
203
+ return remainingValues;
204
+ }
205
+ // do nothing it single-select
206
+ return prev;
207
+ });
208
+ }, [selectStore, focusInput]);
191
209
  const handleKeyDown = useCallback(event => {
192
210
  // Close menu
193
211
  if (event.key === 'Enter' || event.key === 'Tab') {
@@ -209,7 +227,12 @@ const RootInner = ({
209
227
  resetSelectedValue();
210
228
  }
211
229
  }
212
- }, [clearOnEscape, isOpen, resetSelectedValue, setInputValue, setOpen]);
230
+ if (event.key === 'Backspace') {
231
+ if (deleteChipOnBackspace && multiselect && !inputValue && selectedValue.length) {
232
+ removeMultiSelectInputChip(selectedValue[selectedValue.length - 1]);
233
+ }
234
+ }
235
+ }, [clearOnEscape, removeMultiSelectInputChip, deleteChipOnBackspace, isOpen, resetSelectedValue, setInputValue, setOpen, inputValue, multiselect, selectedValue]);
213
236
  // Reset input on blur
214
237
  const handleOnBlur = useCallback(() => {
215
238
  if (!clearOnBlur || isOpen) {
@@ -222,23 +245,6 @@ const RootInner = ({
222
245
  const handleOnFocus = useCallback(event => {
223
246
  onFocus?.(event);
224
247
  }, [onFocus]);
225
- const removeMultiSelectInputChip = id => {
226
- // For multi-select variant only
227
- selectStore.setValue(prev => {
228
- if (Array.isArray(prev)) {
229
- // unselect corresponding option
230
- const remainingValues = prev.filter(val => val !== id);
231
- // focus combobox input if no more input chips
232
- if (remainingValues.length === 0) {
233
- focusInput();
234
- }
235
- // update state
236
- return remainingValues;
237
- }
238
- // do nothing it single-select
239
- return prev;
240
- });
241
- };
242
248
  const handleFocusInputOnEvent = useCallback(event => {
243
249
  // don't focus if child element event was triggered
244
250
  if (event.target !== event.currentTarget) {
@@ -125,6 +125,11 @@ export interface ComboboxBaseProps<Multiple extends boolean, FreeInput extends b
125
125
  * If `true`, clear all values when the user presses escape and the dropdown menu is closed.
126
126
  */
127
127
  clearOnEscape?: boolean;
128
+ /**
129
+ * If `true`, clear last multiselect chip when the user presses backspace and the input has no value.
130
+ * @default false
131
+ */
132
+ deleteChipOnBackspace?: boolean;
128
133
  /**
129
134
  * The name of the combobox. Submitted with its owning form as part of a name/value pair.
130
135
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@box/blueprint-web",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "publishConfig": {