grommet 2.25.2 → 2.25.3

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.
@@ -55,7 +55,7 @@ var Anchor = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
55
55
  var onClick = (0, _react.useCallback)(function (event) {
56
56
  sendAnalytics({
57
57
  type: 'anchorClick',
58
- element: event.target,
58
+ element: (0, _utils.findButtonParent)(event.target),
59
59
  event: event,
60
60
  href: href,
61
61
  label: typeof label === 'string' ? label : undefined
@@ -235,7 +235,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
235
235
  var onClick = (0, _react.useCallback)(function (event) {
236
236
  sendAnalytics({
237
237
  type: 'buttonClick',
238
- element: event.target,
238
+ element: (0, _utils.findButtonParent)(event.target),
239
239
  event: event,
240
240
  href: href,
241
241
  label: typeof label === 'string' ? label : undefined
@@ -440,7 +440,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
440
440
  href: href,
441
441
  kind: kind,
442
442
  themePaths: themePaths,
443
- onClick: onClickProp ? onClick : undefined,
443
+ onClick: onClick,
444
444
  onFocus: function onFocus(event) {
445
445
  setFocus(true);
446
446
  if (_onFocus) _onFocus(event);
@@ -85,18 +85,25 @@ var LayerContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
85
85
  (0, _react.useEffect)(function () {
86
86
  var start = new Date();
87
87
  var element = layerRef.current;
88
- sendAnalytics({
89
- type: 'layerOpen',
90
- element: element
91
- });
92
- return function () {
88
+ var isHidden = position === 'hidden';
89
+
90
+ if (!isHidden) {
93
91
  sendAnalytics({
94
- type: 'layerClose',
95
- element: element,
96
- elapsed: new Date().getTime() - start.getTime()
92
+ type: 'layerOpen',
93
+ element: element
97
94
  });
95
+ }
96
+
97
+ return function () {
98
+ if (!isHidden) {
99
+ sendAnalytics({
100
+ type: 'layerClose',
101
+ element: element,
102
+ elapsed: new Date().getTime() - start.getTime()
103
+ });
104
+ }
98
105
  };
99
- }, [sendAnalytics, layerRef]);
106
+ }, [sendAnalytics, layerRef, position]);
100
107
  (0, _react.useEffect)(function () {
101
108
  if (position !== 'hidden') {
102
109
  var node = layerRef.current || containerRef.current || ref.current;
@@ -21,6 +21,8 @@ var _Text = require("../Text");
21
21
 
22
22
  var _utils = require("../../utils");
23
23
 
24
+ var _AnalyticsContext = require("../../contexts/AnalyticsContext");
25
+
24
26
  var _propTypes = require("./propTypes");
25
27
 
26
28
  var _excluded = ["a11yTitle", "aria-label", "action", "as", "background", "border", "children", "data", "defaultItemProps", "disabled", "focus", "itemKey", "itemProps", "onActive", "onClickItem", "onKeyDown", "onMore", "onOrder", "pad", "paginate", "primaryKey", "secondaryKey", "show", "step"];
@@ -221,6 +223,7 @@ var List = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
221
223
  setOrderingData = _useState5[1];
222
224
 
223
225
  var draggingRef = (0, _react.useRef)();
226
+ var sendAnalytics = (0, _AnalyticsContext.useAnalytics)();
224
227
  var ariaProps = {
225
228
  role: onClickItem || onOrder ? 'listbox' : 'list'
226
229
  };
@@ -266,6 +269,13 @@ var List = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
266
269
  adjustedEvent.item = data[active];
267
270
  adjustedEvent.index = active;
268
271
  onClickItem(adjustedEvent);
272
+ sendAnalytics({
273
+ type: 'listItemClick',
274
+ element: listRef.current,
275
+ event: adjustedEvent,
276
+ item: data[active],
277
+ index: active
278
+ });
269
279
  }
270
280
  } : undefined,
271
281
  onUp: (onClickItem || onOrder) && active ? function () {
@@ -420,6 +430,13 @@ var List = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
420
430
  // accessibility guidelines that focus remains on `ul`
421
431
 
422
432
  listRef.current.focus();
433
+ sendAnalytics({
434
+ type: 'listItemClick',
435
+ element: listRef.current,
436
+ event: adjustedEvent,
437
+ item: item,
438
+ index: index
439
+ });
423
440
  }
424
441
  },
425
442
  onMouseOver: function onMouseOver() {
@@ -7,7 +7,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
7
7
  import React, { cloneElement, forwardRef, useCallback, useContext, useEffect, useState } from 'react';
8
8
  import { ThemeContext } from 'styled-components';
9
9
  import { defaultProps } from '../../default-props';
10
- import { normalizeColor } from '../../utils';
10
+ import { findButtonParent, normalizeColor } from '../../utils';
11
11
  import { Box } from '../Box';
12
12
  import { StyledAnchor } from './StyledAnchor';
13
13
  import { AnchorPropTypes } from './propTypes';
@@ -38,7 +38,7 @@ var Anchor = /*#__PURE__*/forwardRef(function (_ref, ref) {
38
38
  var onClick = useCallback(function (event) {
39
39
  sendAnalytics({
40
40
  type: 'anchorClick',
41
- element: event.target,
41
+ element: findButtonParent(event.target),
42
42
  event: event,
43
43
  href: href,
44
44
  label: typeof label === 'string' ? label : undefined
@@ -6,7 +6,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
6
6
 
7
7
  import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState, useCallback } from 'react';
8
8
  import { ThemeContext } from 'styled-components';
9
- import { backgroundAndTextColors, colorIsDark, normalizeBackground, normalizeColor } from '../../utils';
9
+ import { backgroundAndTextColors, colorIsDark, findButtonParent, normalizeBackground, normalizeColor } from '../../utils';
10
10
  import { defaultProps } from '../../default-props';
11
11
  import { ButtonPropTypes } from './propTypes';
12
12
  import { Box } from '../Box';
@@ -215,7 +215,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
215
215
  var onClick = useCallback(function (event) {
216
216
  sendAnalytics({
217
217
  type: 'buttonClick',
218
- element: event.target,
218
+ element: findButtonParent(event.target),
219
219
  event: event,
220
220
  href: href,
221
221
  label: typeof label === 'string' ? label : undefined
@@ -420,7 +420,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
420
420
  href: href,
421
421
  kind: kind,
422
422
  themePaths: themePaths,
423
- onClick: onClickProp ? onClick : undefined,
423
+ onClick: onClick,
424
424
  onFocus: function onFocus(event) {
425
425
  setFocus(true);
426
426
  if (_onFocus) _onFocus(event);
@@ -62,18 +62,25 @@ var LayerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
62
62
  useEffect(function () {
63
63
  var start = new Date();
64
64
  var element = layerRef.current;
65
- sendAnalytics({
66
- type: 'layerOpen',
67
- element: element
68
- });
69
- return function () {
65
+ var isHidden = position === 'hidden';
66
+
67
+ if (!isHidden) {
70
68
  sendAnalytics({
71
- type: 'layerClose',
72
- element: element,
73
- elapsed: new Date().getTime() - start.getTime()
69
+ type: 'layerOpen',
70
+ element: element
74
71
  });
72
+ }
73
+
74
+ return function () {
75
+ if (!isHidden) {
76
+ sendAnalytics({
77
+ type: 'layerClose',
78
+ element: element,
79
+ elapsed: new Date().getTime() - start.getTime()
80
+ });
81
+ }
75
82
  };
76
- }, [sendAnalytics, layerRef]);
83
+ }, [sendAnalytics, layerRef, position]);
77
84
  useEffect(function () {
78
85
  if (position !== 'hidden') {
79
86
  var node = layerRef.current || containerRef.current || ref.current;
@@ -13,6 +13,7 @@ import { Keyboard } from '../Keyboard';
13
13
  import { Pagination } from '../Pagination';
14
14
  import { Text } from '../Text';
15
15
  import { focusStyle, genericStyles, normalizeColor, normalizeShow, unfocusStyle, useForwardedRef, usePagination } from '../../utils';
16
+ import { useAnalytics } from '../../contexts/AnalyticsContext';
16
17
  import { ListPropTypes } from './propTypes';
17
18
  var StyledList = styled.ul.withConfig({
18
19
  displayName: "List__StyledList",
@@ -201,6 +202,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
201
202
  setOrderingData = _useState5[1];
202
203
 
203
204
  var draggingRef = useRef();
205
+ var sendAnalytics = useAnalytics();
204
206
  var ariaProps = {
205
207
  role: onClickItem || onOrder ? 'listbox' : 'list'
206
208
  };
@@ -246,6 +248,13 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
246
248
  adjustedEvent.item = data[active];
247
249
  adjustedEvent.index = active;
248
250
  onClickItem(adjustedEvent);
251
+ sendAnalytics({
252
+ type: 'listItemClick',
253
+ element: listRef.current,
254
+ event: adjustedEvent,
255
+ item: data[active],
256
+ index: active
257
+ });
249
258
  }
250
259
  } : undefined,
251
260
  onUp: (onClickItem || onOrder) && active ? function () {
@@ -400,6 +409,13 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
400
409
  // accessibility guidelines that focus remains on `ul`
401
410
 
402
411
  listRef.current.focus();
412
+ sendAnalytics({
413
+ type: 'listItemClick',
414
+ element: listRef.current,
415
+ event: adjustedEvent,
416
+ item: item,
417
+ index: index
418
+ });
403
419
  }
404
420
  },
405
421
  onMouseOver: function onMouseOver() {
package/es6/utils/DOM.js CHANGED
@@ -199,4 +199,8 @@ export var isNodeBeforeScroll = function isNodeBeforeScroll(node, target) {
199
199
  targetTop = _ref2.top;
200
200
 
201
201
  return top <= targetTop;
202
+ };
203
+ export var findButtonParent = function findButtonParent(element) {
204
+ if (element && element.nodeName !== 'BUTTON' && element.nodeName !== 'A') return findButtonParent(element.parentElement);
205
+ return element;
202
206
  };