grommet 2.40.2 → 2.42.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 (139) hide show
  1. package/components/AccordionPanel/AccordionPanel.js +1 -7
  2. package/components/Box/Box.js +1 -1
  3. package/components/Box/StyledBox.js +1 -6
  4. package/components/Box/index.d.ts +1 -0
  5. package/components/Box/propTypes.js +1 -0
  6. package/components/Button/Button.js +1 -0
  7. package/components/Button/StyledButton.js +3 -2
  8. package/components/Button/StyledButtonKind.js +12 -6
  9. package/components/Calendar/Calendar.js +90 -56
  10. package/components/Calendar/StyledCalendar.js +89 -7
  11. package/components/Calendar/utils.js +16 -2
  12. package/components/Carousel/Carousel.js +1 -1
  13. package/components/Chart/Chart.js +3 -3
  14. package/components/CheckBox/CheckBox.js +3 -2
  15. package/components/CheckBoxGroup/CheckBoxGroup.js +1 -1
  16. package/components/Clock/Digital.js +1 -1
  17. package/components/Data/stories/Infinite.js +2 -2
  18. package/components/Data/stories/OnSelect.js +2 -2
  19. package/components/Data/stories/SpaceX.js +2 -2
  20. package/components/Data/stories/StarWars.js +1 -1
  21. package/components/DataChart/Detail.js +19 -4
  22. package/components/DataFilter/DataFilter.js +6 -1
  23. package/components/DataSort/DataSort.js +46 -14
  24. package/components/DataSort/stories/Simple.js +10 -1
  25. package/components/DataTable/Body.js +14 -8
  26. package/components/DataTable/GroupedBody.js +3 -3
  27. package/components/DataTable/buildState.js +5 -1
  28. package/components/DataTable/stories/SpaceX.js +2 -2
  29. package/components/DataTable/stories/SpaceXUngrouped.js +1 -1
  30. package/components/Drop/DropContainer.js +51 -3
  31. package/components/FileInput/index.d.ts +2 -3
  32. package/components/FocusedContainer.js +134 -17
  33. package/components/Grommet/Grommet.js +11 -5
  34. package/components/Layer/Layer.js +1 -1
  35. package/components/Layer/index.d.ts +2 -0
  36. package/components/List/List.js +18 -12
  37. package/components/MaskedInput/MaskedInput.js +3 -0
  38. package/components/Menu/Menu.js +3 -3
  39. package/components/Meter/Circle.js +2 -2
  40. package/components/Notification/Notification.js +18 -6
  41. package/components/Notification/index.d.ts +1 -0
  42. package/components/Notification/propTypes.js +1 -0
  43. package/components/Pagination/Pagination.js +4 -2
  44. package/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
  45. package/components/Select/Select.js +29 -18
  46. package/components/Select/SelectContainer.js +41 -34
  47. package/components/Select/index.d.ts +1 -1
  48. package/components/Select/stories/ChildrenRender.js +7 -8
  49. package/components/Select/utils.js +13 -2
  50. package/components/SelectMultiple/SelectMultiple.js +18 -6
  51. package/components/SelectMultiple/SelectMultipleContainer.js +28 -2
  52. package/components/SelectMultiple/SelectMultipleValue.js +14 -1
  53. package/components/SkipLinks/index.d.ts +1 -0
  54. package/components/SkipLinks/propTypes.js +1 -0
  55. package/components/Tab/Tab.js +1 -1
  56. package/components/Tag/Tag.js +11 -7
  57. package/components/TextInput/TextInput.js +3 -0
  58. package/components/ToggleGroup/StyledToggleGroup.js +12 -5
  59. package/components/ToggleGroup/ToggleGroup.js +21 -10
  60. package/components/WorldMap/WorldMap.js +1 -1
  61. package/contexts/RootsContext.js +23 -5
  62. package/es6/components/AccordionPanel/AccordionPanel.js +2 -9
  63. package/es6/components/Box/Box.js +1 -1
  64. package/es6/components/Box/StyledBox.js +1 -6
  65. package/es6/components/Box/index.d.ts +1 -0
  66. package/es6/components/Box/propTypes.js +1 -0
  67. package/es6/components/Button/Button.js +1 -0
  68. package/es6/components/Button/StyledButton.js +4 -3
  69. package/es6/components/Button/StyledButtonKind.js +12 -6
  70. package/es6/components/Calendar/Calendar.js +89 -56
  71. package/es6/components/Calendar/StyledCalendar.js +90 -8
  72. package/es6/components/Calendar/utils.js +15 -1
  73. package/es6/components/Carousel/Carousel.js +1 -1
  74. package/es6/components/Chart/Chart.js +3 -3
  75. package/es6/components/CheckBox/CheckBox.js +3 -2
  76. package/es6/components/CheckBoxGroup/CheckBoxGroup.js +1 -1
  77. package/es6/components/Clock/Digital.js +1 -1
  78. package/es6/components/Data/stories/Infinite.js +2 -2
  79. package/es6/components/Data/stories/OnSelect.js +2 -2
  80. package/es6/components/Data/stories/SpaceX.js +2 -2
  81. package/es6/components/Data/stories/StarWars.js +1 -1
  82. package/es6/components/DataChart/Detail.js +20 -5
  83. package/es6/components/DataFilter/DataFilter.js +6 -1
  84. package/es6/components/DataSort/DataSort.js +46 -14
  85. package/es6/components/DataSort/stories/Simple.js +10 -1
  86. package/es6/components/DataTable/Body.js +14 -8
  87. package/es6/components/DataTable/GroupedBody.js +3 -3
  88. package/es6/components/DataTable/buildState.js +5 -1
  89. package/es6/components/DataTable/stories/SpaceX.js +2 -2
  90. package/es6/components/DataTable/stories/SpaceXUngrouped.js +1 -1
  91. package/es6/components/Drop/DropContainer.js +51 -3
  92. package/es6/components/FileInput/index.d.ts +2 -3
  93. package/es6/components/FocusedContainer.js +136 -19
  94. package/es6/components/Grommet/Grommet.js +12 -6
  95. package/es6/components/Layer/Layer.js +1 -1
  96. package/es6/components/Layer/index.d.ts +2 -0
  97. package/es6/components/List/List.js +18 -12
  98. package/es6/components/MaskedInput/MaskedInput.js +3 -0
  99. package/es6/components/Menu/Menu.js +3 -3
  100. package/es6/components/Meter/Circle.js +2 -2
  101. package/es6/components/Notification/Notification.js +18 -6
  102. package/es6/components/Notification/index.d.ts +1 -0
  103. package/es6/components/Notification/propTypes.js +1 -0
  104. package/es6/components/Pagination/Pagination.js +4 -2
  105. package/es6/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
  106. package/es6/components/Select/Select.js +30 -19
  107. package/es6/components/Select/SelectContainer.js +41 -34
  108. package/es6/components/Select/index.d.ts +1 -1
  109. package/es6/components/Select/stories/ChildrenRender.js +7 -8
  110. package/es6/components/Select/utils.js +15 -3
  111. package/es6/components/SelectMultiple/SelectMultiple.js +18 -6
  112. package/es6/components/SelectMultiple/SelectMultipleContainer.js +28 -2
  113. package/es6/components/SelectMultiple/SelectMultipleValue.js +14 -1
  114. package/es6/components/SkipLinks/index.d.ts +1 -0
  115. package/es6/components/SkipLinks/propTypes.js +1 -0
  116. package/es6/components/Tab/Tab.js +1 -1
  117. package/es6/components/Tag/Tag.js +11 -7
  118. package/es6/components/TextInput/TextInput.js +3 -0
  119. package/es6/components/ToggleGroup/StyledToggleGroup.js +12 -5
  120. package/es6/components/ToggleGroup/ToggleGroup.js +22 -11
  121. package/es6/components/WorldMap/WorldMap.js +1 -1
  122. package/es6/contexts/RootsContext.js +20 -3
  123. package/es6/themes/base.d.ts +205 -6
  124. package/es6/themes/base.js +166 -1
  125. package/es6/utils/DOM.js +2 -1
  126. package/es6/utils/background.js +1 -1
  127. package/es6/utils/index.js +2 -1
  128. package/es6/utils/styles.js +8 -0
  129. package/es6/utils/useId.js +16 -0
  130. package/grommet.min.js +1 -1
  131. package/grommet.min.js.map +1 -1
  132. package/package.json +40 -40
  133. package/themes/base.d.ts +205 -6
  134. package/themes/base.js +166 -1
  135. package/utils/DOM.js +2 -1
  136. package/utils/background.js +1 -1
  137. package/utils/index.js +6 -0
  138. package/utils/styles.js +9 -1
  139. package/utils/useId.js +19 -0
@@ -1,6 +1,7 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
2
+ import React, { Fragment, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import styled from 'styled-components';
4
+ import { AnnounceContext } from '../../contexts';
4
5
  import { Box } from '../Box';
5
6
  import { Drop } from '../Drop';
6
7
  import { Grid } from '../Grid';
@@ -23,6 +24,7 @@ var Detail = function Detail(_ref) {
23
24
  seriesStyles = _ref.seriesStyles,
24
25
  renderValue = _ref.renderValue,
25
26
  thickness = _ref.thickness;
27
+ var announce = useContext(AnnounceContext);
26
28
  var _useThemeValue = useThemeValue(),
27
29
  theme = _useThemeValue.theme;
28
30
  var _useState = useState(),
@@ -71,6 +73,19 @@ var Detail = function Detail(_ref) {
71
73
  };
72
74
  return res;
73
75
  }, [data.length, detailIndex, horizontalProp]);
76
+ useEffect(function () {
77
+ if (detailIndex !== undefined) {
78
+ var content = series.filter(function (_ref2) {
79
+ var _data$detailIndex;
80
+ var property = _ref2.property;
81
+ return (!activeProperty || activeProperty === property) && (data == null || (_data$detailIndex = data[detailIndex]) == null ? void 0 : _data$detailIndex[property]) !== undefined || axis && axis.x && axis.x.property === property;
82
+ }).map(function (serie) {
83
+ var axisValue = horizontalProp ? data[detailIndex][serie.property] : detailIndex;
84
+ return (serie.label || serie.property) + " " + renderValue(serie, axisValue);
85
+ }).join(' ');
86
+ announce(content);
87
+ }
88
+ }, [activeProperty, announce, axis, data, detailIndex, horizontalProp, renderValue, series]);
74
89
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Keyboard, {
75
90
  onLeft: function onLeft() {
76
91
  if (detailIndex === undefined) setDetailIndex(data.length - 1);else if (detailIndex > 0) setDetailIndex(detailIndex - 1);
@@ -147,10 +162,10 @@ var Detail = function Detail(_ref) {
147
162
  columns: ['auto', 'auto', 'auto'],
148
163
  gap: "xsmall",
149
164
  align: "center"
150
- }, series.filter(function (_ref2) {
151
- var _data$detailIndex;
152
- var property = _ref2.property;
153
- return (!activeProperty || activeProperty === property) && (data == null || (_data$detailIndex = data[detailIndex]) == null ? void 0 : _data$detailIndex[property]) !== undefined || axis && axis.x && axis.x.property === property;
165
+ }, series.filter(function (_ref3) {
166
+ var _data$detailIndex2;
167
+ var property = _ref3.property;
168
+ return (!activeProperty || activeProperty === property) && (data == null || (_data$detailIndex2 = data[detailIndex]) == null ? void 0 : _data$detailIndex2[property]) !== undefined || axis && axis.x && axis.x.property === property;
154
169
  }).map(function (serie) {
155
170
  var propertyStyle = seriesStyles[serie.property];
156
171
  var axisValue = horizontalProp ? data[detailIndex][serie.property] : detailIndex;
@@ -135,7 +135,7 @@ export var DataFilter = function DataFilter(_ref) {
135
135
  var _properties$property4;
136
136
  var step =
137
137
  // from `range` on DataFilter
138
- (rangeProp == null ? void 0 : rangeProp.step) || ( // from range in Data `properties`
138
+ (rangeProp == null ? void 0 : rangeProp.step) || (// from range in Data `properties`
139
139
  properties == null || (_properties$property4 = properties[property]) == null || (_properties$property4 = _properties$property4.range) == null ? void 0 : _properties$property4.step);
140
140
  if (!step) {
141
141
  // avoid floating point issues where 4.4 - 2 returns 2.4000000000000004
@@ -193,6 +193,11 @@ export var DataFilter = function DataFilter(_ref) {
193
193
  onSearch: options.length >= minSelectSearchOptions ? setSearchText : undefined,
194
194
  onClose: function onClose() {
195
195
  return setSearchText('');
196
+ },
197
+ labelKey: "label",
198
+ valueKey: {
199
+ key: 'value',
200
+ reduce: true
196
201
  }
197
202
  });
198
203
  }
@@ -1,6 +1,6 @@
1
1
  var _excluded = ["drop", "options"];
2
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
2
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
3
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
4
4
  import React, { useContext, useMemo, useState } from 'react';
5
5
  import { Descend } from 'grommet-icons/icons/Descend';
6
6
  import { DataContext } from '../../contexts/DataContext';
@@ -29,11 +29,44 @@ var Content = function Content(_ref) {
29
29
  properties = _useContext.properties;
30
30
  var _useContext2 = useContext(MessageContext),
31
31
  format = _useContext2.format;
32
- var options = useMemo(function () {
33
- return optionsArg || properties && Object.keys(properties).sort().filter(function (property) {
34
- var _properties$property;
35
- return !((properties == null || (_properties$property = properties[property]) == null ? void 0 : _properties$property.sort) === false);
36
- }) || data.length > 0 && Object.keys(data[0]).sort() || data;
32
+ var selectProps = useMemo(function () {
33
+ var props = {};
34
+ if (optionsArg) {
35
+ props = {
36
+ options: optionsArg
37
+ };
38
+ }
39
+ if (properties && Array.isArray(properties)) {
40
+ props = {
41
+ options: properties
42
+ };
43
+ } else if (properties && typeof properties === 'object') {
44
+ props = {
45
+ options: Object.entries(properties).filter(function (_ref2) {
46
+ var sort = _ref2[1].sort;
47
+ return !(sort === false);
48
+ }).map(function (_ref3) {
49
+ var key = _ref3[0],
50
+ label = _ref3[1].label;
51
+ return {
52
+ key: key,
53
+ label: label || key
54
+ };
55
+ }).sort(function (a, b) {
56
+ return a.label.localeCompare(b.label);
57
+ }),
58
+ valueKey: {
59
+ key: 'key',
60
+ reduce: true
61
+ },
62
+ labelKey: 'label'
63
+ };
64
+ } else {
65
+ props = {
66
+ options: data.length > 0 && Object.keys(data[0]).sort() || data
67
+ };
68
+ }
69
+ return props;
37
70
  }, [data, optionsArg, properties]);
38
71
  var directionOptions = [{
39
72
  label: format({
@@ -57,11 +90,10 @@ var Content = function Content(_ref) {
57
90
  id: 'dataSort.by',
58
91
  messages: messages == null ? void 0 : messages.dataSort
59
92
  })
60
- }, /*#__PURE__*/React.createElement(Select, {
93
+ }, /*#__PURE__*/React.createElement(Select, _extends({
61
94
  id: sortPropertyId,
62
- name: "_sort.property",
63
- options: options
64
- })), /*#__PURE__*/React.createElement(FormField, {
95
+ name: "_sort.property"
96
+ }, selectProps))), /*#__PURE__*/React.createElement(FormField, {
65
97
  key: "dir",
66
98
  htmlFor: sortDirectionId,
67
99
  label: format({
@@ -74,11 +106,11 @@ var Content = function Content(_ref) {
74
106
  options: directionOptions
75
107
  }))];
76
108
  };
77
- export var DataSort = function DataSort(_ref2) {
109
+ export var DataSort = function DataSort(_ref4) {
78
110
  var _theme$data$button;
79
- var drop = _ref2.drop,
80
- options = _ref2.options,
81
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
111
+ var drop = _ref4.drop,
112
+ options = _ref4.options,
113
+ rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
82
114
  var _useContext3 = useContext(DataContext),
83
115
  dataId = _useContext3.id,
84
116
  messages = _useContext3.messages;
@@ -1,6 +1,14 @@
1
1
  import React from 'react';
2
2
  import { Box, Data, DataSort, DataTable } from 'grommet';
3
3
  import { columns, DATA } from '../../DataTable/stories/data';
4
+ var properties = {};
5
+ columns.forEach(function (_ref) {
6
+ var property = _ref.property,
7
+ header = _ref.header;
8
+ properties[property] = {
9
+ label: typeof header === 'string' ? header : property
10
+ };
11
+ });
4
12
  export var Simple = function Simple() {
5
13
  return (
6
14
  /*#__PURE__*/
@@ -12,7 +20,8 @@ export var Simple = function Simple() {
12
20
  pad: "large",
13
21
  gap: "medium"
14
22
  }, /*#__PURE__*/React.createElement(Data, {
15
- data: DATA
23
+ data: DATA,
24
+ properties: properties
16
25
  }, /*#__PURE__*/React.createElement(DataSort, null), /*#__PURE__*/React.createElement(DataTable, {
17
26
  columns: columns
18
27
  })))
@@ -67,7 +67,7 @@ var Row = /*#__PURE__*/memo(function (_ref) {
67
67
  return setActive(undefined);
68
68
  } : undefined
69
69
  }, (selected || onSelect) && /*#__PURE__*/React.createElement(Cell, {
70
- background: (pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect) && cellProps.pinned.background || cellProps.background,
70
+ background: isSelected && cellProps.selected.background || (pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect) && cellProps.pinned.background || cellProps.background,
71
71
  border: cellProps.pinned.border || cellProps.border,
72
72
  pinnedOffset: pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect,
73
73
  "aria-disabled": isDisabled || !onSelect || undefined,
@@ -94,6 +94,7 @@ var Row = /*#__PURE__*/memo(function (_ref) {
94
94
  },
95
95
  verticalAlign: verticalAlign
96
96
  }), rowDetails && /*#__PURE__*/React.createElement(ExpanderCell, {
97
+ background: isSelected && cellProps.selected.background,
97
98
  context: isRowExpanded ? 'groupHeader' : 'body',
98
99
  expanded: isRowExpanded,
99
100
  onToggle: function onToggle() {
@@ -110,11 +111,12 @@ var Row = /*#__PURE__*/memo(function (_ref) {
110
111
  }), columns.map(function (column) {
111
112
  return /*#__PURE__*/React.createElement(Cell, {
112
113
  key: column.property,
113
- background: column.pin && cellProps.pinned.background || cellProps.background,
114
+ background: isSelected && cellProps.selected.background || column.pin && cellProps.pinned.background || cellProps.background,
114
115
  border: column.pin && cellProps.pinned.border || cellProps.border,
115
116
  context: "body",
116
117
  column: column,
117
118
  datum: datum,
119
+ isSelected: isSelected,
118
120
  pad: column.pin && cellProps.pinned.pad || cellProps.pad,
119
121
  pinnedOffset: pinnedOffset && pinnedOffset[column.property],
120
122
  primaryProperty: primaryProperty,
@@ -188,13 +190,17 @@ var Body = /*#__PURE__*/forwardRef(function (_ref2, ref) {
188
190
  } : undefined
189
191
  // The WCAG recommendation for checkboxes is to select them with "Space"
190
192
  ,
191
- onSpace: function onSpace() {
192
- if (clickableRow) {
193
- if (onClickRow === 'select') {
194
- selectRow();
195
- }
193
+ onSpace: clickableRow ? function (event) {
194
+ event.preventDefault();
195
+ if (typeof onClickRow === 'function') {
196
+ event.persist();
197
+ var adjustedEvent = event;
198
+ adjustedEvent.datum = data == null ? void 0 : data[active];
199
+ onClickRow(adjustedEvent);
200
+ } else if (onClickRow === 'select') {
201
+ selectRow();
196
202
  }
197
- },
203
+ } : undefined,
198
204
  onUp: onClickRow && active ? function () {
199
205
  return setActive(active - 1);
200
206
  } : undefined,
@@ -133,7 +133,7 @@ export var GroupedBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
133
133
  key: key,
134
134
  size: size
135
135
  }, /*#__PURE__*/React.createElement(ExpanderCell, {
136
- background: cellProps.background,
136
+ background: isSelected && cellProps.selected.background || cellProps.background,
137
137
  border: cellProps.border,
138
138
  context: context,
139
139
  pad: cellProps.pad,
@@ -141,7 +141,7 @@ export var GroupedBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
141
141
  expanded: expanded,
142
142
  verticalAlign: verticalAlign
143
143
  }), (selected || onSelect) && /*#__PURE__*/React.createElement(TableCell, {
144
- background: cellProps.background,
144
+ background: isSelected && cellProps.selected.background || cellProps.background,
145
145
  border: cellProps.pinned.border || cellProps.border,
146
146
  plain: "noPad",
147
147
  size: "auto",
@@ -163,7 +163,7 @@ export var GroupedBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
163
163
  }
164
164
  return /*#__PURE__*/React.createElement(Cell, {
165
165
  key: column.property,
166
- background: cellProps.background,
166
+ background: isSelected && cellProps.selected.background || cellProps.background,
167
167
  border: cellProps.border,
168
168
  context: context,
169
169
  column: column,
@@ -1,3 +1,4 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
1
2
  // This file contains helper functions for DataTable, to keep the component
2
3
  // files simpler.
3
4
 
@@ -262,6 +263,7 @@ var cellPropertyNames = ['background', 'border', 'pad'];
262
263
  // For example, background={{ header: { background } }}
263
264
  // will become cellProps.header.background
264
265
  export var normalizeCellProps = function normalizeCellProps(props, theme) {
266
+ var _theme$dataTable3;
265
267
  var result = {};
266
268
  tableContextNames.forEach(function (context) {
267
269
  result[context] = {
@@ -297,11 +299,13 @@ export var normalizeCellProps = function normalizeCellProps(props, theme) {
297
299
  }
298
300
  });
299
301
  });
302
+ result.body.selected = _extends({}, theme == null || (_theme$dataTable3 = theme.dataTable) == null || (_theme$dataTable3 = _theme$dataTable3.body) == null ? void 0 : _theme$dataTable3.selected);
300
303
  return result;
301
304
  };
302
305
  export var normalizeRowCellProps = function normalizeRowCellProps(rowProps, cellProps, primaryKey, index) {
303
306
  var result = {
304
- pinned: {}
307
+ pinned: {},
308
+ selected: cellProps.selected
305
309
  };
306
310
  ['background', 'border', 'pad'].forEach(function (propName) {
307
311
  var _rowProps$primaryKey;
@@ -114,7 +114,7 @@ export var SpaceX = function SpaceX() {
114
114
  }, [groups]);
115
115
  useEffect(function () {
116
116
  var fetchData = /*#__PURE__*/function () {
117
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
117
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
118
118
  var query;
119
119
  return _regeneratorRuntime().wrap(function _callee$(_context) {
120
120
  while (1) switch (_context.prev = _context.next) {
@@ -151,7 +151,7 @@ export var SpaceX = function SpaceX() {
151
151
  }, []);
152
152
  useEffect(function () {
153
153
  var fetchData = /*#__PURE__*/function () {
154
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
154
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
155
155
  var _sort;
156
156
  var query;
157
157
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -64,7 +64,7 @@ export var SpaceXUngrouped = function SpaceXUngrouped() {
64
64
  setLimit = _useState3[1];
65
65
  useEffect(function () {
66
66
  var fetchData = /*#__PURE__*/function () {
67
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
67
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
68
68
  var _sort;
69
69
  var query;
70
70
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -177,12 +177,50 @@ var DropContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
177
177
  direction, change the Drop to display above/below. If there is
178
178
  less room in the other direction leave the Drop in its current
179
179
  position. */
180
- if (responsive && (align.top === 'top' && targetRect.top < 0 || align.bottom === 'top' && targetRect.top - containerRect.height <= 0 && targetRect.bottom + containerRect.height < windowHeight)) {
180
+ if (responsive &&
181
+ // drop is above target
182
+ align.bottom === 'top' &&
183
+ // drop is overflowing above window
184
+ targetRect.top - containerRect.height <= 0 &&
185
+ // there is room to display the drop below the target
186
+ targetRect.bottom + containerRect.height < windowHeight) {
187
+ // top of drop is aligned to bottom of target
181
188
  top = targetRect.bottom;
182
189
  maxHeight = top;
183
- } else if (responsive && (align.bottom === 'bottom' && targetRect.bottom > windowHeight || align.top === 'bottom' && targetRect.bottom + containerRect.height >= windowHeight && targetRect.top - containerRect.height > 0)) {
190
+ } else if (responsive &&
191
+ // top of drop is aligned to top of target
192
+ align.top === 'top' &&
193
+ // drop is overflowing below window
194
+ targetRect.top + containerRect.height >= windowHeight &&
195
+ // height of the drop is larger than the target.
196
+ targetRect.top + containerRect.height > targetRect.bottom &&
197
+ // there is room to display the drop above the target
198
+ targetRect.bottom - containerRect.height > 0) {
199
+ // bottom of drop is aligned to bottom of target
200
+ bottom = targetRect.bottom;
201
+ maxHeight = top;
202
+ } else if (responsive &&
203
+ // top of drop is aligned to bottom of target
204
+ align.top === 'bottom' &&
205
+ // drop is overflowing below window
206
+ targetRect.bottom + containerRect.height >= windowHeight &&
207
+ // there is room to display the drop above the target
208
+ targetRect.top - containerRect.height > 0) {
209
+ // bottom of drop is aligned to top of target
184
210
  bottom = targetRect.top;
185
211
  maxHeight = bottom;
212
+ } else if (responsive &&
213
+ // bottom of drop is aligned to bottom of target
214
+ align.bottom === 'bottom' &&
215
+ // drop is overflowing above window
216
+ targetRect.bottom - containerRect.height <= 0 &&
217
+ // height of the drop is larger than the target.
218
+ targetRect.bottom - containerRect.height > targetRect.top &&
219
+ // there is room to display the drop below the target
220
+ targetRect.top + containerRect.height > 0) {
221
+ // top of drop is aligned to top of target
222
+ top = targetRect.top;
223
+ maxHeight = bottom;
186
224
  } else if (align.top === 'top') {
187
225
  top = targetRect.top;
188
226
  maxHeight = windowHeight - top;
@@ -265,9 +303,19 @@ var DropContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
265
303
  window.removeEventListener('resize', onResize);
266
304
  };
267
305
  }, [align, containerTarget, onAlign, dropTarget, portalContext, portalId, responsive, restrictFocus, stretch, theme.drop, dropRef, dropOptions]);
306
+
307
+ // Once drop is open the focus will be put on the drop container
308
+ // if restrictFocus is true. If the caller put focus
309
+ // on an element already, we honor that. Otherwise, we put
310
+ // the focus on the drop container.
268
311
  useEffect(function () {
269
312
  if (restrictFocus) {
270
- dropRef.current.focus();
313
+ var dropContainer = dropRef.current;
314
+ if (dropContainer) {
315
+ if (!dropContainer.contains(document.activeElement)) {
316
+ dropContainer.focus();
317
+ }
318
+ }
271
319
  }
272
320
  }, [dropRef, restrictFocus]);
273
321
  var content = /*#__PURE__*/React.createElement(StyledDrop, _extends({
@@ -23,9 +23,8 @@ export interface FileInputProps {
23
23
  multiple?: boolean | { aggregateThreshold?: number; max?: number };
24
24
  name?: string;
25
25
  onChange?: (
26
- event?: React.ChangeEvent<HTMLInputElement>,
27
- { files }?: { files: File[] },
28
- { target }?: { target: { files: FileList } },
26
+ event: React.ChangeEvent<HTMLInputElement>,
27
+ { files }: { files: File[] },
29
28
  ) => void;
30
29
  renderFile?: (...args: any[]) => void;
31
30
  }
@@ -1,9 +1,28 @@
1
1
  var _excluded = ["hidden", "restrictScroll", "children", "trapFocus"];
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
4
- import React, { useContext, useEffect, useRef, useState } from 'react';
4
+ import React, { useEffect, useRef, useState } from 'react';
5
5
  import { makeNodeFocusable, makeNodeUnfocusable } from '../utils';
6
- import { RootsContext } from '../contexts/RootsContext';
6
+ import { RootsContext, useRoots } from '../contexts/RootsContext';
7
+ var isFocusable = function isFocusable(element) {
8
+ if ((element == null ? void 0 : element.tabIndex) < 0 || element != null && element.disabled) {
9
+ return false;
10
+ }
11
+ switch (element == null ? void 0 : element.nodeName) {
12
+ case 'A':
13
+ return !!element.href && element.rel !== 'ignore';
14
+ case 'INPUT':
15
+ return element.type !== 'hidden';
16
+ case 'BUTTON':
17
+ case 'SELECT':
18
+ case 'TEXTAREA':
19
+ return true;
20
+ case 'DIV':
21
+ return element.tabIndex >= 0;
22
+ default:
23
+ return false;
24
+ }
25
+ };
7
26
  export var FocusedContainer = function FocusedContainer(_ref) {
8
27
  var _ref$hidden = _ref.hidden,
9
28
  hidden = _ref$hidden === void 0 ? false : _ref$hidden,
@@ -16,14 +35,103 @@ export var FocusedContainer = function FocusedContainer(_ref) {
16
35
  bodyOverflowStyle = _useState[0],
17
36
  setBodyOverflowStyle = _useState[1];
18
37
  var ref = useRef(null);
19
- var roots = useContext(RootsContext);
20
- var _useState2 = useState(roots),
21
- nextRoots = _useState2[0],
22
- setNextRoots = _useState2[1];
38
+ var preNodeRef = useRef(null);
39
+ var postNodeRef = useRef(null);
40
+ var _useRoots = useRoots(),
41
+ contextValue = _useRoots.contextValue,
42
+ hasRoots = _useRoots.hasRoots;
43
+ var contextRoots = contextValue.roots;
44
+ // When attemptFocus moves focus around to find the focusable element,
45
+ // set this to true so handleTrapFocus doesn't focus the element.
46
+ var ignoreUtilFocusRef = useRef(false);
47
+ var lastFocusRef = useRef(null);
23
48
  useEffect(function () {
24
- // make sure value of null is not added to array
25
- if (ref.current) setNextRoots([].concat(roots, [ref.current]));
26
- }, [roots]);
49
+ var container = ref.current;
50
+ var roots = contextRoots.current;
51
+ var attemptFocus = function attemptFocus(element) {
52
+ // Check if the element is focusable; if not, return false
53
+ if (!isFocusable(element)) {
54
+ return false;
55
+ }
56
+ ignoreUtilFocusRef.current = true;
57
+ try {
58
+ element.focus();
59
+ } catch (e) {
60
+ // continue regardless of error
61
+ }
62
+ ignoreUtilFocusRef.current = false;
63
+ // Return true if the element is currently the active element or has focus
64
+ return document.activeElement === element;
65
+ };
66
+ var _focusFirstDescendant = function focusFirstDescendant(element) {
67
+ // Iterate through all child nodes of the provided element
68
+ for (var i = 0; i < element.childNodes.length; i += 1) {
69
+ var child = element.childNodes[i];
70
+ if (attemptFocus(child) || _focusFirstDescendant(child)) return true;
71
+ }
72
+ // If no focusable child or descendant was found, return false
73
+ return false;
74
+ };
75
+ var _focusLastDescendant = function focusLastDescendant(element) {
76
+ for (var i = element.childNodes.length - 1; i >= 0; i -= 1) {
77
+ var child = element.childNodes[i];
78
+ if (attemptFocus(child) || _focusLastDescendant(child)) return true;
79
+ }
80
+ return false;
81
+ };
82
+ var handleTrapFocus = function handleTrapFocus(e) {
83
+ if (!hidden && trapFocus && ignoreUtilFocusRef.current === false && container &&
84
+ // only perform focus if this is the most recently opened drop
85
+ roots[roots.length - 1] === container) {
86
+ if (container.contains(e.target)) {
87
+ lastFocusRef.current = e.target;
88
+ } else {
89
+ _focusFirstDescendant(container);
90
+ if (lastFocusRef.current === document.activeElement) {
91
+ _focusLastDescendant(container);
92
+ }
93
+ lastFocusRef.current = document.activeElement;
94
+ }
95
+ }
96
+ };
97
+
98
+ // add container to the global roots
99
+ if (container) roots.push(container);
100
+
101
+ // Create and insert focusable nodes to help track when focus
102
+ // has left this container but without letting focus be noticeably
103
+ // placed on anything outside the container
104
+ if (!hidden && trapFocus) {
105
+ var preDiv = document.createElement('div');
106
+ var postDiv = document.createElement('div');
107
+ var commonStyles = {
108
+ position: 'absolute',
109
+ height: '1px',
110
+ left: '0',
111
+ right: '0'
112
+ };
113
+ Object.assign(preDiv.style, _extends({}, commonStyles, {
114
+ top: '0'
115
+ }));
116
+ Object.assign(postDiv.style, _extends({}, commonStyles, {
117
+ bottom: '0'
118
+ }));
119
+ preNodeRef.current = container.parentNode.insertBefore(preDiv, container);
120
+ postNodeRef.current = container.parentNode.insertBefore(postDiv, container.nextSibling);
121
+ preNodeRef.current.tabIndex = 0;
122
+ postNodeRef.current.tabIndex = 0;
123
+ }
124
+ document.addEventListener('focus', handleTrapFocus, true);
125
+ return function () {
126
+ var _preNodeRef$current, _postNodeRef$current;
127
+ // remove from global roots array
128
+ if (roots.includes(container)) roots.splice(roots.indexOf(container), 1);
129
+ document.removeEventListener('focus', handleTrapFocus, true);
130
+ if (roots != null && roots[roots.length - 1]) makeNodeFocusable(roots[roots.length - 1]);
131
+ preNodeRef == null || (_preNodeRef$current = preNodeRef.current) == null || _preNodeRef$current.remove();
132
+ postNodeRef == null || (_postNodeRef$current = postNodeRef.current) == null || _postNodeRef$current.remove();
133
+ };
134
+ }, [hidden, contextRoots, trapFocus]);
27
135
  useEffect(function () {
28
136
  if (bodyOverflowStyle !== 'hidden' && !hidden && restrictScroll && trapFocus) {
29
137
  setBodyOverflowStyle(document.body.style.overflow);
@@ -36,21 +144,30 @@ export var FocusedContainer = function FocusedContainer(_ref) {
36
144
  };
37
145
  }, [bodyOverflowStyle, hidden, trapFocus, restrictScroll]);
38
146
  useEffect(function () {
147
+ var roots = contextRoots.current;
39
148
  var timer = setTimeout(function () {
40
- if (!hidden && trapFocus && roots && roots[0]) {
41
- roots.forEach(makeNodeUnfocusable);
149
+ if (!hidden && trapFocus) {
150
+ // make every root before this one unfocusable
151
+ roots == null || roots.forEach(function (root, index) {
152
+ if (index < roots.length - 1) makeNodeUnfocusable(root);
153
+ });
42
154
  }
43
155
  }, 0);
44
156
  return function () {
45
- // remove trap and restore ability to focus on the last root only
46
- if (roots && roots[0]) makeNodeFocusable(roots[roots.length - 1]);
47
- clearTimeout(timer);
157
+ return clearTimeout(timer);
48
158
  };
49
- }, [hidden, roots, trapFocus]);
50
- return /*#__PURE__*/React.createElement(RootsContext.Provider, {
51
- value: nextRoots
52
- }, /*#__PURE__*/React.createElement("div", _extends({
159
+ }, [hidden, contextRoots, trapFocus]);
160
+ var focusedContainer = /*#__PURE__*/React.createElement("div", _extends({
53
161
  ref: ref,
54
162
  "aria-hidden": hidden
55
- }, rest), children));
163
+ }, rest), children);
164
+ if (hasRoots) return focusedContainer;
165
+ return (
166
+ /*#__PURE__*/
167
+ // for cases outside of Grommet React tree, manage trapFocus when
168
+ // Drop/Layer opens another Drop/Layer
169
+ React.createElement(RootsContext.Provider, {
170
+ value: contextValue
171
+ }, focusedContainer)
172
+ );
56
173
  };
@@ -1,7 +1,7 @@
1
1
  var _excluded = ["children", "full", "containerTarget", "theme", "options", "messages", "onAnalytics"];
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
4
- import React, { forwardRef, useEffect, useMemo, useState } from 'react';
4
+ import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { createGlobalStyle } from 'styled-components';
6
6
  import { ContainerTargetContext, ResponsiveContext, ThemeContext } from '../../contexts';
7
7
  import { deepMerge, backgroundIsDark, getBreakpoint, getDeviceBreakpoint, normalizeColor, useForwardedRef } from '../../utils';
@@ -53,9 +53,6 @@ var Grommet = /*#__PURE__*/forwardRef(function (props, ref) {
53
53
  var _useState = useState(),
54
54
  stateResponsive = _useState[0],
55
55
  setResponsive = _useState[1];
56
- var _useState2 = useState([]),
57
- roots = _useState2[0],
58
- setRoots = _useState2[1];
59
56
  var theme = useMemo(function () {
60
57
  var nextTheme = deepMerge(baseTheme, themeProp || {});
61
58
 
@@ -106,15 +103,24 @@ var Grommet = /*#__PURE__*/forwardRef(function (props, ref) {
106
103
  }, [theme]);
107
104
  var responsive = stateResponsive || deviceResponsive(userAgent, theme) || theme.global.deviceBreakpoints.tablet;
108
105
  var grommetRef = useForwardedRef(ref);
106
+
107
+ // track open FocusedContainers in a global array to manage
108
+ // focus event listeners for trapFocus
109
+ var roots = useRef([]);
109
110
  useEffect(function () {
110
- if (grommetRef.current) setRoots([grommetRef.current]);
111
+ if (grommetRef.current) roots.current.push(grommetRef.current);
111
112
  }, [grommetRef]);
113
+ var rootsContextValue = useMemo(function () {
114
+ return {
115
+ roots: roots
116
+ };
117
+ }, []);
112
118
  return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
113
119
  value: theme
114
120
  }, /*#__PURE__*/React.createElement(ResponsiveContext.Provider, {
115
121
  value: responsive
116
122
  }, /*#__PURE__*/React.createElement(RootsContext.Provider, {
117
- value: roots
123
+ value: rootsContextValue
118
124
  }, /*#__PURE__*/React.createElement(ContainerTargetContext.Provider, {
119
125
  value: containerTarget
120
126
  }, /*#__PURE__*/React.createElement(OptionsContext.Provider, {
@@ -68,7 +68,7 @@ var Layer = /*#__PURE__*/forwardRef(function (props, ref) {
68
68
  }
69
69
  };
70
70
  }, [animate, animation, containerTarget, layerContainer, originalFocusedElement]);
71
- return layerContainer ? /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(LayerContainer, _extends({
71
+ return layerContainer ? /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement(LayerContainer, _extends({
72
72
  ref: ref
73
73
  }, props)), layerContainer) : null;
74
74
  });