carbon-react 141.1.0 → 141.1.1

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.
@@ -11,5 +11,6 @@ declare const _default: (id: string) => {
11
11
  tabIndex: number;
12
12
  isInHighlightedRow: boolean | undefined;
13
13
  isInSelectedRow: boolean | undefined;
14
+ bringToFront: (ev: React.MouseEvent<HTMLElement, MouseEvent> | React.FocusEvent<HTMLElement>, tagName: "TD" | "TH") => void;
14
15
  };
15
16
  export default _default;
@@ -22,6 +22,48 @@ export default (id => {
22
22
  const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
23
23
  const isFirstCell = id === firstCellId;
24
24
  const isExpandableCell = expandable && isFirstCell && firstColumnExpandable;
25
+ const bringToFront = (ev, tagName) => {
26
+ /* istanbul ignore if */
27
+ if (!ev || !ev.nativeEvent || typeof ev.nativeEvent.composedPath !== "function") {
28
+ return;
29
+ }
30
+ const {
31
+ nativeEvent
32
+ } = ev;
33
+
34
+ // get the entire path of the event
35
+ const path = nativeEvent.composedPath();
36
+
37
+ // get the table from the path
38
+ const tableBody = path.find(el => {
39
+ return el instanceof HTMLElement && el.tagName === "TBODY";
40
+ });
41
+
42
+ // if there is no table in the path we don't do anything
43
+ if (!tableBody) {
44
+ return;
45
+ }
46
+
47
+ // get all the th and td elements that are sticky
48
+ const stickyCells = Array.from(tableBody.querySelectorAll("th, td")).filter(el => {
49
+ return el.getAttribute("data-sticky-align") === "left" || el.getAttribute("data-sticky-align") === "right" || el.classList.contains("isSticky");
50
+ });
51
+
52
+ // reset the z-index to the default value for all the sticky cells, in case other cells were clicked before
53
+ stickyCells.map(el => {
54
+ el.classList.remove("bringToFront");
55
+ return el;
56
+ });
57
+
58
+ // find the current cell in the path
59
+ const cell = path.find(el => el instanceof HTMLElement && el.tagName === tagName);
60
+
61
+ // if the current cell is sticky, increase the z-index value
62
+ const cellIndex = stickyCells.indexOf(cell);
63
+ if (cellIndex !== -1) {
64
+ stickyCells[cellIndex].classList.add("bringToFront");
65
+ }
66
+ };
25
67
  useEffect(() => {
26
68
  const tabstopTimer = setTimeout(() => {
27
69
  setTabIndex(isExpandableCell && getTabStopElementId() === id ? 0 : -1);
@@ -41,6 +83,7 @@ export default (id => {
41
83
  isExpandableCell,
42
84
  tabIndex,
43
85
  isInHighlightedRow: highlighted,
44
- isInSelectedRow: selected
86
+ isInSelectedRow: selected,
87
+ bringToFront
45
88
  };
46
89
  });
@@ -29,8 +29,12 @@ export const FlatTableCell = ({
29
29
  makeCellSticky,
30
30
  isInHighlightedRow,
31
31
  isInSelectedRow,
32
- tabIndex
32
+ tabIndex,
33
+ bringToFront
33
34
  } = useTableCell(internalId.current);
35
+ const handleOnFocus = ev => {
36
+ bringToFront(ev, "TD");
37
+ };
34
38
  return /*#__PURE__*/React.createElement(StyledFlatTableCell, _extends({
35
39
  leftPosition: leftPosition,
36
40
  rightPosition: rightPosition,
@@ -53,7 +57,8 @@ export const FlatTableCell = ({
53
57
  "data-selected": isInSelectedRow && isExpandableCell,
54
58
  "data-highlighted": isInHighlightedRow && isExpandableCell
55
59
  }, rest, {
56
- id: internalId.current
60
+ id: internalId.current,
61
+ onFocus: handleOnFocus
57
62
  }), /*#__PURE__*/React.createElement(StyledCellContent, {
58
63
  title: truncate && !title && typeof children === "string" ? children : title,
59
64
  expandable: expandable
@@ -19,10 +19,12 @@ const firstColumnOldFocusStyling = `
19
19
  outline: 2px solid var(--colorsSemanticFocus500);
20
20
  outline-offset: -1px;
21
21
  `;
22
- const newFocusStyling = `
23
- ${addFocusStyling(true)}
24
- z-index: 1000;
25
- `;
22
+ const newFocusStyling = theme => {
23
+ return `
24
+ ${addFocusStyling(true)}
25
+ z-index: ${theme.zIndex.overlay + 5};
26
+ `;
27
+ };
26
28
  const getLeftStickyStyling = (index, themeOptOut) => index === 0 && /* istanbul ignore next */
27
29
  themeOptOut && /* istanbul ignore next */
28
30
  css`
@@ -196,7 +198,7 @@ const StyledFlatTableRow = styled.tr`
196
198
  right: 0px;
197
199
  top: 0;
198
200
  bottom: 0px;
199
- ${!theme.focusRedesignOptOut ? newFocusStyling : /* istanbul ignore next */oldFocusStyling}
201
+ ${!theme.focusRedesignOptOut ? newFocusStyling(theme) : /* istanbul ignore next */oldFocusStyling}
200
202
  pointer-events: none;
201
203
  }
202
204
 
@@ -232,7 +234,7 @@ const StyledFlatTableRow = styled.tr`
232
234
  border: none;
233
235
  content: "";
234
236
  height: ${rowHeight}px;
235
- ${newFocusStyling}
237
+ ${newFocusStyling(theme)}
236
238
  }
237
239
  `}
238
240
  `}
@@ -280,7 +282,7 @@ const StyledFlatTableRow = styled.tr`
280
282
  cursor: pointer;
281
283
 
282
284
  :focus {
283
- ${!theme.focusRedesignOptOut ? newFocusStyling : /* istanbul ignore next */firstColumnOldFocusStyling}
285
+ ${!theme.focusRedesignOptOut ? newFocusStyling(theme) : /* istanbul ignore next */firstColumnOldFocusStyling}
284
286
  }
285
287
 
286
288
  :hover {
@@ -31,11 +31,15 @@ export const FlatTableRowHeader = ({
31
31
  isExpandableCell,
32
32
  tabIndex,
33
33
  isInHighlightedRow,
34
- isInSelectedRow
34
+ isInSelectedRow,
35
+ bringToFront
35
36
  } = useTableCell(internalId.current);
36
37
  const handleOnClick = useCallback(ev => {
37
38
  if (isExpandableCell && onClick) onClick(ev);
38
39
  }, [isExpandableCell, onClick]);
40
+ const handleOnFocus = ev => {
41
+ bringToFront(ev, "TH");
42
+ };
39
43
  const handleOnKeyDown = useCallback(ev => {
40
44
  if (isExpandableCell && onKeyDown) {
41
45
  onKeyDown(ev);
@@ -66,7 +70,8 @@ export const FlatTableRowHeader = ({
66
70
  "data-selected": isInSelectedRow && isExpandableCell,
67
71
  "data-highlighted": isInHighlightedRow && isExpandableCell
68
72
  }, rest, {
69
- id: internalId.current
73
+ id: internalId.current,
74
+ onFocus: handleOnFocus
70
75
  }), /*#__PURE__*/React.createElement(StyledFlatTableRowHeaderContent, {
71
76
  title: truncate && !title && typeof children === "string" ? children : title,
72
77
  expandable: expandable
@@ -269,6 +269,16 @@ css`
269
269
  }) => theme.zIndex.overlay};
270
270
  }
271
271
 
272
+ tbody
273
+ ${StyledFlatTableRowHeader}.bringToFront,
274
+ ${StyledFlatTableCell}.bringToFront,
275
+ tbody
276
+ ${StyledFlatTableCheckbox}.bringToFront {
277
+ z-index: ${({
278
+ theme
279
+ }) => theme.zIndex.overlay + 5};
280
+ }
281
+
272
282
  ${({
273
283
  footer
274
284
  }) => footer && css`
@@ -11,5 +11,6 @@ declare const _default: (id: string) => {
11
11
  tabIndex: number;
12
12
  isInHighlightedRow: boolean | undefined;
13
13
  isInSelectedRow: boolean | undefined;
14
+ bringToFront: (ev: React.MouseEvent<HTMLElement, MouseEvent> | React.FocusEvent<HTMLElement>, tagName: "TD" | "TH") => void;
14
15
  };
15
16
  export default _default;
@@ -29,6 +29,48 @@ var _default = id => {
29
29
  const makeCellSticky = leftPosition !== undefined || rightPosition !== undefined;
30
30
  const isFirstCell = id === firstCellId;
31
31
  const isExpandableCell = expandable && isFirstCell && firstColumnExpandable;
32
+ const bringToFront = (ev, tagName) => {
33
+ /* istanbul ignore if */
34
+ if (!ev || !ev.nativeEvent || typeof ev.nativeEvent.composedPath !== "function") {
35
+ return;
36
+ }
37
+ const {
38
+ nativeEvent
39
+ } = ev;
40
+
41
+ // get the entire path of the event
42
+ const path = nativeEvent.composedPath();
43
+
44
+ // get the table from the path
45
+ const tableBody = path.find(el => {
46
+ return el instanceof HTMLElement && el.tagName === "TBODY";
47
+ });
48
+
49
+ // if there is no table in the path we don't do anything
50
+ if (!tableBody) {
51
+ return;
52
+ }
53
+
54
+ // get all the th and td elements that are sticky
55
+ const stickyCells = Array.from(tableBody.querySelectorAll("th, td")).filter(el => {
56
+ return el.getAttribute("data-sticky-align") === "left" || el.getAttribute("data-sticky-align") === "right" || el.classList.contains("isSticky");
57
+ });
58
+
59
+ // reset the z-index to the default value for all the sticky cells, in case other cells were clicked before
60
+ stickyCells.map(el => {
61
+ el.classList.remove("bringToFront");
62
+ return el;
63
+ });
64
+
65
+ // find the current cell in the path
66
+ const cell = path.find(el => el instanceof HTMLElement && el.tagName === tagName);
67
+
68
+ // if the current cell is sticky, increase the z-index value
69
+ const cellIndex = stickyCells.indexOf(cell);
70
+ if (cellIndex !== -1) {
71
+ stickyCells[cellIndex].classList.add("bringToFront");
72
+ }
73
+ };
32
74
  (0, _react.useEffect)(() => {
33
75
  const tabstopTimer = setTimeout(() => {
34
76
  setTabIndex(isExpandableCell && getTabStopElementId() === id ? 0 : -1);
@@ -48,7 +90,8 @@ var _default = id => {
48
90
  isExpandableCell,
49
91
  tabIndex,
50
92
  isInHighlightedRow: highlighted,
51
- isInSelectedRow: selected
93
+ isInSelectedRow: selected,
94
+ bringToFront
52
95
  };
53
96
  };
54
97
  exports.default = _default;
@@ -38,8 +38,12 @@ const FlatTableCell = ({
38
38
  makeCellSticky,
39
39
  isInHighlightedRow,
40
40
  isInSelectedRow,
41
- tabIndex
41
+ tabIndex,
42
+ bringToFront
42
43
  } = (0, _useTableCell.default)(internalId.current);
44
+ const handleOnFocus = ev => {
45
+ bringToFront(ev, "TD");
46
+ };
43
47
  return /*#__PURE__*/_react.default.createElement(_flatTableCell.StyledFlatTableCell, _extends({
44
48
  leftPosition: leftPosition,
45
49
  rightPosition: rightPosition,
@@ -62,7 +66,8 @@ const FlatTableCell = ({
62
66
  "data-selected": isInSelectedRow && isExpandableCell,
63
67
  "data-highlighted": isInHighlightedRow && isExpandableCell
64
68
  }, rest, {
65
- id: internalId.current
69
+ id: internalId.current,
70
+ onFocus: handleOnFocus
66
71
  }), /*#__PURE__*/_react.default.createElement(_flatTableCell.StyledCellContent, {
67
72
  title: truncate && !title && typeof children === "string" ? children : title,
68
73
  expandable: expandable
@@ -28,10 +28,12 @@ const firstColumnOldFocusStyling = `
28
28
  outline: 2px solid var(--colorsSemanticFocus500);
29
29
  outline-offset: -1px;
30
30
  `;
31
- const newFocusStyling = `
32
- ${(0, _addFocusStyling.default)(true)}
33
- z-index: 1000;
34
- `;
31
+ const newFocusStyling = theme => {
32
+ return `
33
+ ${(0, _addFocusStyling.default)(true)}
34
+ z-index: ${theme.zIndex.overlay + 5};
35
+ `;
36
+ };
35
37
  const getLeftStickyStyling = (index, themeOptOut) => index === 0 && /* istanbul ignore next */
36
38
  themeOptOut && /* istanbul ignore next */
37
39
  (0, _styledComponents.css)`
@@ -205,7 +207,7 @@ const StyledFlatTableRow = _styledComponents.default.tr`
205
207
  right: 0px;
206
208
  top: 0;
207
209
  bottom: 0px;
208
- ${!theme.focusRedesignOptOut ? newFocusStyling : /* istanbul ignore next */oldFocusStyling}
210
+ ${!theme.focusRedesignOptOut ? newFocusStyling(theme) : /* istanbul ignore next */oldFocusStyling}
209
211
  pointer-events: none;
210
212
  }
211
213
 
@@ -241,7 +243,7 @@ const StyledFlatTableRow = _styledComponents.default.tr`
241
243
  border: none;
242
244
  content: "";
243
245
  height: ${rowHeight}px;
244
- ${newFocusStyling}
246
+ ${newFocusStyling(theme)}
245
247
  }
246
248
  `}
247
249
  `}
@@ -289,7 +291,7 @@ const StyledFlatTableRow = _styledComponents.default.tr`
289
291
  cursor: pointer;
290
292
 
291
293
  :focus {
292
- ${!theme.focusRedesignOptOut ? newFocusStyling : /* istanbul ignore next */firstColumnOldFocusStyling}
294
+ ${!theme.focusRedesignOptOut ? newFocusStyling(theme) : /* istanbul ignore next */firstColumnOldFocusStyling}
293
295
  }
294
296
 
295
297
  :hover {
@@ -40,11 +40,15 @@ const FlatTableRowHeader = ({
40
40
  isExpandableCell,
41
41
  tabIndex,
42
42
  isInHighlightedRow,
43
- isInSelectedRow
43
+ isInSelectedRow,
44
+ bringToFront
44
45
  } = (0, _useTableCell.default)(internalId.current);
45
46
  const handleOnClick = (0, _react.useCallback)(ev => {
46
47
  if (isExpandableCell && onClick) onClick(ev);
47
48
  }, [isExpandableCell, onClick]);
49
+ const handleOnFocus = ev => {
50
+ bringToFront(ev, "TH");
51
+ };
48
52
  const handleOnKeyDown = (0, _react.useCallback)(ev => {
49
53
  if (isExpandableCell && onKeyDown) {
50
54
  onKeyDown(ev);
@@ -75,7 +79,8 @@ const FlatTableRowHeader = ({
75
79
  "data-selected": isInSelectedRow && isExpandableCell,
76
80
  "data-highlighted": isInHighlightedRow && isExpandableCell
77
81
  }, rest, {
78
- id: internalId.current
82
+ id: internalId.current,
83
+ onFocus: handleOnFocus
79
84
  }), /*#__PURE__*/_react.default.createElement(_flatTableRowHeader.StyledFlatTableRowHeaderContent, {
80
85
  title: truncate && !title && typeof children === "string" ? children : title,
81
86
  expandable: expandable
@@ -278,6 +278,16 @@ const StyledFlatTableWrapper = exports.StyledFlatTableWrapper = (0, _styledCompo
278
278
  }) => theme.zIndex.overlay};
279
279
  }
280
280
 
281
+ tbody
282
+ ${_flatTableRowHeader.StyledFlatTableRowHeader}.bringToFront,
283
+ ${_flatTableCell.StyledFlatTableCell}.bringToFront,
284
+ tbody
285
+ ${_flatTableCheckbox.default}.bringToFront {
286
+ z-index: ${({
287
+ theme
288
+ }) => theme.zIndex.overlay + 5};
289
+ }
290
+
281
291
  ${({
282
292
  footer
283
293
  }) => footer && (0, _styledComponents.css)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "141.1.0",
3
+ "version": "141.1.1",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",