grommet 2.40.2 → 2.41.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.
- package/components/Button/StyledButtonKind.js +12 -6
- package/components/DataChart/Detail.js +19 -4
- package/components/DataFilter/DataFilter.js +5 -0
- package/components/Drop/DropContainer.js +51 -3
- package/components/FocusedContainer.js +134 -17
- package/components/Grommet/Grommet.js +11 -5
- package/components/MaskedInput/MaskedInput.js +3 -0
- package/components/Menu/Menu.js +3 -3
- package/components/Select/Select.js +22 -15
- package/components/Select/stories/ChildrenRender.js +7 -8
- package/components/SelectMultiple/SelectMultiple.js +8 -6
- package/components/TextInput/TextInput.js +3 -0
- package/contexts/RootsContext.js +23 -5
- package/es6/components/Button/StyledButtonKind.js +12 -6
- package/es6/components/DataChart/Detail.js +20 -5
- package/es6/components/DataFilter/DataFilter.js +5 -0
- package/es6/components/Drop/DropContainer.js +51 -3
- package/es6/components/FocusedContainer.js +136 -19
- package/es6/components/Grommet/Grommet.js +12 -6
- package/es6/components/MaskedInput/MaskedInput.js +3 -0
- package/es6/components/Menu/Menu.js +3 -3
- package/es6/components/Select/Select.js +22 -15
- package/es6/components/Select/stories/ChildrenRender.js +7 -8
- package/es6/components/SelectMultiple/SelectMultiple.js +8 -6
- package/es6/components/TextInput/TextInput.js +3 -0
- package/es6/contexts/RootsContext.js +20 -3
- package/es6/themes/base.d.ts +1 -0
- package/es6/themes/base.js +1 -0
- package/es6/utils/DOM.js +2 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +22 -22
- package/themes/base.d.ts +1 -0
- package/themes/base.js +1 -0
- package/utils/DOM.js +2 -1
|
@@ -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 (
|
|
151
|
-
var _data$
|
|
152
|
-
var property =
|
|
153
|
-
return (!activeProperty || activeProperty === property) && (data == null || (_data$
|
|
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;
|
|
@@ -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
|
}
|
|
@@ -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 &&
|
|
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 &&
|
|
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
|
|
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({
|
|
@@ -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, {
|
|
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
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
41
|
-
|
|
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
|
-
|
|
46
|
-
if (roots && roots[0]) makeNodeFocusable(roots[roots.length - 1]);
|
|
47
|
-
clearTimeout(timer);
|
|
157
|
+
return clearTimeout(timer);
|
|
48
158
|
};
|
|
49
|
-
}, [hidden,
|
|
50
|
-
|
|
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)
|
|
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:
|
|
123
|
+
value: rootsContextValue
|
|
118
124
|
}, /*#__PURE__*/React.createElement(ContainerTargetContext.Provider, {
|
|
119
125
|
value: containerTarget
|
|
120
126
|
}, /*#__PURE__*/React.createElement(OptionsContext.Provider, {
|
|
@@ -380,6 +380,9 @@ var MaskedInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
380
380
|
target: inputRef.current,
|
|
381
381
|
onClickOutside: onHideDrop,
|
|
382
382
|
onEsc: onHideDrop
|
|
383
|
+
// MaskedInput manages its own keyboard behavior via Keyboard
|
|
384
|
+
,
|
|
385
|
+
trapFocus: false
|
|
383
386
|
}, dropProps), /*#__PURE__*/React.createElement(ContainerBox, _extends({
|
|
384
387
|
ref: dropRef,
|
|
385
388
|
overflow: "auto",
|
|
@@ -390,14 +390,14 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
390
390
|
ref: dropContainerRef,
|
|
391
391
|
tabIndex: -1,
|
|
392
392
|
background: dropBackground || theme.menu.background
|
|
393
|
-
}, passThemeFlag), alignControlMirror === 'top' && align.
|
|
393
|
+
}, passThemeFlag), alignControlMirror === 'top' && align.bottom !== 'top' && align.top !== 'bottom' ? controlMirror : undefined, /*#__PURE__*/React.createElement(Box, {
|
|
394
394
|
overflow: "auto",
|
|
395
395
|
role: "menu",
|
|
396
396
|
a11yTitle: a11y
|
|
397
|
-
}, menuContent), !initialAlignTop &&
|
|
397
|
+
}, menuContent), !initialAlignTop &&
|
|
398
398
|
// don't show controlMirror if caller is using
|
|
399
399
|
// align.bottom === 'top'
|
|
400
|
-
alignControlMirror === 'bottom' &&
|
|
400
|
+
alignControlMirror === 'bottom' && align.bottom !== 'top' && align.top !== 'bottom' ? controlMirror : undefined))
|
|
401
401
|
}), content));
|
|
402
402
|
});
|
|
403
403
|
Menu.displayName = 'Menu';
|
|
@@ -126,23 +126,30 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
126
126
|
// the option indexes present in the value
|
|
127
127
|
var optionIndexesInValue = useMemo(function () {
|
|
128
128
|
var result = [];
|
|
129
|
-
|
|
130
|
-
if (selected
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
129
|
+
if (selected !== undefined) {
|
|
130
|
+
if (Array.isArray(selected)) {
|
|
131
|
+
var validSelections = selected.filter(function (i) {
|
|
132
|
+
return i in allOptions;
|
|
133
|
+
});
|
|
134
|
+
result.push.apply(result, validSelections);
|
|
135
|
+
} else if (selected in allOptions) {
|
|
136
|
+
result.push(selected);
|
|
137
|
+
}
|
|
138
|
+
} else if (Array.isArray(normalizedValue)) {
|
|
139
|
+
normalizedValue.forEach(function (v) {
|
|
140
|
+
var index = allOptions.map(function (option) {
|
|
141
|
+
return applyKey(option, valueKey);
|
|
142
|
+
}).indexOf(v);
|
|
143
|
+
if (index !== -1) result.push(index);
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
var index = allOptions.map(function (option) {
|
|
147
|
+
return applyKey(option, valueKey);
|
|
148
|
+
}).indexOf(normalizedValue);
|
|
149
|
+
if (index !== -1) {
|
|
143
150
|
result.push(index);
|
|
144
151
|
}
|
|
145
|
-
}
|
|
152
|
+
}
|
|
146
153
|
return result;
|
|
147
154
|
}, [allOptions, selected, valueKey, normalizedValue]);
|
|
148
155
|
var _useState3 = useState(propOpen),
|
|
@@ -7,9 +7,8 @@ export var Children = function Children() {
|
|
|
7
7
|
selected = _useState[0],
|
|
8
8
|
setSelected = _useState[1];
|
|
9
9
|
var onRemoveSeason = function onRemoveSeason(season) {
|
|
10
|
-
var seasonIndex = allSeasons.indexOf(season);
|
|
11
10
|
setSelected(selected.filter(function (selectedSeason) {
|
|
12
|
-
return selectedSeason !==
|
|
11
|
+
return selectedSeason !== season;
|
|
13
12
|
}));
|
|
14
13
|
};
|
|
15
14
|
var renderSeason = function renderSeason(season) {
|
|
@@ -67,12 +66,12 @@ export var Children = function Children() {
|
|
|
67
66
|
}, /*#__PURE__*/React.createElement(Select, {
|
|
68
67
|
closeOnChange: false,
|
|
69
68
|
multiple: true,
|
|
70
|
-
|
|
69
|
+
valueLabel: /*#__PURE__*/React.createElement(Box, {
|
|
71
70
|
wrap: true,
|
|
72
71
|
direction: "row",
|
|
73
72
|
width: "small"
|
|
74
|
-
}, selected && selected.length ? selected.map(function (
|
|
75
|
-
return renderSeason(
|
|
73
|
+
}, selected && selected.length ? selected.map(function (value) {
|
|
74
|
+
return renderSeason(value);
|
|
76
75
|
}) : /*#__PURE__*/React.createElement(Box, {
|
|
77
76
|
pad: {
|
|
78
77
|
vertical: 'xsmall',
|
|
@@ -81,11 +80,11 @@ export var Children = function Children() {
|
|
|
81
80
|
margin: "xsmall"
|
|
82
81
|
}, "Select Season")),
|
|
83
82
|
options: allSeasons,
|
|
84
|
-
|
|
83
|
+
value: selected,
|
|
85
84
|
disabled: [2, 6],
|
|
86
85
|
onChange: function onChange(_ref) {
|
|
87
|
-
var nextSelected = _ref.
|
|
88
|
-
setSelected(
|
|
86
|
+
var nextSelected = _ref.value;
|
|
87
|
+
setSelected(nextSelected);
|
|
89
88
|
}
|
|
90
89
|
}, renderOption))
|
|
91
90
|
// </Grommet>
|
|
@@ -159,12 +159,14 @@ var SelectMultiple = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
159
159
|
// the option indexes present in the value
|
|
160
160
|
var optionIndexesInValue = useMemo(function () {
|
|
161
161
|
var result = [];
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
if (!Array.isArray(normalizedValue)) {
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
normalizedValue.forEach(function (v) {
|
|
166
|
+
var index = allOptions.map(function (option) {
|
|
167
|
+
return applyKey(option, valueKey);
|
|
168
|
+
}).indexOf(v);
|
|
169
|
+
if (index !== -1) result.push(index);
|
|
168
170
|
});
|
|
169
171
|
return result;
|
|
170
172
|
}, [allOptions, valueKey, normalizedValue]);
|
|
@@ -276,6 +276,9 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
276
276
|
target: dropTarget || inputRef.current,
|
|
277
277
|
onClickOutside: clickOutside,
|
|
278
278
|
onEsc: closeDrop
|
|
279
|
+
// TextInput manages its own keyboard behavior via keyboardProps
|
|
280
|
+
,
|
|
281
|
+
trapFocus: false
|
|
279
282
|
}, dropProps), /*#__PURE__*/React.createElement(ContainerBox, _extends({
|
|
280
283
|
id: id ? "listbox__" + id : undefined,
|
|
281
284
|
role: "listbox",
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext, useMemo, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
// When toggling aria-hidden values, we only want to affect elements
|
|
4
4
|
// in the DOM that come from Grommet, so we track those elements in this
|
|
5
|
-
// context value.
|
|
6
|
-
|
|
5
|
+
// context value. We also only want `trapFocus` to apply to the most recently
|
|
6
|
+
// opened Drop/Layer. See FocusedContainer.js
|
|
7
|
+
export var RootsContext = /*#__PURE__*/React.createContext(undefined);
|
|
8
|
+
export var useRoots = function useRoots() {
|
|
9
|
+
// If FocusedContainer is within Grommet React tree, there will be a value
|
|
10
|
+
// from RootsContext. If not, set up a default value that can be passed
|
|
11
|
+
// to drops that might open from within a drop.
|
|
12
|
+
var defaultRoots = useRef([]);
|
|
13
|
+
var defaultValue = useMemo(function () {
|
|
14
|
+
return {
|
|
15
|
+
roots: defaultRoots
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
var existingRoots = useContext(RootsContext);
|
|
19
|
+
return {
|
|
20
|
+
contextValue: existingRoots || defaultValue,
|
|
21
|
+
hasRoots: (existingRoots == null ? void 0 : existingRoots.roots) !== undefined
|
|
22
|
+
};
|
|
23
|
+
};
|
package/es6/themes/base.d.ts
CHANGED
package/es6/themes/base.js
CHANGED
package/es6/utils/DOM.js
CHANGED
|
@@ -153,7 +153,8 @@ export var makeNodeUnfocusable = function makeNodeUnfocusable(node) {
|
|
|
153
153
|
Array.prototype.filter.call(elements || [], function (element) {
|
|
154
154
|
return element.getAttribute(TABINDEX) !== null;
|
|
155
155
|
}).forEach(function (element) {
|
|
156
|
-
|
|
156
|
+
// if TABINDEX_STATE already exists, it's holding the original value
|
|
157
|
+
if (!element.getAttribute(TABINDEX_STATE)) element.setAttribute(TABINDEX_STATE, element.getAttribute(TABINDEX));
|
|
157
158
|
element.setAttribute(TABINDEX, -1);
|
|
158
159
|
});
|
|
159
160
|
// then, if any element is inherently focusable and not handled above,
|