grommet 2.20.1 → 2.21.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 (167) hide show
  1. package/components/Button/Button.js +2 -3
  2. package/components/Chart/Chart.js +14 -6
  3. package/components/DataChart/DataChart.js +84 -21
  4. package/components/DataChart/Detail.js +8 -0
  5. package/components/DataChart/XAxis.js +19 -10
  6. package/components/DataChart/index.d.ts +10 -2
  7. package/components/DataChart/propTypes.js +2 -1
  8. package/components/DataChart/stories/Offset.js +82 -0
  9. package/components/DataChart/stories/StackedAreas.js +77 -0
  10. package/components/DataChart/stories/StackedLines.js +73 -0
  11. package/components/DateInput/DateInput.js +21 -9
  12. package/components/DateInput/index.d.ts +1 -0
  13. package/components/DateInput/propTypes.js +1 -0
  14. package/components/List/List.js +11 -2
  15. package/components/List/index.d.ts +1 -0
  16. package/components/List/propTypes.js +1 -0
  17. package/components/Markdown/Markdown.js +4 -2
  18. package/components/Menu/Menu.js +39 -12
  19. package/components/Notification/Notification.js +17 -6
  20. package/components/Notification/index.d.ts +7 -1
  21. package/components/Notification/propTypes.js +4 -1
  22. package/components/RangeInput/StyledRangeInput.js +1 -1
  23. package/components/RangeInput/stories/SimpleRange.js +2 -6
  24. package/components/Select/Select.js +44 -12
  25. package/components/Select/SelectContainer.js +22 -6
  26. package/components/Select/stories/ChildrenRender.js +37 -33
  27. package/components/Select/stories/Clear.js +7 -3
  28. package/components/Select/stories/Controlled.js +32 -28
  29. package/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
  30. package/components/Select/stories/Disabled.js +29 -25
  31. package/components/Select/stories/InsideFormField.js +29 -27
  32. package/components/Select/stories/LazyLoadingOptions.js +27 -25
  33. package/components/Select/stories/ManyOptions.js +47 -43
  34. package/components/Select/stories/Multiple.js +25 -21
  35. package/components/Select/stories/ObjectOptions.js +27 -25
  36. package/components/Select/stories/Search.js +62 -58
  37. package/components/Select/stories/Simple.js +26 -22
  38. package/components/Select/stories/Uncontrolled.js +24 -20
  39. package/components/Select/stories/ValueLabel.js +40 -36
  40. package/components/Select/stories/typescript/CreateOption.tsx +34 -30
  41. package/components/Sidebar/stories/Labels.js +25 -19
  42. package/components/Sidebar/stories/typescript/Simple.tsx +17 -12
  43. package/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  44. package/components/SkipLinks/stories/Simple.js +82 -78
  45. package/components/Tab/Tab.js +6 -1
  46. package/components/Table/stories/Default.js +30 -28
  47. package/components/Table/stories/InfiniteScrollInTable.js +39 -35
  48. package/components/Table/stories/MeterInTable.js +26 -24
  49. package/components/Tag/Tag.js +17 -6
  50. package/components/Tag/index.d.ts +8 -0
  51. package/components/Tag/propTypes.js +2 -1
  52. package/components/Tag/stories/Size.js +45 -0
  53. package/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  54. package/components/TextArea/stories/Fill.js +18 -16
  55. package/components/TextArea/stories/InsideFormField.js +43 -41
  56. package/components/TextArea/stories/NonResizable.js +13 -11
  57. package/components/TextArea/stories/Simple.js +13 -11
  58. package/components/TextInput/TextInput.js +5 -8
  59. package/{es6/components/TextInput/stories/typescript → components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
  60. package/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  61. package/components/TextInput/stories/DefaultSuggestion.js +20 -19
  62. package/components/TextInput/stories/Icon.js +22 -21
  63. package/components/TextInput/stories/InsideFormField.js +32 -30
  64. package/components/TextInput/stories/OnSelect.js +20 -19
  65. package/components/TextInput/stories/Password.js +30 -29
  66. package/components/TextInput/stories/Simple.js +17 -16
  67. package/components/TextInput/stories/StyledPlaceholder.js +10 -9
  68. package/components/TextInput/stories/Suggestions.js +19 -18
  69. package/components/TextInput/stories/Uncontrolled.js +18 -17
  70. package/components/TextInput/stories/WithTags.js +19 -18
  71. package/components/Tip/stories/Caret.js +37 -31
  72. package/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
  73. package/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
  74. package/components/Tip/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
  75. package/components/Tip/stories/HeaderActions.js +66 -60
  76. package/components/Tip/stories/InfoTip.js +59 -56
  77. package/components/Tip/stories/typescript/Animated.tsx +26 -21
  78. package/components/Tip/stories/typescript/Children.tsx +52 -51
  79. package/components/Tip/stories/typescript/Simple.tsx +12 -7
  80. package/es6/components/Button/Button.js +2 -3
  81. package/es6/components/Chart/Chart.js +14 -6
  82. package/es6/components/DataChart/DataChart.js +84 -21
  83. package/es6/components/DataChart/Detail.js +7 -0
  84. package/es6/components/DataChart/XAxis.js +19 -10
  85. package/es6/components/DataChart/index.d.ts +10 -2
  86. package/es6/components/DataChart/propTypes.js +2 -1
  87. package/es6/components/DataChart/stories/Offset.js +70 -0
  88. package/es6/components/DataChart/stories/StackedAreas.js +65 -0
  89. package/es6/components/DataChart/stories/StackedLines.js +61 -0
  90. package/es6/components/DateInput/DateInput.js +21 -9
  91. package/es6/components/DateInput/index.d.ts +1 -0
  92. package/es6/components/DateInput/propTypes.js +1 -0
  93. package/es6/components/List/List.js +11 -2
  94. package/es6/components/List/index.d.ts +1 -0
  95. package/es6/components/List/propTypes.js +1 -0
  96. package/es6/components/Markdown/Markdown.js +4 -2
  97. package/es6/components/Menu/Menu.js +40 -13
  98. package/es6/components/Notification/Notification.js +18 -7
  99. package/es6/components/Notification/index.d.ts +7 -1
  100. package/es6/components/Notification/propTypes.js +4 -1
  101. package/es6/components/RangeInput/StyledRangeInput.js +1 -1
  102. package/es6/components/RangeInput/stories/SimpleRange.js +3 -6
  103. package/es6/components/Select/Select.js +44 -12
  104. package/es6/components/Select/SelectContainer.js +22 -6
  105. package/es6/components/Select/stories/ChildrenRender.js +38 -33
  106. package/es6/components/Select/stories/Clear.js +8 -4
  107. package/es6/components/Select/stories/Controlled.js +33 -28
  108. package/es6/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
  109. package/es6/components/Select/stories/Disabled.js +30 -25
  110. package/es6/components/Select/stories/InsideFormField.js +30 -27
  111. package/es6/components/Select/stories/LazyLoadingOptions.js +28 -25
  112. package/es6/components/Select/stories/ManyOptions.js +48 -43
  113. package/es6/components/Select/stories/Multiple.js +26 -21
  114. package/es6/components/Select/stories/ObjectOptions.js +28 -25
  115. package/es6/components/Select/stories/Search.js +63 -58
  116. package/es6/components/Select/stories/Simple.js +27 -22
  117. package/es6/components/Select/stories/Uncontrolled.js +25 -20
  118. package/es6/components/Select/stories/ValueLabel.js +41 -36
  119. package/es6/components/Select/stories/typescript/CreateOption.tsx +34 -30
  120. package/es6/components/Sidebar/stories/Labels.js +26 -20
  121. package/es6/components/Sidebar/stories/typescript/Simple.tsx +17 -12
  122. package/es6/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  123. package/es6/components/SkipLinks/stories/Simple.js +83 -79
  124. package/es6/components/Tab/Tab.js +6 -1
  125. package/es6/components/Table/stories/Default.js +31 -28
  126. package/es6/components/Table/stories/InfiniteScrollInTable.js +40 -36
  127. package/es6/components/Table/stories/MeterInTable.js +27 -24
  128. package/es6/components/Tag/Tag.js +17 -6
  129. package/es6/components/Tag/index.d.ts +8 -0
  130. package/es6/components/Tag/propTypes.js +2 -1
  131. package/es6/components/Tag/stories/Size.js +33 -0
  132. package/es6/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  133. package/es6/components/TextArea/stories/Fill.js +19 -16
  134. package/es6/components/TextArea/stories/InsideFormField.js +44 -41
  135. package/es6/components/TextArea/stories/NonResizable.js +14 -11
  136. package/es6/components/TextArea/stories/Simple.js +14 -11
  137. package/es6/components/TextInput/TextInput.js +5 -8
  138. package/{components/TextInput/stories/typescript → es6/components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
  139. package/es6/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  140. package/es6/components/TextInput/stories/DefaultSuggestion.js +21 -19
  141. package/es6/components/TextInput/stories/Icon.js +23 -21
  142. package/es6/components/TextInput/stories/InsideFormField.js +33 -30
  143. package/es6/components/TextInput/stories/OnSelect.js +21 -19
  144. package/es6/components/TextInput/stories/Password.js +31 -29
  145. package/es6/components/TextInput/stories/Simple.js +18 -16
  146. package/es6/components/TextInput/stories/StyledPlaceholder.js +11 -9
  147. package/es6/components/TextInput/stories/Suggestions.js +20 -18
  148. package/es6/components/TextInput/stories/Uncontrolled.js +19 -17
  149. package/es6/components/TextInput/stories/WithTags.js +20 -18
  150. package/es6/components/Tip/stories/Caret.js +38 -32
  151. package/es6/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
  152. package/es6/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
  153. package/es6/components/Tip/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
  154. package/es6/components/Tip/stories/HeaderActions.js +67 -61
  155. package/es6/components/Tip/stories/InfoTip.js +60 -57
  156. package/es6/components/Tip/stories/typescript/Animated.tsx +26 -21
  157. package/es6/components/Tip/stories/typescript/Children.tsx +52 -51
  158. package/es6/components/Tip/stories/typescript/Simple.tsx +12 -7
  159. package/es6/languages/default.json +2 -1
  160. package/es6/themes/base.d.ts +34 -1
  161. package/es6/themes/base.js +39 -0
  162. package/grommet.min.js +1 -1
  163. package/grommet.min.js.map +1 -1
  164. package/languages/default.json +2 -1
  165. package/package.json +4 -4
  166. package/themes/base.d.ts +34 -1
  167. package/themes/base.js +39 -0
@@ -39,7 +39,8 @@ var _utils3 = require("./utils");
39
39
 
40
40
  var _propTypes = require("./propTypes");
41
41
 
42
- var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "value", "messages"];
42
+ var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "icon", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "value", "messages"],
43
+ _excluded2 = ["icon"];
43
44
 
44
45
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
45
46
 
@@ -57,6 +58,7 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
57
58
  dropProps = _ref.dropProps,
58
59
  format = _ref.format,
59
60
  id = _ref.id,
61
+ icon = _ref.icon,
60
62
  _ref$inline = _ref.inline,
61
63
  inline = _ref$inline === void 0 ? false : _ref$inline,
62
64
  inputProps = _ref.inputProps,
@@ -119,7 +121,17 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
119
121
 
120
122
  var _useState = (0, _react.useState)(schema ? (0, _utils3.valueToText)(normalizedDate, schema) : undefined),
121
123
  textValue = _useState[0],
122
- setTextValue = _useState[1]; // We need to distinguish between the caller changing a Form value
124
+ setTextValue = _useState[1]; // Setting the icon through `inputProps` is deprecated.
125
+ // The `icon` prop should be used instead.
126
+
127
+
128
+ var _ref2 = inputProps || {},
129
+ MaskedInputIcon = _ref2.icon,
130
+ restOfInputProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
131
+
132
+ if (MaskedInputIcon) {
133
+ console.warn("Customizing the DateInput icon through inputProps is deprecated. \nUse the icon prop instead.");
134
+ } // We need to distinguish between the caller changing a Form value
123
135
  // and the user typing a date that he isn't finished with yet.
124
136
  // To handle this, we see if we have a value and the text value
125
137
  // associated with it doesn't align to it, then we update the text value.
@@ -193,8 +205,8 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
193
205
 
194
206
  var formContextValue = (0, _react.useMemo)(function () {
195
207
  return {
196
- useFormInput: function useFormInput(_ref2) {
197
- var valueProp = _ref2.value;
208
+ useFormInput: function useFormInput(_ref3) {
209
+ var valueProp = _ref3.value;
198
210
  return [valueProp, function () {}];
199
211
  }
200
212
  };
@@ -213,7 +225,7 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
213
225
  }
214
226
  }, dropProps),
215
227
  dropContent: calendar,
216
- icon: /*#__PURE__*/_react["default"].createElement(_Calendar.Calendar, {
228
+ icon: icon || MaskedInputIcon || /*#__PURE__*/_react["default"].createElement(_Calendar.Calendar, {
217
229
  size: iconSize
218
230
  })
219
231
  }, buttonProps));
@@ -242,7 +254,7 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
242
254
  disabled: disabled,
243
255
  mask: mask,
244
256
  plain: true
245
- }, inputProps, rest, {
257
+ }, restOfInputProps, rest, {
246
258
  value: textValue,
247
259
  onChange: function onChange(event) {
248
260
  var nextTextValue = event.target.value;
@@ -270,7 +282,7 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
270
282
  })), /*#__PURE__*/_react["default"].createElement(_Button.Button, {
271
283
  onClick: open ? closeCalendar : openCalendar,
272
284
  plain: true,
273
- icon: /*#__PURE__*/_react["default"].createElement(_Calendar.Calendar, {
285
+ icon: icon || MaskedInputIcon || /*#__PURE__*/_react["default"].createElement(_Calendar.Calendar, {
274
286
  size: iconSize
275
287
  }),
276
288
  margin: {
@@ -297,8 +309,8 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
297
309
  left: 'left'
298
310
  }, dropProps),
299
311
  onEsc: closeCalendar,
300
- onClickOutside: function onClickOutside(_ref3) {
301
- var target = _ref3.target;
312
+ onClickOutside: function onClickOutside(_ref4) {
313
+ var target = _ref4.target;
302
314
 
303
315
  if (target !== containerRef.current && !containerRef.current.contains(target)) {
304
316
  closeCalendar();
@@ -11,6 +11,7 @@ export interface DateInputProps {
11
11
  defaultValue?: string | string[];
12
12
  dropProps?: DropType;
13
13
  format?: string;
14
+ icon?: JSX.Element;
14
15
  id?: string;
15
16
  inline?: boolean;
16
17
  inputProps?: MaskedInputType;
@@ -16,6 +16,7 @@ if (process.env.NODE_ENV !== 'production') {
16
16
  defaultValue: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].arrayOf(_propTypes["default"].string)]),
17
17
  dropProps: _propTypes["default"].shape({}),
18
18
  format: _propTypes["default"].string,
19
+ icon: _propTypes["default"].element,
19
20
  id: _propTypes["default"].string,
20
21
  inline: _propTypes["default"].bool,
21
22
  inputProps: _propTypes["default"].shape({}),
@@ -23,7 +23,7 @@ var _utils = require("../../utils");
23
23
 
24
24
  var _propTypes = require("./propTypes");
25
25
 
26
- var _excluded = ["action", "as", "background", "border", "children", "data", "defaultItemProps", "focus", "itemProps", "onOrder", "pad", "paginate", "primaryKey", "secondaryKey", "show", "step", "onClickItem", "onMore"];
26
+ var _excluded = ["action", "as", "background", "border", "children", "data", "defaultItemProps", "focus", "itemKey", "itemProps", "onOrder", "pad", "paginate", "primaryKey", "secondaryKey", "show", "step", "onClickItem", "onMore"];
27
27
 
28
28
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
29
 
@@ -135,6 +135,7 @@ var List = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
135
135
  data = _ref.data,
136
136
  defaultItemProps = _ref.defaultItemProps,
137
137
  focus = _ref.focus,
138
+ itemKey = _ref.itemKey,
138
139
  itemProps = _ref.itemProps,
139
140
  onOrder = _ref.onOrder,
140
141
  pad = _ref.pad,
@@ -315,7 +316,15 @@ var List = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
315
316
  content = item;
316
317
  }
317
318
 
318
- var key = getKey(item, index, itemId);
319
+ if (itemKey) {
320
+ if (typeof itemKey === 'function') {
321
+ itemId = itemKey(item);
322
+ } else {
323
+ itemId = normalize(item, index, itemKey);
324
+ }
325
+ }
326
+
327
+ var key = itemKey ? itemId : getKey(item, index, itemId);
319
328
 
320
329
  if (action) {
321
330
  content = [/*#__PURE__*/_react["default"].createElement(_Box.Box, {
@@ -46,6 +46,7 @@ export interface ListProps<ListItemType> {
46
46
  data?: ListItemType[];
47
47
  gridArea?: GridAreaType;
48
48
  defaultItemProps?: BoxTypes;
49
+ itemKey?: string | ((item: ListItemType) => string | number);
49
50
  itemProps?: {
50
51
  [_: string]: { background?: string; border?: BorderType; pad?: PadType };
51
52
  };
@@ -38,6 +38,7 @@ if (process.env.NODE_ENV !== 'production') {
38
38
  data: _propTypes["default"].arrayOf(_propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].shape({})])),
39
39
  children: _propTypes["default"].func,
40
40
  defaultItemProps: _propTypes["default"].shape(_propTypes2.BoxPropTypes),
41
+ itemKey: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func]),
41
42
  itemProps: _propTypes["default"].shape({}),
42
43
  onMore: _propTypes["default"].func,
43
44
  onClickItem: _propTypes["default"].func,
@@ -96,13 +96,15 @@ var GrommetMarkdown = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
96
96
  component: _TableRow.TableRow
97
97
  }
98
98
  }, heading, components, options && options.overrides); // we use Fragment as the wrapper so we can assign the ref with the div
99
+ // wrapper can still be overridden with the options.
99
100
 
100
101
  return /*#__PURE__*/_react["default"].createElement("div", _extends({
101
102
  ref: ref
102
103
  }, rest), /*#__PURE__*/_react["default"].createElement(_markdownToJsx["default"], {
103
104
  children: children,
104
- options: _extends({}, options, {
105
- wrapper: _react.Fragment,
105
+ options: _extends({
106
+ wrapper: _react.Fragment
107
+ }, options, {
106
108
  overrides: overrides
107
109
  })
108
110
  }));
@@ -39,7 +39,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
39
39
  var ContainerBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
40
40
  displayName: "Menu__ContainerBox",
41
41
  componentId: "sc-17fcys9-0"
42
- })(["max-height:inherit;@media screen and (-ms-high-contrast:active),(-ms-high-contrast:none){width:100%;}", ";"], function (props) {
42
+ })(["max-height:inherit;@media screen and (-ms-high-contrast:active),(-ms-high-contrast:none){width:100%;}:focus{outline:none;}", ";"], function (props) {
43
43
  return props.theme.menu.extend;
44
44
  });
45
45
  /* Notes on keyboard interactivity (based on W3) // For details reference: https://www.w3.org/TR/wai-aria-practices/#menu
@@ -109,7 +109,8 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
109
109
  setAlignControlMirror = _useState[1];
110
110
 
111
111
  var initialAlignTop = alignControlMirror === align.top;
112
- var buttonRefs = {};
112
+ var dropContainerRef = (0, _react.useRef)();
113
+ var buttonRefs = (0, _react.useRef)([]);
113
114
  var constants = (0, _react.useMemo)(function () {
114
115
  return {
115
116
  none: 'none',
@@ -138,13 +139,28 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
138
139
  var onDropOpen = (0, _react.useCallback)(function () {
139
140
  setOpen(true);
140
141
  }, []);
142
+ (0, _react.useEffect)(function () {
143
+ // need to wait for Drop to be ready
144
+ var timer = setTimeout(function () {
145
+ if (isOpen) {
146
+ var optionsNode = dropContainerRef.current;
147
+
148
+ if (optionsNode) {
149
+ optionsNode.focus();
150
+ }
151
+ }
152
+ }, 100);
153
+ return function () {
154
+ return clearTimeout(timer);
155
+ };
156
+ }, [isOpen]);
141
157
 
142
158
  var onSelectMenuItem = function onSelectMenuItem(event) {
143
159
  if (isOpen) {
144
160
  if (activeItemIndex >= 0) {
145
161
  event.preventDefault();
146
162
  event.stopPropagation();
147
- buttonRefs[activeItemIndex].click();
163
+ buttonRefs.current[activeItemIndex].click();
148
164
  }
149
165
  } else {
150
166
  onDropOpen();
@@ -179,7 +195,10 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
179
195
  }
180
196
 
181
197
  setActiveItemIndex(index);
182
- buttonRefs[index].focus();
198
+
199
+ if (buttonRefs.current[index]) {
200
+ buttonRefs.current[index].focus();
201
+ }
183
202
  }
184
203
  };
185
204
 
@@ -195,7 +214,9 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
195
214
  } else {
196
215
  var index;
197
216
 
198
- if (activeItemIndex - 1 < 0) {
217
+ if (activeItemIndex === 'none') {
218
+ index = items.length - 1;
219
+ } else if (activeItemIndex - 1 < 0) {
199
220
  if (constants.controlTop && activeItemIndex - 1 === controlButtonIndex) {
200
221
  index = items.length;
201
222
  } else {
@@ -206,7 +227,10 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
206
227
  }
207
228
 
208
229
  setActiveItemIndex(index);
209
- buttonRefs[index].focus();
230
+
231
+ if (buttonRefs.current[index]) {
232
+ buttonRefs.current[index].focus();
233
+ }
210
234
  }
211
235
  };
212
236
 
@@ -250,7 +274,7 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
250
274
  }, /*#__PURE__*/_react["default"].createElement(_Button.Button, _extends({
251
275
  ref: function ref(r) {
252
276
  // make it accessible at the end of all menu items
253
- buttonRefs[items.length] = r;
277
+ buttonRefs.current[items.length] = r;
254
278
  },
255
279
  a11yTitle: ariaLabel || a11yTitle || format({
256
280
  id: 'menu.closeMenu',
@@ -274,9 +298,8 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
274
298
  } : content));
275
299
 
276
300
  return /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
277
- onDown: onNextMenuItem,
278
- onUp: onPreviousMenuItem,
279
- onEnter: onSelectMenuItem,
301
+ onDown: onDropOpen,
302
+ onUp: onDropOpen,
280
303
  onSpace: onSelectMenuItem,
281
304
  onEsc: onDropClose,
282
305
  onTab: onDropClose,
@@ -300,8 +323,12 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
300
323
  onTab: function onTab(event) {
301
324
  return event.shiftKey ? onPreviousMenuItem(event) : onNextMenuItem(event);
302
325
  },
326
+ onDown: onNextMenuItem,
327
+ onUp: onPreviousMenuItem,
303
328
  onEnter: onSelectMenuItem
304
329
  }, /*#__PURE__*/_react["default"].createElement(ContainerBox, {
330
+ ref: dropContainerRef,
331
+ tabIndex: -1,
305
332
  background: dropBackground || theme.menu.background
306
333
  }, alignControlMirror === 'top' && align.top === 'top' ? controlMirror : undefined, /*#__PURE__*/_react["default"].createElement(_Box.Box, {
307
334
  overflow: "auto"
@@ -324,10 +351,10 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
324
351
  flex: false
325
352
  }, /*#__PURE__*/_react["default"].createElement(_Button.Button, _extends({
326
353
  ref: function ref(r) {
327
- buttonRefs[index] = r;
354
+ buttonRefs.current[index] = r;
328
355
  },
329
356
  onFocus: function onFocus() {
330
- return setActiveItemIndex(index);
357
+ setActiveItemIndex(index);
331
358
  },
332
359
  active: activeItemIndex === index,
333
360
  focusIndicator: false,
@@ -30,9 +30,11 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
30
30
  var Notification = function Notification(_ref) {
31
31
  var message = _ref.message,
32
32
  onClose = _ref.onClose,
33
+ id = _ref.id,
33
34
  status = _ref.status,
34
35
  title = _ref.title,
35
36
  toast = _ref.toast;
37
+ var autoClose = (toast == null ? void 0 : toast.autoClose) === undefined ? true : toast.autoClose;
36
38
 
37
39
  var theme = (0, _react.useContext)(_styledComponents.ThemeContext) || _defaultProps.defaultProps.theme;
38
40
 
@@ -40,16 +42,23 @@ var Notification = function Notification(_ref) {
40
42
  visible = _useState[0],
41
43
  setVisible = _useState[1];
42
44
 
45
+ var position = (0, _react.useMemo)(function () {
46
+ return toast && (toast == null ? void 0 : toast.position) || 'top';
47
+ }, [toast]);
43
48
  var close = (0, _react.useCallback)(function () {
44
49
  setVisible(false);
45
50
  if (onClose) onClose();
46
51
  }, [onClose]);
47
52
  (0, _react.useEffect)(function () {
48
- var timer = setTimeout(close, theme.notification.toast.time || theme.notification.time);
49
- return function () {
50
- return clearTimeout(timer);
51
- };
52
- }, [close, theme.notification.toast.time, theme.notification.time]);
53
+ if (autoClose) {
54
+ var timer = setTimeout(close, theme.notification.toast.time || theme.notification.time);
55
+ return function () {
56
+ return clearTimeout(timer);
57
+ };
58
+ }
59
+
60
+ return undefined;
61
+ }, [autoClose, close, theme.notification.toast.time, theme.notification.time]);
53
62
  var CloseIcon = theme.notification.close.icon;
54
63
  var _theme$notification$s = theme.notification[status],
55
64
  StatusIcon = _theme$notification$s.icon,
@@ -78,8 +87,10 @@ var Notification = function Notification(_ref) {
78
87
  role: "log",
79
88
  modal: false,
80
89
  onEsc: onClose,
90
+ id: id,
81
91
  responsive: true,
82
- plain: true
92
+ plain: true,
93
+ position: position
83
94
  }), content);
84
95
  }
85
96
 
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { LayerPositionType } from '../Layer';
2
3
 
3
4
  export type StatusType = 'critical' | 'warning' | 'normal' | 'unknown';
4
5
 
@@ -6,7 +7,12 @@ export interface NotificationProps {
6
7
  title: string;
7
8
  message?: string;
8
9
  status?: StatusType;
9
- toast?: boolean;
10
+ toast?:
11
+ | boolean
12
+ | {
13
+ autoClose?: boolean;
14
+ position?: LayerPositionType;
15
+ };
10
16
  onClose?: (...args: any[]) => any;
11
17
  }
12
18
 
@@ -14,7 +14,10 @@ if (process.env.NODE_ENV !== 'production') {
14
14
  title: _propTypes["default"].string.isRequired,
15
15
  message: _propTypes["default"].string,
16
16
  status: _propTypes["default"].oneOf(['critical', 'warning', 'normal', 'unknown']),
17
- toast: _propTypes["default"].bool,
17
+ toast: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].shape({
18
+ autoClose: _propTypes["default"].bool,
19
+ position: _propTypes["default"].oneOf(['bottom', 'bottom-left', 'bottom-right', 'center', 'end', 'hidden', 'left', 'right', 'start', 'top', 'top-left', 'top-right'])
20
+ })]),
18
21
  onClose: _propTypes["default"].func
19
22
  };
20
23
  }
@@ -32,7 +32,7 @@ var trackColorStyle = function trackColorStyle(props) {
32
32
 
33
33
  var max = props.max,
34
34
  min = props.min;
35
- var thumbPosition = (props.value - min) / (max - min) * 100 + "%";
35
+ var thumbPosition = ((props.value || 0) - min) / (max - min) * 100 + "%";
36
36
  var defaultTrackColor; // backward compatibility in case no bounds are defined
37
37
 
38
38
  if (props.theme.rangeInput && props.theme.rangeInput.track && !props.theme.rangeInput.track.lower && !props.theme.rangeInput.track.upper) {
@@ -7,8 +7,6 @@ var _react = _interopRequireDefault(require("react"));
7
7
 
8
8
  var _grommet = require("grommet");
9
9
 
10
- var _themes = require("grommet/themes");
11
-
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
11
 
14
12
  var Simple = function Simple() {
@@ -20,15 +18,13 @@ var Simple = function Simple() {
20
18
  return setValue(event.target.value);
21
19
  };
22
20
 
23
- return /*#__PURE__*/_react["default"].createElement(_grommet.Grommet, {
24
- theme: _themes.grommet
25
- }, /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
21
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
26
22
  align: "center",
27
23
  pad: "large"
28
24
  }, /*#__PURE__*/_react["default"].createElement(_grommet.RangeInput, {
29
25
  value: value,
30
26
  onChange: onChange
31
- })));
27
+ }));
32
28
  };
33
29
 
34
30
  exports.Simple = Simple;
@@ -122,14 +122,37 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
122
122
  var formContext = (0, _react.useContext)(_FormContext.FormContext);
123
123
 
124
124
  var _useContext = (0, _react.useContext)(_MessageContext.MessageContext),
125
- format = _useContext.format; // value is used for what we receive in valueProp and the basis for
125
+ format = _useContext.format; // Determine if the Select is opened with the keyboard. If so,
126
+ // focus should be set on the first option when the drop opens
127
+ // see set initial focus code in SelectContainer.js
128
+
129
+
130
+ var _useState = (0, _react.useState)(),
131
+ usingKeyboard = _useState[0],
132
+ setUsingKeyboard = _useState[1];
133
+
134
+ var onMouseDown = function onMouseDown() {
135
+ return setUsingKeyboard(false);
136
+ };
137
+
138
+ var onKeyPress = function onKeyPress() {
139
+ return setUsingKeyboard(true);
140
+ };
141
+
142
+ (0, _react.useEffect)(function () {
143
+ document.addEventListener('mousedown', onMouseDown);
144
+ document.addEventListener('keydown', onKeyPress);
145
+ return function () {
146
+ document.removeEventListener('mousedown', onMouseDown);
147
+ document.removeEventListener('keydown', onKeyPress);
148
+ };
149
+ }, []); // value is used for what we receive in valueProp and the basis for
126
150
  // what we send with onChange
127
151
  // When 'valueKey' sets 'reduce', the value(s) here should match
128
152
  // what the 'valueKey' would return for the corresponding
129
153
  // selected option object.
130
154
  // Otherwise, the value(s) should match the selected options.
131
155
 
132
-
133
156
  var _formContext$useFormI = formContext.useFormInput({
134
157
  name: name,
135
158
  value: valueProp,
@@ -154,14 +177,14 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
154
177
  return valueKey && valueKey.reduce ? value : (0, _utils2.applyKey)(value, valueKey);
155
178
  }, [value, valueKey]); // search input value
156
179
 
157
- var _useState = (0, _react.useState)(),
158
- search = _useState[0],
159
- setSearch = _useState[1]; // All select option indices and values
180
+ var _useState2 = (0, _react.useState)(),
181
+ search = _useState2[0],
182
+ setSearch = _useState2[1]; // All select option indices and values
160
183
 
161
184
 
162
- var _useState2 = (0, _react.useState)(optionsProp),
163
- allOptions = _useState2[0],
164
- setAllOptions = _useState2[1]; // Track changes to options property, except when options are being
185
+ var _useState3 = (0, _react.useState)(optionsProp),
186
+ allOptions = _useState3[0],
187
+ setAllOptions = _useState3[1]; // Track changes to options property, except when options are being
165
188
  // updated due to search activity. Allows option's initial index value
166
189
  // to be referenced when filtered by search.
167
190
 
@@ -192,9 +215,9 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
192
215
  return result;
193
216
  }, [allOptions, selected, valueKey, valuedValue]);
194
217
 
195
- var _useState3 = (0, _react.useState)(propOpen),
196
- open = _useState3[0],
197
- setOpen = _useState3[1];
218
+ var _useState4 = (0, _react.useState)(propOpen),
219
+ open = _useState4[0],
220
+ setOpen = _useState4[1];
198
221
 
199
222
  (0, _react.useEffect)(function () {
200
223
  return setOpen(propOpen);
@@ -321,7 +344,15 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
321
344
  onUp: onRequestOpen
322
345
  }, /*#__PURE__*/_react["default"].createElement(StyledSelectDropButton, {
323
346
  ref: ref,
324
- a11yTitle: ariaLabel || a11yTitle,
347
+ a11yTitle: "" + (ariaLabel || a11yTitle || placeholder || 'Open Drop') + (value ? format({
348
+ id: 'select.selected',
349
+ messages: messages,
350
+ values: {
351
+ currentSelectedValue: value
352
+ }
353
+ }) : ''),
354
+ "aria-expanded": Boolean(open),
355
+ "aria-haspopup": "listbox",
325
356
  id: id,
326
357
  disabled: disabled === true || undefined,
327
358
  dropAlign: dropAlign,
@@ -358,6 +389,7 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
358
389
  search: search,
359
390
  setSearch: setSearch,
360
391
  selected: selected,
392
+ usingKeyboard: usingKeyboard,
361
393
  value: value,
362
394
  valueKey: valueKey
363
395
  }, children) // StyledDropButton needs to know if the border should be shown
@@ -93,6 +93,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
93
93
  search = _ref2.search,
94
94
  setSearch = _ref2.setSearch,
95
95
  selected = _ref2.selected,
96
+ usingKeyboard = _ref2.usingKeyboard,
96
97
  _ref2$value = _ref2.value,
97
98
  value = _ref2$value === void 0 ? '' : _ref2$value,
98
99
  valueKey = _ref2.valueKey,
@@ -114,7 +115,11 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
114
115
  setFocus = _useState3[1];
115
116
 
116
117
  var searchRef = (0, _react.useRef)();
117
- var optionsRef = (0, _react.useRef)(); // adjust activeIndex when options change
118
+ var optionsRef = (0, _react.useRef)();
119
+ (0, _react.useEffect)(function () {
120
+ var optionsNode = optionsRef.current;
121
+ if (optionsNode.children && optionsNode.children[activeIndex]) optionsNode.children[activeIndex].focus();
122
+ }, [activeIndex]); // adjust activeIndex when options change
118
123
 
119
124
  (0, _react.useEffect)(function () {
120
125
  if (activeIndex === -1 && search && optionIndexesInValue.length) {
@@ -133,6 +138,11 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
133
138
  if (searchInput && searchInput.focus) {
134
139
  (0, _utils.setFocusWithoutScroll)(searchInput);
135
140
  }
141
+ } else if (optionsNode && optionsNode.children && usingKeyboard) {
142
+ // if the user is navigating with the keyboard set the
143
+ // first child as the active index when the drop opens
144
+ (0, _utils.setFocusWithoutScroll)(optionsNode.children[0]);
145
+ setActiveIndex(0);
136
146
  } else if (optionsNode) {
137
147
  (0, _utils.setFocusWithoutScroll)(optionsNode);
138
148
  }
@@ -140,7 +150,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
140
150
  return function () {
141
151
  return clearTimeout(timer);
142
152
  };
143
- }, [onSearch]); // clear keyboardNavigation after a while
153
+ }, [onSearch, usingKeyboard]); // clear keyboardNavigation after a while
144
154
 
145
155
  (0, _react.useEffect)(function () {
146
156
  if (keyboardNavigation) {
@@ -348,9 +358,10 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
348
358
  theme: theme,
349
359
  setFocus: setFocus
350
360
  }), /*#__PURE__*/_react["default"].createElement(OptionsBox, {
351
- role: "menubar",
361
+ role: "listbox",
352
362
  tabIndex: "-1",
353
- ref: optionsRef
363
+ ref: optionsRef,
364
+ "aria-multiselectable": multiple
354
365
  }, options.length > 0 ? /*#__PURE__*/_react["default"].createElement(_InfiniteScroll.InfiniteScroll, {
355
366
  items: options,
356
367
  step: theme.select.step,
@@ -383,8 +394,13 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
383
394
  , {
384
395
  key: index,
385
396
  ref: optionRef,
386
- tabIndex: "-1",
387
- role: "menuitem",
397
+ tabIndex: optionSelected ? '0' : '-1',
398
+ role: "option",
399
+ "aria-setsize": options.length,
400
+ "aria-posinset": index + 1,
401
+ "aria-selected": optionSelected,
402
+ focusIndicator: false,
403
+ "aria-disabled": optionDisabled || undefined,
388
404
  plain: !child ? undefined : true,
389
405
  align: "start",
390
406
  kind: !child ? 'option' : undefined,