grommet 2.26.0 → 2.27.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.
Files changed (86) hide show
  1. package/all/stories/AllComponents.js +19 -126
  2. package/components/Accordion/stories/CustomHeader.js +3 -1
  3. package/components/Avatar/Avatar.js +22 -9
  4. package/components/CheckBox/StyledCheckBox.js +9 -5
  5. package/components/DataChart/Detail.js +3 -1
  6. package/components/DataTable/index.d.ts +6 -6
  7. package/components/DateInput/DateInput.js +1 -1
  8. package/components/Diagram/Diagram.js +2 -1
  9. package/components/Drop/stories/Inline.js +1 -1
  10. package/components/Drop/stories/Overflow.js +1 -1
  11. package/components/Drop/stories/Plain.js +1 -1
  12. package/components/Drop/stories/Simple.js +1 -1
  13. package/components/Drop/stories/Styled.js +1 -1
  14. package/components/List/List.js +16 -13
  15. package/components/List/stories/Order.js +1 -0
  16. package/components/List/stories/Pinned.js +1 -0
  17. package/components/List/stories/Selection.js +1 -0
  18. package/components/List/stories/onClickItem.js +1 -0
  19. package/components/Notification/Notification.js +2 -2
  20. package/components/Notification/index.d.ts +1 -1
  21. package/components/Notification/propTypes.js +1 -1
  22. package/components/RadioButton/README.md +1 -279
  23. package/components/RadioButton/RadioButton.js +1 -0
  24. package/components/Select/Select.js +8 -4
  25. package/components/Select/SelectContainer.js +4 -4
  26. package/components/Select/utils.js +28 -2
  27. package/components/SelectMultiple/SelectMultiple.js +4 -4
  28. package/components/SelectMultiple/SelectMultipleContainer.js +10 -8
  29. package/components/SelectMultiple/SelectMultipleValue.js +18 -21
  30. package/components/SelectMultiple/SelectionSummary.js +1 -1
  31. package/components/SelectMultiple/stories/ObjectOptions.js +25 -1
  32. package/components/Sidebar/stories/Labels.js +4 -1
  33. package/components/TextArea/stories/NonResizable.js +1 -0
  34. package/components/TextArea/stories/Simple.js +1 -0
  35. package/es6/all/stories/AllComponents.js +21 -121
  36. package/es6/components/Accordion/stories/CustomHeader.js +3 -1
  37. package/es6/components/Avatar/Avatar.js +21 -9
  38. package/es6/components/CheckBox/StyledCheckBox.js +9 -5
  39. package/es6/components/DataChart/Detail.js +3 -1
  40. package/es6/components/DataTable/index.d.ts +6 -6
  41. package/es6/components/DateInput/DateInput.js +1 -1
  42. package/es6/components/Diagram/Diagram.js +2 -1
  43. package/es6/components/Drop/stories/Inline.js +1 -1
  44. package/es6/components/Drop/stories/Overflow.js +1 -1
  45. package/es6/components/Drop/stories/Plain.js +1 -1
  46. package/es6/components/Drop/stories/Simple.js +1 -1
  47. package/es6/components/Drop/stories/Styled.js +1 -1
  48. package/es6/components/List/List.js +16 -13
  49. package/es6/components/List/stories/Order.js +1 -0
  50. package/es6/components/List/stories/Pinned.js +1 -0
  51. package/es6/components/List/stories/Selection.js +1 -0
  52. package/es6/components/List/stories/onClickItem.js +1 -0
  53. package/es6/components/Notification/Notification.js +2 -2
  54. package/es6/components/Notification/index.d.ts +1 -1
  55. package/es6/components/Notification/propTypes.js +1 -1
  56. package/es6/components/RadioButton/README.md +1 -279
  57. package/es6/components/RadioButton/RadioButton.js +1 -0
  58. package/es6/components/Select/Select.js +8 -4
  59. package/es6/components/Select/SelectContainer.js +4 -4
  60. package/es6/components/Select/utils.js +21 -1
  61. package/es6/components/SelectMultiple/SelectMultiple.js +5 -5
  62. package/es6/components/SelectMultiple/SelectMultipleContainer.js +11 -9
  63. package/es6/components/SelectMultiple/SelectMultipleValue.js +19 -22
  64. package/es6/components/SelectMultiple/SelectionSummary.js +2 -2
  65. package/es6/components/SelectMultiple/stories/ObjectOptions.js +25 -1
  66. package/es6/components/Sidebar/stories/Labels.js +4 -1
  67. package/es6/components/TextArea/stories/NonResizable.js +1 -0
  68. package/es6/components/TextArea/stories/Simple.js +1 -0
  69. package/es6/themes/base.d.ts +8 -3
  70. package/es6/themes/base.js +6 -1
  71. package/es6/themes/hacktoberfest2022.js +129 -0
  72. package/es6/themes/index.js +2 -1
  73. package/es6/utils/background.js +4 -4
  74. package/es6/utils/styles.js +3 -1
  75. package/grommet.min.js +1 -1
  76. package/grommet.min.js.map +1 -1
  77. package/package.json +45 -43
  78. package/themes/base.d.ts +8 -3
  79. package/themes/base.js +6 -1
  80. package/themes/hacktoberfest2022.js +137 -0
  81. package/themes/index.js +6 -2
  82. package/tools/grommet-babel-preset-es2015.js +1 -12
  83. package/tools/pack.js +1 -94
  84. package/tools/release-stable.js +1 -27
  85. package/utils/background.js +4 -4
  86. package/utils/styles.js +3 -1
@@ -1,280 +1,2 @@
1
1
  ## RadioButton
2
- A radio button control.
3
-
4
- RadioButton should typically not be used directly.
5
- Instead, use RadioButtonGroup.
6
-
7
- [![](https://cdn-images-1.medium.com/fit/c/120/120/1*TD1P0HtIH9zF0UEH28zYtw.png)](https://storybook.grommet.io/?selectedKind=Input-RadioButton&full=0&stories=1&panelRight=0) [![](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/grommet/grommet-sandbox?initialpath=/radiobutton&module=%2Fsrc%2FRadioButton.js)
8
- ## Usage
9
-
10
- ```javascript
11
- import { RadioButton } from 'grommet';
12
- <RadioButton />
13
- ```
14
-
15
- ## Properties
16
-
17
- **a11yTitle**
18
-
19
- Custom label to be used by screen readers.
20
- When provided, an aria-label will be added to the element.
21
-
22
- ```
23
- string
24
- ```
25
-
26
- **checked**
27
-
28
- Same as React <input checked={} />
29
-
30
- ```
31
- boolean
32
- ```
33
-
34
- **children**
35
-
36
- Function that will be called to render the visual representation.
37
- It will be passed an object indicating whether the button is checked. It
38
- should return a react element.
39
- For example:
40
- `children={({ checked }) => <Box ...>{...}</Box>}`
41
-
42
-
43
- ```
44
- function
45
- ```
46
-
47
- **disabled**
48
-
49
- Same as React <input disabled={} />. Also adds a hidden input element
50
- with the same name so form submissions work.
51
-
52
- ```
53
- boolean
54
- ```
55
-
56
- **id**
57
-
58
- The DOM id attribute value to use for the underlying <input/> element.
59
-
60
- ```
61
- string
62
- ```
63
-
64
- **label**
65
-
66
- Label text to place next to the control.
67
-
68
- ```
69
- node
70
- ```
71
-
72
- **name**
73
-
74
- Required. The DOM name attribute value to use for the underlying <input/>
75
- element.
76
-
77
- ```
78
- string
79
- ```
80
-
81
- **onChange**
82
-
83
- Function that will be called when the user clicks the radio button. It
84
- will be passed a React event object. The current state can be accessed
85
- via event.target.checked. Same as React <input onChange={} />.
86
-
87
- ```
88
- function
89
- ```
90
-
91
- ## Intrinsic element
92
-
93
- ```
94
- input
95
- ```
96
- ## Theme
97
-
98
- **global.colors.control**
99
-
100
- The default color of the border surrounding
101
- the checked icon in RadioButton checked state. Expects `string | { dark: string, light: string }`.
102
-
103
- Defaults to
104
-
105
- ```
106
- { dark: 'accent-1', light: 'brand'}
107
- ```
108
-
109
- **radioButton.border.color**
110
-
111
- The color of the border of the Radio Button. Expects `string | { dark: string, light: string }`.
112
-
113
- Defaults to
114
-
115
- ```
116
- {dark: 'rgba(255, 255, 255, 0.5), light: 'rgba(0, 0, 0, 0.15)}
117
- ```
118
-
119
- **radioButton.border.width**
120
-
121
- The width size of the border of the RadioButton. Expects `string`.
122
-
123
- Defaults to
124
-
125
- ```
126
- 2px
127
- ```
128
-
129
- **radioButton.check.background.color**
130
-
131
- The background color of the checked icon in the RadioButton. Expects `string | {dark: string, light: string}`.
132
-
133
- Defaults to
134
-
135
- ```
136
- undefined
137
- ```
138
-
139
- **radioButton.check.color**
140
-
141
- The color of the checked icon in the RadioButton. Expects `string | { dark: string, light: string }`.
142
-
143
- Defaults to
144
-
145
- ```
146
- undefined
147
- ```
148
-
149
- **radioButton.check.extend**
150
-
151
- Any additional style for the checked RadioButton. Expects `string | (props) => {}`.
152
-
153
- Defaults to
154
-
155
- ```
156
- undefined
157
- ```
158
-
159
- **radioButton.check.radius**
160
-
161
- The border-radius of the RadioButton. Expects `string`.
162
-
163
- Defaults to
164
-
165
- ```
166
- 100%
167
- ```
168
-
169
- **radioButton.color**
170
-
171
- The color of the border surrounding the checked
172
- icon in RadioButton checked state. Expects `string | { dark: string, light: string }`.
173
-
174
- Defaults to
175
-
176
- ```
177
- undefined
178
- ```
179
-
180
- **radioButton.container.extend**
181
-
182
- Any additional style for the container around
183
- the radio button and its label. Expects `string | (props) => {}`.
184
-
185
- Defaults to
186
-
187
- ```
188
- undefined
189
- ```
190
-
191
- **radioButton.extend**
192
-
193
- Any additional style for the radio button itself. Expects `string | (props) => {}`.
194
-
195
- Defaults to
196
-
197
- ```
198
- undefined
199
- ```
200
-
201
- **radioButton.font.weight**
202
-
203
- The font weight of the label. Expects `number | string`.
204
-
205
- Defaults to
206
-
207
- ```
208
- undefined
209
- ```
210
-
211
- **radioButton.gap**
212
-
213
- The gap between the label and the RadioButton itself. Expects `string`.
214
-
215
- Defaults to
216
-
217
- ```
218
- small
219
- ```
220
-
221
- **radioButton.hover.background.color**
222
-
223
- The background color of the Box surrounding the RadioButton
224
- when hovered over. Expects `string | { dark: string, light: string }`.
225
-
226
- Defaults to
227
-
228
- ```
229
- undefined
230
- ```
231
-
232
- **radioButton.hover.border.color**
233
-
234
- The color of the RadioButton border when hovered over. Expects `string | { dark: string, light: string }`.
235
-
236
- Defaults to
237
-
238
- ```
239
- {dark: white, light: black}
240
- ```
241
-
242
- **radioButton.icon.extend**
243
-
244
- Any additional style for the RadioButton icon. Expects `string | (props) => {}`.
245
-
246
- Defaults to
247
-
248
- ```
249
- undefined
250
- ```
251
-
252
- **radioButton.icon.size**
253
-
254
- The size of the icon in the RadioButton. Expects `string`.
255
-
256
- Defaults to
257
-
258
- ```
259
- undefined
260
- ```
261
-
262
- **radioButton.icons.circle**
263
-
264
- The icon to replace the inner checked circle. Expects `React.Element`.
265
-
266
- Defaults to
267
-
268
- ```
269
- undefined
270
- ```
271
-
272
- **radioButton.size**
273
-
274
- The size of the RadioButton. Expects `string`.
275
-
276
- Defaults to
277
-
278
- ```
279
- 24px
280
- ```
2
+ Documentation for this component: https://v2.grommet.io/radiobutton
@@ -91,6 +91,7 @@ var RadioButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
91
91
  },
92
92
  round: theme.radioButton.check.radius
93
93
  }, checked && (Icon ? /*#__PURE__*/React.createElement(Icon, {
94
+ theme: theme,
94
95
  as: StyledRadioButtonIcon
95
96
  }) : /*#__PURE__*/React.createElement(StyledRadioButtonIcon, {
96
97
  viewBox: "0 0 24 24",
@@ -45,7 +45,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
45
45
  gridArea = _ref.gridArea,
46
46
  id = _ref.id,
47
47
  icon = _ref.icon,
48
- labelKey = _ref.labelKey,
48
+ labelKeyProp = _ref.labelKey,
49
49
  margin = _ref.margin,
50
50
  messages = _ref.messages,
51
51
  multiple = _ref.multiple,
@@ -68,7 +68,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
68
68
  selected = _ref.selected,
69
69
  size = _ref.size,
70
70
  valueProp = _ref.value,
71
- valueKey = _ref.valueKey,
71
+ valueKeyProp = _ref.valueKey,
72
72
  valueLabel = _ref.valueLabel,
73
73
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
74
74
 
@@ -77,11 +77,15 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
77
77
  var formContext = useContext(FormContext);
78
78
 
79
79
  var _useContext = useContext(MessageContext),
80
- format = _useContext.format; // Determine if the Select is opened with the keyboard. If so,
80
+ format = _useContext.format; // For greater resilience, use labelKey if valueKey isn't provided and
81
+ // vice versa. https://github.com/grommet/grommet/pull/6299
82
+
83
+
84
+ var valueKey = valueKeyProp || labelKeyProp;
85
+ var labelKey = labelKeyProp || valueKeyProp; // Determine if the Select is opened with the keyboard. If so,
81
86
  // focus should be set on the first option when the drop opens
82
87
  // see set initial focus code in SelectContainer.js
83
88
 
84
-
85
89
  var usingKeyboard = useKeyboard(); // value is used for what we receive in valueProp and the basis for
86
90
  // what we send with onChange
87
91
  // When 'valueKey' sets 'reduce', the value(s) here should match
@@ -133,7 +133,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
133
133
  // deprecated in favor of value
134
134
  result = selected.indexOf(index) !== -1;
135
135
  } else {
136
- var optionVal = getOptionValue(index, options, valueKey || labelKey);
136
+ var optionVal = getOptionValue(index, options, valueKey);
137
137
 
138
138
  if (Array.isArray(value)) {
139
139
  if (value.length === 0) {
@@ -142,7 +142,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
142
142
  result = value.indexOf(optionVal) !== -1;
143
143
  } else if (valueKey) {
144
144
  result = value.some(function (valueItem) {
145
- var valueValue = typeof valueKey === 'function' ? valueKey(valueItem) : valueItem[valueKey];
145
+ var valueValue = typeof valueKey === 'function' ? valueKey(valueItem) : valueItem[valueKey] || valueItem[valueKey.key];
146
146
  return valueValue === optionVal;
147
147
  });
148
148
  }
@@ -155,7 +155,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
155
155
  }
156
156
 
157
157
  return result;
158
- }, [selected, value, valueKey, options, labelKey]);
158
+ }, [selected, value, valueKey, options]);
159
159
  var selectOption = useCallback(function (index) {
160
160
  return function (event) {
161
161
  if (onChange) {
@@ -352,7 +352,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
352
352
  });
353
353
  if (typeof child === 'string' || child.props && child.props.children && typeof child.props.children === 'string') textComponent = true;
354
354
  } else if (theme.select.options) {
355
- child = /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.options.text, getOptionLabel(index, options, labelKey || valueKey)));
355
+ child = /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.options.text, getOptionLabel(index, options, labelKey)));
356
356
  textComponent = true;
357
357
  } // if we have a child, turn on plain, and hoverIndicator
358
358
 
@@ -14,6 +14,26 @@ export var getOptionLabel = function getOptionLabel(index, options, labelKey) {
14
14
  export var getOptionValue = function getOptionValue(index, options, valueKey) {
15
15
  return applyKey(options[index], valueKey);
16
16
  };
17
+ export var getOptionIndex = function getOptionIndex(options, i, valueKey) {
18
+ if (options) {
19
+ if (typeof i === 'object') return options.findIndex(function (x) {
20
+ return applyKey(x, valueKey) === applyKey(i, valueKey);
21
+ });
22
+ return options.indexOf(i);
23
+ }
24
+
25
+ return undefined;
26
+ };
27
+ export var arrayIncludes = function arrayIncludes(arr, i, valueKey) {
28
+ if (arr) {
29
+ if (typeof i === 'object') return arr.some(function (x) {
30
+ return applyKey(x, valueKey) === applyKey(i, valueKey);
31
+ });
32
+ return arr.includes(i);
33
+ }
34
+
35
+ return undefined;
36
+ };
17
37
  export var useDisabled = function useDisabled(disabled, disabledKey, options, valueKey) {
18
38
  return useCallback(function (index) {
19
39
  var option = options[index];
@@ -26,7 +46,7 @@ export var useDisabled = function useDisabled(disabled, disabledKey, options, va
26
46
  result = disabled.indexOf(index) !== -1;
27
47
  } else {
28
48
  var optionVal = getOptionValue(index, options, valueKey);
29
- result = disabled.indexOf(optionVal) !== -1;
49
+ result = getOptionIndex(disabled, options[index], valueKey) !== -1 || getOptionIndex(disabled, optionVal, valueKey) !== -1;
30
50
  }
31
51
  }
32
52
 
@@ -15,7 +15,7 @@ import { FormContext } from '../Form/FormContext';
15
15
  import { SelectMultipleValue } from './SelectMultipleValue';
16
16
  import { SelectMultipleContainer } from './SelectMultipleContainer';
17
17
  import { HiddenInput, SelectTextInput, StyledSelectDropButton } from '../Select/StyledSelect';
18
- import { applyKey, getNormalizedValue, changeEvent, getSelectIcon, getIconColor, getDisplayLabelKey } from '../Select/utils';
18
+ import { applyKey, getNormalizedValue, changeEvent, getSelectIcon, getIconColor, getDisplayLabelKey, arrayIncludes } from '../Select/utils';
19
19
  import { DefaultSelectTextInput } from '../Select/DefaultSelectTextInput';
20
20
  import { MessageContext } from '../../contexts/MessageContext';
21
21
  import { SelectMultiplePropTypes } from './propTypes';
@@ -169,17 +169,17 @@ var SelectMultiple = /*#__PURE__*/forwardRef(function (_ref, ref) {
169
169
  if (onOpen) onOpen();
170
170
  }, [onOpen, open]);
171
171
  useEffect(function () {
172
- if (sortSelectedOnClose && value && (open && search || !open)) {
172
+ if (sortSelectedOnClose && (open && search || !open)) {
173
173
  var selectedOptions = optionsProp.filter(function (option) {
174
- return value.includes(valueKey && valueKey.reduce ? applyKey(option, valueKey) : option);
174
+ return arrayIncludes(value, valueKey && valueKey.reduce ? applyKey(option, valueKey) : option, valueKey || labelKey);
175
175
  });
176
176
  var unselectedOptions = optionsProp.filter(function (i) {
177
- return !selectedOptions.includes(i);
177
+ return !arrayIncludes(selectedOptions, i, valueKey || labelKey);
178
178
  });
179
179
  var nextOrderedOptions = selectedOptions.concat(unselectedOptions);
180
180
  setOrderedOptions(nextOrderedOptions);
181
181
  }
182
- }, [open, sortSelectedOnClose, optionsProp, value, valueKey, search]);
182
+ }, [labelKey, open, sortSelectedOnClose, optionsProp, value, valueKey, search]);
183
183
  var onRequestClose = useCallback(function () {
184
184
  setOpen(false);
185
185
  if (onClose) onClose();
@@ -14,7 +14,7 @@ import { Text } from '../Text';
14
14
  import { TextInput } from '../TextInput';
15
15
  import { SelectionSummary } from './SelectionSummary';
16
16
  import { StyledContainer, OptionsContainer, SelectOption } from '../Select/StyledSelect';
17
- import { applyKey, getOptionLabel, getOptionValue, useDisabled } from '../Select/utils';
17
+ import { applyKey, getOptionLabel, getOptionValue, useDisabled, getOptionIndex, arrayIncludes } from '../Select/utils';
18
18
  import { EmptySearchOption } from '../Select/EmptySearchOption';
19
19
  var SelectMultipleContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
20
20
  var _optionsRef$current;
@@ -135,7 +135,7 @@ var SelectMultipleContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
135
135
  return function (event) {
136
136
  if (onChange) {
137
137
  var nextOptionIndexesInValue = optionIndexesInValue.slice(0);
138
- var allOptionsIndex = allOptions.indexOf(options[index]);
138
+ var allOptionsIndex = getOptionIndex(allOptions, options[index], valueKey || labelKey);
139
139
  var valueIndex = optionIndexesInValue.indexOf(allOptionsIndex);
140
140
 
141
141
  if (valueIndex === -1 && (!limit || (value == null ? void 0 : value.length) < limit)) {
@@ -155,7 +155,7 @@ var SelectMultipleContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
155
155
  });
156
156
  }
157
157
  };
158
- }, [limit, onChange, optionIndexesInValue, options, allOptions, valueKey, value]);
158
+ }, [labelKey, limit, onChange, optionIndexesInValue, options, allOptions, valueKey, value]);
159
159
  var onNextOption = useCallback(function (event) {
160
160
  event.preventDefault();
161
161
  var nextActiveIndex = activeIndex + 1;
@@ -235,7 +235,7 @@ var SelectMultipleContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
235
235
  if (typeof disabledProp[0] === 'number') {
236
236
  result = disabledProp.indexOf(index) !== -1;
237
237
  } else {
238
- result = disabledProp.indexOf(getOptionValue(index, options, valueKey || labelKey)) !== -1;
238
+ result = getOptionIndex(disabledProp, getOptionValue(index, options, valueKey || labelKey), valueKey || labelKey) !== -1;
239
239
  }
240
240
  }
241
241
 
@@ -353,7 +353,7 @@ var SelectMultipleContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
353
353
  show: activeIndex !== -1 ? activeIndex : undefined
354
354
  }, function (option, index, optionRef) {
355
355
  var optionDisabled = isDisabled(index);
356
- var optionSelected = value ? value.includes(valueKey && valueKey.reduce ? applyKey(option, valueKey) : option) : false;
356
+ var optionSelected = value ? arrayIncludes(value, valueKey && valueKey.reduce ? applyKey(option, valueKey) : option, valueKey || labelKey) : false;
357
357
  var optionActive = activeIndex === index;
358
358
  var optionLabel = getOptionLabel(index, options, labelKey || valueKey); // Determine whether the label is done as a child or
359
359
  // as an option Button kind property.
@@ -383,13 +383,15 @@ var SelectMultipleContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
383
383
  }
384
384
 
385
385
  if (!children && search) {
386
- if (typeof optionLabel === 'string' && optionLabel.toLowerCase().indexOf(search) >= 0) {
386
+ var searchText = search.toLowerCase();
387
+
388
+ if (typeof optionLabel === 'string' && optionLabel.toLowerCase().indexOf(searchText) >= 0) {
387
389
  // code to bold search term in matching options
388
- var boldIndex = optionLabel.toLowerCase().indexOf(search);
390
+ var boldIndex = optionLabel.toLowerCase().indexOf(searchText);
389
391
  var childBeginning = optionLabel.substring(0, boldIndex);
390
- var childBold = optionLabel.substring(boldIndex, boldIndex + search.length);
392
+ var childBold = optionLabel.substring(boldIndex, boldIndex + searchText.length);
391
393
  childBold = /*#__PURE__*/React.createElement("b", null, childBold);
392
- var childEnd = optionLabel.substring(boldIndex + search.length);
394
+ var childEnd = optionLabel.substring(boldIndex + searchText.length);
393
395
  child = /*#__PURE__*/React.createElement(CheckBox, {
394
396
  label: /*#__PURE__*/React.createElement(Box, {
395
397
  alignSelf: "center",
@@ -3,7 +3,7 @@ import { Box } from '../Box';
3
3
  import { Button } from '../Button';
4
4
  import { CheckBox } from '../CheckBox';
5
5
  import { SelectOption } from '../Select/StyledSelect';
6
- import { applyKey, getOptionLabel, getOptionValue, useDisabled } from '../Select/utils';
6
+ import { applyKey, getOptionLabel, useDisabled, arrayIncludes, getOptionIndex } from '../Select/utils';
7
7
 
8
8
  var SelectMultipleValue = function SelectMultipleValue(_ref) {
9
9
  var allOptions = _ref.allOptions,
@@ -25,11 +25,13 @@ var SelectMultipleValue = function SelectMultipleValue(_ref) {
25
25
  var isDisabled = useDisabled(disabled, disabledKey, allOptions, valueKey || labelKey);
26
26
  var visibleValue = useCallback(function (i) {
27
27
  var optionValue = valueKey && valueKey.reduce ? applyKey(i, valueKey) : i;
28
- var indexOptions = allOptions.indexOf(i);
28
+ var optionSelected = arrayIncludes(value, optionValue, valueKey || labelKey);
29
+ var indexOptions = getOptionIndex(allOptions, i, valueKey || labelKey);
29
30
  var optionLabel = getOptionLabel(indexOptions, allOptions, labelKey || valueKey);
30
31
  var optionDisabled = isDisabled(indexOptions);
32
+ var valueIndex = getOptionIndex(value, optionValue, valueKey || labelKey);
31
33
 
32
- if (value.indexOf(optionValue) < theme.selectMultiple.maxInline) {
34
+ if (valueIndex < theme.selectMultiple.maxInline) {
33
35
  var child;
34
36
 
35
37
  if (children) {
@@ -42,10 +44,10 @@ var SelectMultipleValue = function SelectMultipleValue(_ref) {
42
44
 
43
45
  return /*#__PURE__*/React.createElement(SelectOption, {
44
46
  role: "option",
45
- a11yTitle: value.includes(optionValue) ? optionLabel + " selected" : optionLabel + " not selected",
47
+ a11yTitle: optionSelected ? optionLabel + " selected" : optionLabel + " not selected",
46
48
  "aria-setsize": value.length,
47
- "aria-posinset": value.indexOf(optionValue) + 1,
48
- "aria-selected": value.includes(optionValue),
49
+ "aria-posinset": valueIndex + 1,
50
+ "aria-selected": optionSelected,
49
51
  "aria-disabled": optionDisabled,
50
52
  plain: true,
51
53
  hoverIndicator: !optionDisabled,
@@ -54,35 +56,30 @@ var SelectMultipleValue = function SelectMultipleValue(_ref) {
54
56
  onClick: function onClick(event) {
55
57
  if (!optionDisabled) {
56
58
  var intermediate = [].concat(value);
57
- var index = value.indexOf(optionValue);
58
59
 
59
- if (intermediate.includes(optionValue)) {
60
+ if (arrayIncludes(intermediate, optionValue, valueKey || labelKey)) {
60
61
  onSelectChange(event, {
61
62
  option: optionValue,
62
63
  value: intermediate.filter(function (v) {
63
- return v !== optionValue;
64
+ return typeof v === 'object' ? applyKey(v, valueKey || labelKey) === applyKey(optionValue, valueKey || labelKey) : v !== optionValue;
64
65
  })
65
66
  });
66
67
 
67
- if (index !== intermediate.length - 1) {
68
+ if (valueIndex !== intermediate.length - 1) {
68
69
  setTimeout(function () {
69
- var nextFocus = document.getElementById("selected-" + intermediate[index + 1]);
70
+ var nextFocus = document.getElementById("selected-" + intermediate[valueIndex + 1]);
70
71
  if (nextFocus) nextFocus.focus();
71
- var result = allOptions.find(function (obj, j) {
72
- return getOptionValue(j, allOptions, valueKey || labelKey) === intermediate[index + 1];
73
- });
74
- setShowA11yDiv("Unselected " + optionLabel + ". \n Focus moved to " + getOptionLabel(allOptions.indexOf(result), allOptions, labelKey || valueKey));
72
+ var result = intermediate[valueIndex + 1];
73
+ setShowA11yDiv("Unselected " + optionLabel + ". \n Focus moved to " + getOptionLabel(getOptionIndex(allOptions, result, valueKey || labelKey), allOptions, labelKey || valueKey));
75
74
  }, 200); // Timeout needed to allow screen reader
76
75
  // time to announce and next item to display on
77
76
  // screen. Based on testing, 200ms is enough time
78
77
  } else if (intermediate.length !== 1) {
79
78
  setTimeout(function () {
80
- var nextFocus = document.getElementById("selected-" + intermediate[index - 1]);
79
+ var nextFocus = document.getElementById("selected-" + intermediate[valueIndex - 1]);
81
80
  if (nextFocus) nextFocus.focus();
82
- var result = allOptions.find(function (obj, j) {
83
- return getOptionValue(j, allOptions, valueKey || labelKey) === intermediate[index - 1];
84
- });
85
- setShowA11yDiv("Unselected " + optionLabel + ". Focus moved to \n " + getOptionLabel(allOptions.indexOf(result), allOptions, labelKey || valueKey));
81
+ var result = intermediate[valueIndex - 1];
82
+ setShowA11yDiv("Unselected " + optionLabel + ". Focus moved to \n " + getOptionLabel(getOptionIndex(allOptions, result, valueKey || labelKey), allOptions, labelKey || valueKey));
86
83
  }, 200); // Timeout needed to allow screen reader
87
84
  // time to announce and next item to display on
88
85
  // screen. Based on testing, 200ms is enough time
@@ -101,7 +98,7 @@ var SelectMultipleValue = function SelectMultipleValue(_ref) {
101
98
  key: optionLabel,
102
99
  pad: "xsmall",
103
100
  tabIndex: "-1",
104
- checked: value.includes(optionValue)
101
+ checked: optionSelected
105
102
  }));
106
103
  }
107
104
 
@@ -122,7 +119,7 @@ var SelectMultipleValue = function SelectMultipleValue(_ref) {
122
119
  "aria-multiselectable": true,
123
120
  a11yTitle: "Selected Options"
124
121
  }, value && allOptions.filter(function (i) {
125
- return value.indexOf(valueKey && valueKey.reduce ? applyKey(i, valueKey) : i) !== -1;
122
+ return arrayIncludes(value, valueKey && valueKey.reduce ? applyKey(i, valueKey) : i, valueKey || labelKey);
126
123
  })
127
124
  /* eslint-disable-next-line array-callback-return,
128
125
  consistent-return */
@@ -2,7 +2,7 @@ import React, { useCallback } from 'react';
2
2
  import { Box } from '../Box';
3
3
  import { Button } from '../Button';
4
4
  import { Text } from '../Text';
5
- import { applyKey, getOptionValue, useDisabled } from '../Select/utils';
5
+ import { applyKey, getOptionValue, useDisabled, arrayIncludes } from '../Select/utils';
6
6
 
7
7
  var SelectionSummary = function SelectionSummary(_ref) {
8
8
  var allOptions = _ref.allOptions,
@@ -26,7 +26,7 @@ var SelectionSummary = function SelectionSummary(_ref) {
26
26
 
27
27
  if (value) {
28
28
  for (var i = 0; i < allOptions.length; i += 1) {
29
- if (value.includes(getOptionValue(i, options, valueKey || labelKey)) && isDisabled(i)) disabledSelected += 1;
29
+ if (arrayIncludes(value, getOptionValue(i, options, valueKey || labelKey), valueKey || labelKey) && isDisabled(i)) disabledSelected += 1;
30
30
  }
31
31
 
32
32
  if (value.length === disabledSelected) return true;
@@ -13,12 +13,28 @@ var objectOptions = [{
13
13
  }, {
14
14
  label: 'Purple',
15
15
  value: 4
16
+ }, {
17
+ label: 'Pink',
18
+ value: 5
19
+ }, {
20
+ label: 'Grey',
21
+ value: 6
16
22
  }];
17
23
  export var ObjectOptions = function ObjectOptions() {
18
24
  var _useState = useState(objectOptions),
19
25
  options = _useState[0],
20
26
  setOptions = _useState[1];
21
27
 
28
+ var _useState2 = useState([{
29
+ label: 'Red',
30
+ value: 1
31
+ }, {
32
+ label: 'Grey',
33
+ value: 6
34
+ }]),
35
+ value = _useState2[0],
36
+ setValue = _useState2[1];
37
+
22
38
  return (
23
39
  /*#__PURE__*/
24
40
  // Uncomment <Grommet> lines when using outside of storybook
@@ -30,6 +46,7 @@ export var ObjectOptions = function ObjectOptions() {
30
46
  justify: "start",
31
47
  pad: "large"
32
48
  }, /*#__PURE__*/React.createElement(Text, null, "SelectMultiple with Object Options"), /*#__PURE__*/React.createElement(SelectMultiple, {
49
+ value: value,
33
50
  onSearch: function onSearch(text) {
34
51
  var escapedText = text.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); // Create the regular expression with modified value which
35
52
  // handles escaping special characters. Without escaping special
@@ -48,7 +65,14 @@ export var ObjectOptions = function ObjectOptions() {
48
65
  valueKey: {
49
66
  key: 'value'
50
67
  },
51
- options: options
68
+ options: options,
69
+ onClose: function onClose() {
70
+ setOptions(objectOptions);
71
+ },
72
+ onChange: function onChange(_ref) {
73
+ var nextValue = _ref.value;
74
+ setValue(nextValue);
75
+ }
52
76
  })) // </Grommet>
53
77
 
54
78
  );