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
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+ import { Box, DataChart, Text } from 'grommet';
3
+ var data = [];
4
+
5
+ for (var i = 0; i < 7; i += 1) {
6
+ data.push({
7
+ date: "2020-07-" + (i % 31 + 1).toString().padStart(2, 0),
8
+ usage: Math.floor(Math.abs(Math.sin(i / 2.0) * 100)),
9
+ bonus: Math.floor(Math.abs(Math.cos(i / 2.0) * 100))
10
+ });
11
+ }
12
+
13
+ export var StackedLines = function StackedLines() {
14
+ return (
15
+ /*#__PURE__*/
16
+ // Uncomment <Grommet> lines when using outside of storybook
17
+ // <Grommet theme={grommet}>
18
+ React.createElement(Box, {
19
+ align: "center",
20
+ justify: "start",
21
+ pad: "large"
22
+ }, /*#__PURE__*/React.createElement(DataChart, {
23
+ data: data,
24
+ series: [{
25
+ property: 'date',
26
+ render: function render(date) {
27
+ return /*#__PURE__*/React.createElement(Text, {
28
+ margin: {
29
+ horizontal: 'xsmall'
30
+ }
31
+ }, new Date(date).toLocaleDateString('en-US', {
32
+ month: 'numeric',
33
+ day: 'numeric'
34
+ }));
35
+ }
36
+ }, 'usage', 'bonus'],
37
+ chart: [{
38
+ property: ['usage', 'bonus'],
39
+ type: 'lines',
40
+ thickness: 'xsmall',
41
+ round: true
42
+ }],
43
+ axis: {
44
+ x: {
45
+ property: 'date',
46
+ granularity: 'fine'
47
+ },
48
+ y: true
49
+ },
50
+ guide: {
51
+ y: true
52
+ },
53
+ legend: true
54
+ })) // </Grommet>
55
+
56
+ );
57
+ };
58
+ StackedLines.storyName = 'Stacked lines';
59
+ export default {
60
+ title: 'Visualizations/DataChart/Stacked lines'
61
+ };
@@ -1,4 +1,5 @@
1
- var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "value", "messages"];
1
+ var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "icon", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "value", "messages"],
2
+ _excluded2 = ["icon"];
2
3
 
3
4
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
5
 
@@ -30,6 +31,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
30
31
  dropProps = _ref.dropProps,
31
32
  format = _ref.format,
32
33
  id = _ref.id,
34
+ icon = _ref.icon,
33
35
  _ref$inline = _ref.inline,
34
36
  inline = _ref$inline === void 0 ? false : _ref$inline,
35
37
  inputProps = _ref.inputProps,
@@ -91,7 +93,17 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
91
93
 
92
94
  var _useState = useState(schema ? valueToText(normalizedDate, schema) : undefined),
93
95
  textValue = _useState[0],
94
- setTextValue = _useState[1]; // We need to distinguish between the caller changing a Form value
96
+ setTextValue = _useState[1]; // Setting the icon through `inputProps` is deprecated.
97
+ // The `icon` prop should be used instead.
98
+
99
+
100
+ var _ref2 = inputProps || {},
101
+ MaskedInputIcon = _ref2.icon,
102
+ restOfInputProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
103
+
104
+ if (MaskedInputIcon) {
105
+ console.warn("Customizing the DateInput icon through inputProps is deprecated. \nUse the icon prop instead.");
106
+ } // We need to distinguish between the caller changing a Form value
95
107
  // and the user typing a date that he isn't finished with yet.
96
108
  // To handle this, we see if we have a value and the text value
97
109
  // associated with it doesn't align to it, then we update the text value.
@@ -163,8 +175,8 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
163
175
  })));
164
176
  var formContextValue = useMemo(function () {
165
177
  return {
166
- useFormInput: function useFormInput(_ref2) {
167
- var valueProp = _ref2.value;
178
+ useFormInput: function useFormInput(_ref3) {
179
+ var valueProp = _ref3.value;
168
180
  return [valueProp, function () {}];
169
181
  }
170
182
  };
@@ -183,7 +195,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
183
195
  }
184
196
  }, dropProps),
185
197
  dropContent: calendar,
186
- icon: /*#__PURE__*/React.createElement(CalendarIcon, {
198
+ icon: icon || MaskedInputIcon || /*#__PURE__*/React.createElement(CalendarIcon, {
187
199
  size: iconSize
188
200
  })
189
201
  }, buttonProps));
@@ -212,7 +224,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
212
224
  disabled: disabled,
213
225
  mask: mask,
214
226
  plain: true
215
- }, inputProps, rest, {
227
+ }, restOfInputProps, rest, {
216
228
  value: textValue,
217
229
  onChange: function onChange(event) {
218
230
  var nextTextValue = event.target.value;
@@ -240,7 +252,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
240
252
  })), /*#__PURE__*/React.createElement(Button, {
241
253
  onClick: open ? closeCalendar : openCalendar,
242
254
  plain: true,
243
- icon: /*#__PURE__*/React.createElement(CalendarIcon, {
255
+ icon: icon || MaskedInputIcon || /*#__PURE__*/React.createElement(CalendarIcon, {
244
256
  size: iconSize
245
257
  }),
246
258
  margin: {
@@ -267,8 +279,8 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
267
279
  left: 'left'
268
280
  }, dropProps),
269
281
  onEsc: closeCalendar,
270
- onClickOutside: function onClickOutside(_ref3) {
271
- var target = _ref3.target;
282
+ onClickOutside: function onClickOutside(_ref4) {
283
+ var target = _ref4.target;
272
284
 
273
285
  if (target !== containerRef.current && !containerRef.current.contains(target)) {
274
286
  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;
@@ -8,6 +8,7 @@ if (process.env.NODE_ENV !== 'production') {
8
8
  defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
9
9
  dropProps: PropTypes.shape({}),
10
10
  format: PropTypes.string,
11
+ icon: PropTypes.element,
11
12
  id: PropTypes.string,
12
13
  inline: PropTypes.bool,
13
14
  inputProps: PropTypes.shape({}),
@@ -1,4 +1,4 @@
1
- var _excluded = ["action", "as", "background", "border", "children", "data", "defaultItemProps", "focus", "itemProps", "onOrder", "pad", "paginate", "primaryKey", "secondaryKey", "show", "step", "onClickItem", "onMore"];
1
+ var _excluded = ["action", "as", "background", "border", "children", "data", "defaultItemProps", "focus", "itemKey", "itemProps", "onOrder", "pad", "paginate", "primaryKey", "secondaryKey", "show", "step", "onClickItem", "onMore"];
2
2
 
3
3
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
 
@@ -115,6 +115,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
115
115
  data = _ref.data,
116
116
  defaultItemProps = _ref.defaultItemProps,
117
117
  focus = _ref.focus,
118
+ itemKey = _ref.itemKey,
118
119
  itemProps = _ref.itemProps,
119
120
  onOrder = _ref.onOrder,
120
121
  pad = _ref.pad,
@@ -295,7 +296,15 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
295
296
  content = item;
296
297
  }
297
298
 
298
- var key = getKey(item, index, itemId);
299
+ if (itemKey) {
300
+ if (typeof itemKey === 'function') {
301
+ itemId = itemKey(item);
302
+ } else {
303
+ itemId = normalize(item, index, itemKey);
304
+ }
305
+ }
306
+
307
+ var key = itemKey ? itemId : getKey(item, index, itemId);
299
308
 
300
309
  if (action) {
301
310
  content = [/*#__PURE__*/React.createElement(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
  };
@@ -28,6 +28,7 @@ if (process.env.NODE_ENV !== 'production') {
28
28
  data: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({})])),
29
29
  children: PropTypes.func,
30
30
  defaultItemProps: PropTypes.shape(BoxPropTypes),
31
+ itemKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
31
32
  itemProps: PropTypes.shape({}),
32
33
  onMore: PropTypes.func,
33
34
  onClickItem: PropTypes.func,
@@ -71,13 +71,15 @@ var GrommetMarkdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
71
71
  component: TableRow
72
72
  }
73
73
  }, heading, components, options && options.overrides); // we use Fragment as the wrapper so we can assign the ref with the div
74
+ // wrapper can still be overridden with the options.
74
75
 
75
76
  return /*#__PURE__*/React.createElement("div", _extends({
76
77
  ref: ref
77
78
  }, rest), /*#__PURE__*/React.createElement(Markdown, {
78
79
  children: children,
79
- options: _extends({}, options, {
80
- wrapper: Fragment,
80
+ options: _extends({
81
+ wrapper: Fragment
82
+ }, options, {
81
83
  overrides: overrides
82
84
  })
83
85
  }));
@@ -5,7 +5,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
5
5
 
6
6
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
7
 
8
- import React, { forwardRef, useCallback, useContext, useMemo, useState } from 'react';
8
+ import React, { useRef, forwardRef, useCallback, useContext, useMemo, useState, useEffect } from 'react';
9
9
  import styled, { ThemeContext } from 'styled-components';
10
10
  import { defaultProps } from '../../default-props';
11
11
  import { Box } from '../Box';
@@ -19,7 +19,7 @@ import { MenuPropTypes } from './propTypes';
19
19
  var ContainerBox = styled(Box).withConfig({
20
20
  displayName: "Menu__ContainerBox",
21
21
  componentId: "sc-17fcys9-0"
22
- })(["max-height:inherit;@media screen and (-ms-high-contrast:active),(-ms-high-contrast:none){width:100%;}", ";"], function (props) {
22
+ })(["max-height:inherit;@media screen and (-ms-high-contrast:active),(-ms-high-contrast:none){width:100%;}:focus{outline:none;}", ";"], function (props) {
23
23
  return props.theme.menu.extend;
24
24
  });
25
25
  /* Notes on keyboard interactivity (based on W3) // For details reference: https://www.w3.org/TR/wai-aria-practices/#menu
@@ -89,7 +89,8 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
89
89
  setAlignControlMirror = _useState[1];
90
90
 
91
91
  var initialAlignTop = alignControlMirror === align.top;
92
- var buttonRefs = {};
92
+ var dropContainerRef = useRef();
93
+ var buttonRefs = useRef([]);
93
94
  var constants = useMemo(function () {
94
95
  return {
95
96
  none: 'none',
@@ -118,13 +119,28 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
118
119
  var onDropOpen = useCallback(function () {
119
120
  setOpen(true);
120
121
  }, []);
122
+ useEffect(function () {
123
+ // need to wait for Drop to be ready
124
+ var timer = setTimeout(function () {
125
+ if (isOpen) {
126
+ var optionsNode = dropContainerRef.current;
127
+
128
+ if (optionsNode) {
129
+ optionsNode.focus();
130
+ }
131
+ }
132
+ }, 100);
133
+ return function () {
134
+ return clearTimeout(timer);
135
+ };
136
+ }, [isOpen]);
121
137
 
122
138
  var onSelectMenuItem = function onSelectMenuItem(event) {
123
139
  if (isOpen) {
124
140
  if (activeItemIndex >= 0) {
125
141
  event.preventDefault();
126
142
  event.stopPropagation();
127
- buttonRefs[activeItemIndex].click();
143
+ buttonRefs.current[activeItemIndex].click();
128
144
  }
129
145
  } else {
130
146
  onDropOpen();
@@ -159,7 +175,10 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
159
175
  }
160
176
 
161
177
  setActiveItemIndex(index);
162
- buttonRefs[index].focus();
178
+
179
+ if (buttonRefs.current[index]) {
180
+ buttonRefs.current[index].focus();
181
+ }
163
182
  }
164
183
  };
165
184
 
@@ -175,7 +194,9 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
175
194
  } else {
176
195
  var index;
177
196
 
178
- if (activeItemIndex - 1 < 0) {
197
+ if (activeItemIndex === 'none') {
198
+ index = items.length - 1;
199
+ } else if (activeItemIndex - 1 < 0) {
179
200
  if (constants.controlTop && activeItemIndex - 1 === controlButtonIndex) {
180
201
  index = items.length;
181
202
  } else {
@@ -186,7 +207,10 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
186
207
  }
187
208
 
188
209
  setActiveItemIndex(index);
189
- buttonRefs[index].focus();
210
+
211
+ if (buttonRefs.current[index]) {
212
+ buttonRefs.current[index].focus();
213
+ }
190
214
  }
191
215
  };
192
216
 
@@ -230,7 +254,7 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
230
254
  }, /*#__PURE__*/React.createElement(Button, _extends({
231
255
  ref: function ref(r) {
232
256
  // make it accessible at the end of all menu items
233
- buttonRefs[items.length] = r;
257
+ buttonRefs.current[items.length] = r;
234
258
  },
235
259
  a11yTitle: ariaLabel || a11yTitle || format({
236
260
  id: 'menu.closeMenu',
@@ -253,9 +277,8 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
253
277
  }));
254
278
  } : content));
255
279
  return /*#__PURE__*/React.createElement(Keyboard, {
256
- onDown: onNextMenuItem,
257
- onUp: onPreviousMenuItem,
258
- onEnter: onSelectMenuItem,
280
+ onDown: onDropOpen,
281
+ onUp: onDropOpen,
259
282
  onSpace: onSelectMenuItem,
260
283
  onEsc: onDropClose,
261
284
  onTab: onDropClose,
@@ -279,8 +302,12 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
279
302
  onTab: function onTab(event) {
280
303
  return event.shiftKey ? onPreviousMenuItem(event) : onNextMenuItem(event);
281
304
  },
305
+ onDown: onNextMenuItem,
306
+ onUp: onPreviousMenuItem,
282
307
  onEnter: onSelectMenuItem
283
308
  }, /*#__PURE__*/React.createElement(ContainerBox, {
309
+ ref: dropContainerRef,
310
+ tabIndex: -1,
284
311
  background: dropBackground || theme.menu.background
285
312
  }, alignControlMirror === 'top' && align.top === 'top' ? controlMirror : undefined, /*#__PURE__*/React.createElement(Box, {
286
313
  overflow: "auto"
@@ -303,10 +330,10 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
303
330
  flex: false
304
331
  }, /*#__PURE__*/React.createElement(Button, _extends({
305
332
  ref: function ref(r) {
306
- buttonRefs[index] = r;
333
+ buttonRefs.current[index] = r;
307
334
  },
308
335
  onFocus: function onFocus() {
309
- return setActiveItemIndex(index);
336
+ setActiveItemIndex(index);
310
337
  },
311
338
  active: activeItemIndex === index,
312
339
  focusIndicator: false,
@@ -1,6 +1,6 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
- import React, { useCallback, useContext, useEffect, useState } from 'react';
3
+ import React, { useCallback, useContext, useEffect, useState, useMemo } from 'react';
4
4
  import { ThemeContext } from 'styled-components';
5
5
  import { defaultProps } from '../../default-props';
6
6
  import { Box } from '../Box';
@@ -13,25 +13,34 @@ import { NotificationType } from './propTypes';
13
13
  var Notification = function Notification(_ref) {
14
14
  var message = _ref.message,
15
15
  onClose = _ref.onClose,
16
+ id = _ref.id,
16
17
  status = _ref.status,
17
18
  title = _ref.title,
18
19
  toast = _ref.toast;
20
+ var autoClose = (toast == null ? void 0 : toast.autoClose) === undefined ? true : toast.autoClose;
19
21
  var theme = useContext(ThemeContext) || defaultProps.theme;
20
22
 
21
23
  var _useState = useState(true),
22
24
  visible = _useState[0],
23
25
  setVisible = _useState[1];
24
26
 
27
+ var position = useMemo(function () {
28
+ return toast && (toast == null ? void 0 : toast.position) || 'top';
29
+ }, [toast]);
25
30
  var close = useCallback(function () {
26
31
  setVisible(false);
27
32
  if (onClose) onClose();
28
33
  }, [onClose]);
29
34
  useEffect(function () {
30
- var timer = setTimeout(close, theme.notification.toast.time || theme.notification.time);
31
- return function () {
32
- return clearTimeout(timer);
33
- };
34
- }, [close, theme.notification.toast.time, theme.notification.time]);
35
+ if (autoClose) {
36
+ var timer = setTimeout(close, theme.notification.toast.time || theme.notification.time);
37
+ return function () {
38
+ return clearTimeout(timer);
39
+ };
40
+ }
41
+
42
+ return undefined;
43
+ }, [autoClose, close, theme.notification.toast.time, theme.notification.time]);
35
44
  var CloseIcon = theme.notification.close.icon;
36
45
  var _theme$notification$s = theme.notification[status],
37
46
  StatusIcon = _theme$notification$s.icon,
@@ -59,8 +68,10 @@ var Notification = function Notification(_ref) {
59
68
  role: "log",
60
69
  modal: false,
61
70
  onEsc: onClose,
71
+ id: id,
62
72
  responsive: true,
63
- plain: true
73
+ plain: true,
74
+ position: position
64
75
  }), content);
65
76
  }
66
77
 
@@ -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
 
@@ -6,7 +6,10 @@ if (process.env.NODE_ENV !== 'production') {
6
6
  title: PropTypes.string.isRequired,
7
7
  message: PropTypes.string,
8
8
  status: PropTypes.oneOf(['critical', 'warning', 'normal', 'unknown']),
9
- toast: PropTypes.bool,
9
+ toast: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
10
+ autoClose: PropTypes.bool,
11
+ position: PropTypes.oneOf(['bottom', 'bottom-left', 'bottom-right', 'center', 'end', 'hidden', 'left', 'right', 'start', 'top', 'top-left', 'top-right'])
12
+ })]),
10
13
  onClose: PropTypes.func
11
14
  };
12
15
  }
@@ -20,7 +20,7 @@ var trackColorStyle = function trackColorStyle(props) {
20
20
 
21
21
  var max = props.max,
22
22
  min = props.min;
23
- var thumbPosition = (props.value - min) / (max - min) * 100 + "%";
23
+ var thumbPosition = ((props.value || 0) - min) / (max - min) * 100 + "%";
24
24
  var defaultTrackColor; // backward compatibility in case no bounds are defined
25
25
 
26
26
  if (props.theme.rangeInput && props.theme.rangeInput.track && !props.theme.rangeInput.track.lower && !props.theme.rangeInput.track.upper) {
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { Box, Grommet, RangeInput } from 'grommet';
3
- import { grommet } from 'grommet/themes';
2
+ import { Box, RangeInput } from 'grommet';
4
3
  export var Simple = function Simple() {
5
4
  var _React$useState = React.useState(5),
6
5
  value = _React$useState[0],
@@ -10,15 +9,13 @@ export var Simple = function Simple() {
10
9
  return setValue(event.target.value);
11
10
  };
12
11
 
13
- return /*#__PURE__*/React.createElement(Grommet, {
14
- theme: grommet
15
- }, /*#__PURE__*/React.createElement(Box, {
12
+ return /*#__PURE__*/React.createElement(Box, {
16
13
  align: "center",
17
14
  pad: "large"
18
15
  }, /*#__PURE__*/React.createElement(RangeInput, {
19
16
  value: value,
20
17
  onChange: onChange
21
- })));
18
+ }));
22
19
  };
23
20
  export default {
24
21
  title: 'Input/RangeInput/Simple'
@@ -97,14 +97,37 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
97
97
  var formContext = useContext(FormContext);
98
98
 
99
99
  var _useContext = useContext(MessageContext),
100
- format = _useContext.format; // value is used for what we receive in valueProp and the basis for
100
+ format = _useContext.format; // Determine if the Select is opened with the keyboard. If so,
101
+ // focus should be set on the first option when the drop opens
102
+ // see set initial focus code in SelectContainer.js
103
+
104
+
105
+ var _useState = useState(),
106
+ usingKeyboard = _useState[0],
107
+ setUsingKeyboard = _useState[1];
108
+
109
+ var onMouseDown = function onMouseDown() {
110
+ return setUsingKeyboard(false);
111
+ };
112
+
113
+ var onKeyPress = function onKeyPress() {
114
+ return setUsingKeyboard(true);
115
+ };
116
+
117
+ useEffect(function () {
118
+ document.addEventListener('mousedown', onMouseDown);
119
+ document.addEventListener('keydown', onKeyPress);
120
+ return function () {
121
+ document.removeEventListener('mousedown', onMouseDown);
122
+ document.removeEventListener('keydown', onKeyPress);
123
+ };
124
+ }, []); // value is used for what we receive in valueProp and the basis for
101
125
  // what we send with onChange
102
126
  // When 'valueKey' sets 'reduce', the value(s) here should match
103
127
  // what the 'valueKey' would return for the corresponding
104
128
  // selected option object.
105
129
  // Otherwise, the value(s) should match the selected options.
106
130
 
107
-
108
131
  var _formContext$useFormI = formContext.useFormInput({
109
132
  name: name,
110
133
  value: valueProp,
@@ -129,14 +152,14 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
129
152
  return valueKey && valueKey.reduce ? value : applyKey(value, valueKey);
130
153
  }, [value, valueKey]); // search input value
131
154
 
132
- var _useState = useState(),
133
- search = _useState[0],
134
- setSearch = _useState[1]; // All select option indices and values
155
+ var _useState2 = useState(),
156
+ search = _useState2[0],
157
+ setSearch = _useState2[1]; // All select option indices and values
135
158
 
136
159
 
137
- var _useState2 = useState(optionsProp),
138
- allOptions = _useState2[0],
139
- setAllOptions = _useState2[1]; // Track changes to options property, except when options are being
160
+ var _useState3 = useState(optionsProp),
161
+ allOptions = _useState3[0],
162
+ setAllOptions = _useState3[1]; // Track changes to options property, except when options are being
140
163
  // updated due to search activity. Allows option's initial index value
141
164
  // to be referenced when filtered by search.
142
165
 
@@ -167,9 +190,9 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
167
190
  return result;
168
191
  }, [allOptions, selected, valueKey, valuedValue]);
169
192
 
170
- var _useState3 = useState(propOpen),
171
- open = _useState3[0],
172
- setOpen = _useState3[1];
193
+ var _useState4 = useState(propOpen),
194
+ open = _useState4[0],
195
+ setOpen = _useState4[1];
173
196
 
174
197
  useEffect(function () {
175
198
  return setOpen(propOpen);
@@ -296,7 +319,15 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
296
319
  onUp: onRequestOpen
297
320
  }, /*#__PURE__*/React.createElement(StyledSelectDropButton, {
298
321
  ref: ref,
299
- a11yTitle: ariaLabel || a11yTitle,
322
+ a11yTitle: "" + (ariaLabel || a11yTitle || placeholder || 'Open Drop') + (value ? format({
323
+ id: 'select.selected',
324
+ messages: messages,
325
+ values: {
326
+ currentSelectedValue: value
327
+ }
328
+ }) : ''),
329
+ "aria-expanded": Boolean(open),
330
+ "aria-haspopup": "listbox",
300
331
  id: id,
301
332
  disabled: disabled === true || undefined,
302
333
  dropAlign: dropAlign,
@@ -333,6 +364,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
333
364
  search: search,
334
365
  setSearch: setSearch,
335
366
  selected: selected,
367
+ usingKeyboard: usingKeyboard,
336
368
  value: value,
337
369
  valueKey: valueKey
338
370
  }, children) // StyledDropButton needs to know if the border should be shown
@@ -71,6 +71,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
71
71
  search = _ref2.search,
72
72
  setSearch = _ref2.setSearch,
73
73
  selected = _ref2.selected,
74
+ usingKeyboard = _ref2.usingKeyboard,
74
75
  _ref2$value = _ref2.value,
75
76
  value = _ref2$value === void 0 ? '' : _ref2$value,
76
77
  valueKey = _ref2.valueKey,
@@ -91,7 +92,11 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
91
92
  setFocus = _useState3[1];
92
93
 
93
94
  var searchRef = useRef();
94
- var optionsRef = useRef(); // adjust activeIndex when options change
95
+ var optionsRef = useRef();
96
+ useEffect(function () {
97
+ var optionsNode = optionsRef.current;
98
+ if (optionsNode.children && optionsNode.children[activeIndex]) optionsNode.children[activeIndex].focus();
99
+ }, [activeIndex]); // adjust activeIndex when options change
95
100
 
96
101
  useEffect(function () {
97
102
  if (activeIndex === -1 && search && optionIndexesInValue.length) {
@@ -110,6 +115,11 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
110
115
  if (searchInput && searchInput.focus) {
111
116
  setFocusWithoutScroll(searchInput);
112
117
  }
118
+ } else if (optionsNode && optionsNode.children && usingKeyboard) {
119
+ // if the user is navigating with the keyboard set the
120
+ // first child as the active index when the drop opens
121
+ setFocusWithoutScroll(optionsNode.children[0]);
122
+ setActiveIndex(0);
113
123
  } else if (optionsNode) {
114
124
  setFocusWithoutScroll(optionsNode);
115
125
  }
@@ -117,7 +127,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
117
127
  return function () {
118
128
  return clearTimeout(timer);
119
129
  };
120
- }, [onSearch]); // clear keyboardNavigation after a while
130
+ }, [onSearch, usingKeyboard]); // clear keyboardNavigation after a while
121
131
 
122
132
  useEffect(function () {
123
133
  if (keyboardNavigation) {
@@ -325,9 +335,10 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
325
335
  theme: theme,
326
336
  setFocus: setFocus
327
337
  }), /*#__PURE__*/React.createElement(OptionsBox, {
328
- role: "menubar",
338
+ role: "listbox",
329
339
  tabIndex: "-1",
330
- ref: optionsRef
340
+ ref: optionsRef,
341
+ "aria-multiselectable": multiple
331
342
  }, options.length > 0 ? /*#__PURE__*/React.createElement(InfiniteScroll, {
332
343
  items: options,
333
344
  step: theme.select.step,
@@ -360,8 +371,13 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
360
371
  , {
361
372
  key: index,
362
373
  ref: optionRef,
363
- tabIndex: "-1",
364
- role: "menuitem",
374
+ tabIndex: optionSelected ? '0' : '-1',
375
+ role: "option",
376
+ "aria-setsize": options.length,
377
+ "aria-posinset": index + 1,
378
+ "aria-selected": optionSelected,
379
+ focusIndicator: false,
380
+ "aria-disabled": optionDisabled || undefined,
365
381
  plain: !child ? undefined : true,
366
382
  align: "start",
367
383
  kind: !child ? 'option' : undefined,