@carbon/react 1.3.0-rc.1 → 1.3.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.
@@ -22,7 +22,8 @@ function useTabbableContent(ref) {
22
22
  var _useState = useState(false),
23
23
  _useState2 = _slicedToArray(_useState, 2),
24
24
  hasTabbableContent = _useState2[0],
25
- setHasTabbableContent = _useState2[1];
25
+ setHasTabbableContent = _useState2[1]; // eslint-disable-next-line react-hooks/exhaustive-deps
26
+
26
27
 
27
28
  useIsomorphicEffect(function () {
28
29
  if (ref.current) {
@@ -159,7 +159,7 @@ function TabList(_ref2) {
159
159
  isScrollable = _useState4[0],
160
160
  setIsScrollable = _useState4[1];
161
161
 
162
- var _useState5 = useState(false),
162
+ var _useState5 = useState(null),
163
163
  _useState6 = _slicedToArray(_useState5, 2),
164
164
  scrollLeft = _useState6[0],
165
165
  setScrollLeft = _useState6[1];
@@ -178,7 +178,7 @@ function TabList(_ref2) {
178
178
  var isNextButtonVisible = ref.current ? scrollLeft + buttonWidth + ref.current.clientWidth < ref.current.scrollWidth : false;
179
179
  var previousButtonClasses = cx("".concat(prefix, "--tab--overflow-nav-button"), "".concat(prefix, "--tab--overflow-nav-button--previous"), _defineProperty({}, "".concat(prefix, "--tab--overflow-nav-button--hidden"), !isPreviousButtonVisible));
180
180
  var nextButtonClasses = cx("".concat(prefix, "--tab--overflow-nav-button"), "".concat(prefix, "--tab--overflow-nav-button--next"), _defineProperty({}, "".concat(prefix, "--tab--overflow-nav-button--hidden"), !isNextButtonVisible));
181
- var tabs = [];
181
+ var tabs = useRef([]);
182
182
  var debouncedOnScroll = useCallback(function () {
183
183
  return debounce(function (event) {
184
184
  setScrollLeft(event.target.scrollLeft);
@@ -188,11 +188,11 @@ function TabList(_ref2) {
188
188
  function onKeyDown(event) {
189
189
  if (matches(event, [ArrowRight, ArrowLeft, Home, End])) {
190
190
  event.preventDefault();
191
- var activeTabs = tabs.filter(function (tab) {
192
- return !tab.current.disabled;
191
+ var activeTabs = tabs.current.filter(function (tab) {
192
+ return !tab.disabled;
193
193
  });
194
- var currentIndex = activeTabs.indexOf(tabs[activation === 'automatic' ? selectedIndex : activeIndex]);
195
- var nextIndex = tabs.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
194
+ var currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
195
+ var nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
196
196
 
197
197
  if (activation === 'automatic') {
198
198
  setSelectedIndex(nextIndex);
@@ -200,29 +200,29 @@ function TabList(_ref2) {
200
200
  setActiveIndex(nextIndex);
201
201
  }
202
202
 
203
- tabs[nextIndex].current.focus();
203
+ tabs.current[nextIndex].focus();
204
204
  }
205
205
  }
206
206
 
207
207
  useEffectOnce(function () {
208
- var tab = tabs[selectedIndex];
208
+ var tab = tabs.current[selectedIndex];
209
209
 
210
210
  if (scrollIntoView && tab) {
211
- tab.current.scrollIntoView({
211
+ tab.scrollIntoView({
212
212
  block: 'nearest',
213
213
  inline: 'nearest'
214
214
  });
215
215
  }
216
216
  });
217
217
  useEffectOnce(function () {
218
- if (tabs[selectedIndex].current.disabled) {
219
- var activeTabs = tabs.filter(function (tab) {
220
- return !tab.current.disabled;
218
+ if (tabs.current[selectedIndex].disabled) {
219
+ var activeTabs = tabs.current.filter(function (tab) {
220
+ return !tab.disabled;
221
221
  });
222
222
 
223
223
  if (activeTabs.length > 0) {
224
224
  var tab = activeTabs[0];
225
- setSelectedIndex(tabs.indexOf(tab));
225
+ setSelectedIndex(tabs.current.indexOf(tab));
226
226
  }
227
227
  }
228
228
  });
@@ -246,19 +246,25 @@ function TabList(_ref2) {
246
246
  }, []); // updates scroll location for all scroll behavior.
247
247
 
248
248
  useIsomorphicEffect(function () {
249
- ref.current.scrollLeft = scrollLeft;
249
+ if (scrollLeft !== null) {
250
+ ref.current.scrollLeft = scrollLeft;
251
+ }
250
252
  }, [scrollLeft]);
251
253
  useIsomorphicEffect(function () {
252
- var tab = activation === 'manual' ? tabs[activeIndex] : tabs[selectedIndex];
254
+ if (!isScrollable) {
255
+ return;
256
+ }
257
+
258
+ var tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
253
259
 
254
260
  if (tab) {
255
261
  // The width of the "scroll buttons"
256
262
  // The start and end position of the selected tab
257
- var _tab$current$getBound = tab.current.getBoundingClientRect(),
258
- tabWidth = _tab$current$getBound.width;
263
+ var _tab$getBoundingClien = tab.getBoundingClientRect(),
264
+ tabWidth = _tab$getBoundingClien.width;
259
265
 
260
- var start = tab.current.offsetLeft;
261
- var end = tab.current.offsetLeft + tabWidth; // The start and end of the visible area for the tabs
266
+ var start = tab.offsetLeft;
267
+ var end = tab.offsetLeft + tabWidth; // The start and end of the visible area for the tabs
262
268
 
263
269
  var visibleStart = ref.current.scrollLeft + buttonWidth;
264
270
  var visibleEnd = ref.current.scrollLeft + ref.current.clientWidth - buttonWidth; // The beginning of the tab is clipped and not visible
@@ -272,13 +278,13 @@ function TabList(_ref2) {
272
278
  setScrollLeft(end + buttonWidth - ref.current.clientWidth);
273
279
  }
274
280
  }
275
- }, [activation, activeIndex, selectedIndex]);
281
+ }, [activation, activeIndex, selectedIndex, isScrollable]);
276
282
  usePressable(previousButton, {
277
283
  onPress: function onPress(_ref3) {
278
284
  var longPress = _ref3.longPress;
279
285
 
280
286
  if (!longPress) {
281
- setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.length * 1.5, 0));
287
+ setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
282
288
  }
283
289
  },
284
290
  onLongPress: function onLongPress() {
@@ -290,7 +296,7 @@ function TabList(_ref2) {
290
296
  var longPress = _ref4.longPress;
291
297
 
292
298
  if (!longPress) {
293
- setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
299
+ setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
294
300
  }
295
301
  },
296
302
  onLongPress: function onLongPress() {
@@ -313,12 +319,12 @@ function TabList(_ref2) {
313
319
  onScroll: debouncedOnScroll,
314
320
  onKeyDown: onKeyDown
315
321
  }), React__default.Children.map(children, function (child, index) {
316
- var ref = /*#__PURE__*/React__default.createRef();
317
- tabs.push(ref);
318
322
  return /*#__PURE__*/React__default.createElement(TabContext.Provider, {
319
323
  value: index
320
324
  }, /*#__PURE__*/React__default.cloneElement(child, {
321
- ref: ref
325
+ ref: function ref(node) {
326
+ tabs.current[index] = node;
327
+ }
322
328
  }));
323
329
  })), /*#__PURE__*/React__default.createElement("button", _extends({
324
330
  "aria-hidden": "true",
@@ -32,7 +32,8 @@ function useTabbableContent(ref) {
32
32
  var _useState = React.useState(false),
33
33
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
34
34
  hasTabbableContent = _useState2[0],
35
- setHasTabbableContent = _useState2[1];
35
+ setHasTabbableContent = _useState2[1]; // eslint-disable-next-line react-hooks/exhaustive-deps
36
+
36
37
 
37
38
  useIsomorphicEffect["default"](function () {
38
39
  if (ref.current) {
@@ -170,7 +170,7 @@ function TabList(_ref2) {
170
170
  isScrollable = _useState4[0],
171
171
  setIsScrollable = _useState4[1];
172
172
 
173
- var _useState5 = React.useState(false),
173
+ var _useState5 = React.useState(null),
174
174
  _useState6 = _rollupPluginBabelHelpers.slicedToArray(_useState5, 2),
175
175
  scrollLeft = _useState6[0],
176
176
  setScrollLeft = _useState6[1];
@@ -189,7 +189,7 @@ function TabList(_ref2) {
189
189
  var isNextButtonVisible = ref.current ? scrollLeft + buttonWidth + ref.current.clientWidth < ref.current.scrollWidth : false;
190
190
  var previousButtonClasses = cx__default["default"]("".concat(prefix, "--tab--overflow-nav-button"), "".concat(prefix, "--tab--overflow-nav-button--previous"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--tab--overflow-nav-button--hidden"), !isPreviousButtonVisible));
191
191
  var nextButtonClasses = cx__default["default"]("".concat(prefix, "--tab--overflow-nav-button"), "".concat(prefix, "--tab--overflow-nav-button--next"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(prefix, "--tab--overflow-nav-button--hidden"), !isNextButtonVisible));
192
- var tabs = [];
192
+ var tabs = React.useRef([]);
193
193
  var debouncedOnScroll = React.useCallback(function () {
194
194
  return debounce__default["default"](function (event) {
195
195
  setScrollLeft(event.target.scrollLeft);
@@ -199,11 +199,11 @@ function TabList(_ref2) {
199
199
  function onKeyDown(event) {
200
200
  if (match.matches(event, [keys.ArrowRight, keys.ArrowLeft, keys.Home, keys.End])) {
201
201
  event.preventDefault();
202
- var activeTabs = tabs.filter(function (tab) {
203
- return !tab.current.disabled;
202
+ var activeTabs = tabs.current.filter(function (tab) {
203
+ return !tab.disabled;
204
204
  });
205
- var currentIndex = activeTabs.indexOf(tabs[activation === 'automatic' ? selectedIndex : activeIndex]);
206
- var nextIndex = tabs.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
205
+ var currentIndex = activeTabs.indexOf(tabs.current[activation === 'automatic' ? selectedIndex : activeIndex]);
206
+ var nextIndex = tabs.current.indexOf(activeTabs[getNextIndex(event, activeTabs.length, currentIndex)]);
207
207
 
208
208
  if (activation === 'automatic') {
209
209
  setSelectedIndex(nextIndex);
@@ -211,29 +211,29 @@ function TabList(_ref2) {
211
211
  setActiveIndex(nextIndex);
212
212
  }
213
213
 
214
- tabs[nextIndex].current.focus();
214
+ tabs.current[nextIndex].focus();
215
215
  }
216
216
  }
217
217
 
218
218
  useEffectOnce.useEffectOnce(function () {
219
- var tab = tabs[selectedIndex];
219
+ var tab = tabs.current[selectedIndex];
220
220
 
221
221
  if (scrollIntoView && tab) {
222
- tab.current.scrollIntoView({
222
+ tab.scrollIntoView({
223
223
  block: 'nearest',
224
224
  inline: 'nearest'
225
225
  });
226
226
  }
227
227
  });
228
228
  useEffectOnce.useEffectOnce(function () {
229
- if (tabs[selectedIndex].current.disabled) {
230
- var activeTabs = tabs.filter(function (tab) {
231
- return !tab.current.disabled;
229
+ if (tabs.current[selectedIndex].disabled) {
230
+ var activeTabs = tabs.current.filter(function (tab) {
231
+ return !tab.disabled;
232
232
  });
233
233
 
234
234
  if (activeTabs.length > 0) {
235
235
  var tab = activeTabs[0];
236
- setSelectedIndex(tabs.indexOf(tab));
236
+ setSelectedIndex(tabs.current.indexOf(tab));
237
237
  }
238
238
  }
239
239
  });
@@ -257,19 +257,25 @@ function TabList(_ref2) {
257
257
  }, []); // updates scroll location for all scroll behavior.
258
258
 
259
259
  useIsomorphicEffect["default"](function () {
260
- ref.current.scrollLeft = scrollLeft;
260
+ if (scrollLeft !== null) {
261
+ ref.current.scrollLeft = scrollLeft;
262
+ }
261
263
  }, [scrollLeft]);
262
264
  useIsomorphicEffect["default"](function () {
263
- var tab = activation === 'manual' ? tabs[activeIndex] : tabs[selectedIndex];
265
+ if (!isScrollable) {
266
+ return;
267
+ }
268
+
269
+ var tab = activation === 'manual' ? tabs.current[activeIndex] : tabs.current[selectedIndex];
264
270
 
265
271
  if (tab) {
266
272
  // The width of the "scroll buttons"
267
273
  // The start and end position of the selected tab
268
- var _tab$current$getBound = tab.current.getBoundingClientRect(),
269
- tabWidth = _tab$current$getBound.width;
274
+ var _tab$getBoundingClien = tab.getBoundingClientRect(),
275
+ tabWidth = _tab$getBoundingClien.width;
270
276
 
271
- var start = tab.current.offsetLeft;
272
- var end = tab.current.offsetLeft + tabWidth; // The start and end of the visible area for the tabs
277
+ var start = tab.offsetLeft;
278
+ var end = tab.offsetLeft + tabWidth; // The start and end of the visible area for the tabs
273
279
 
274
280
  var visibleStart = ref.current.scrollLeft + buttonWidth;
275
281
  var visibleEnd = ref.current.scrollLeft + ref.current.clientWidth - buttonWidth; // The beginning of the tab is clipped and not visible
@@ -283,13 +289,13 @@ function TabList(_ref2) {
283
289
  setScrollLeft(end + buttonWidth - ref.current.clientWidth);
284
290
  }
285
291
  }
286
- }, [activation, activeIndex, selectedIndex]);
292
+ }, [activation, activeIndex, selectedIndex, isScrollable]);
287
293
  usePressable.usePressable(previousButton, {
288
294
  onPress: function onPress(_ref3) {
289
295
  var longPress = _ref3.longPress;
290
296
 
291
297
  if (!longPress) {
292
- setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.length * 1.5, 0));
298
+ setScrollLeft(Math.max(scrollLeft - ref.current.scrollWidth / tabs.current.length * 1.5, 0));
293
299
  }
294
300
  },
295
301
  onLongPress: function onLongPress() {
@@ -301,7 +307,7 @@ function TabList(_ref2) {
301
307
  var longPress = _ref4.longPress;
302
308
 
303
309
  if (!longPress) {
304
- setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
310
+ setScrollLeft(Math.min(scrollLeft + ref.current.scrollWidth / tabs.current.length * 1.5, ref.current.scrollWidth - ref.current.clientWidth));
305
311
  }
306
312
  },
307
313
  onLongPress: function onLongPress() {
@@ -324,12 +330,12 @@ function TabList(_ref2) {
324
330
  onScroll: debouncedOnScroll,
325
331
  onKeyDown: onKeyDown
326
332
  }), React__default["default"].Children.map(children, function (child, index) {
327
- var ref = /*#__PURE__*/React__default["default"].createRef();
328
- tabs.push(ref);
329
333
  return /*#__PURE__*/React__default["default"].createElement(TabContext.Provider, {
330
334
  value: index
331
335
  }, /*#__PURE__*/React__default["default"].cloneElement(child, {
332
- ref: ref
336
+ ref: function ref(node) {
337
+ tabs.current[index] = node;
338
+ }
333
339
  }));
334
340
  })), /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({
335
341
  "aria-hidden": "true",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/react",
3
3
  "description": "React components for the Carbon Design System",
4
- "version": "1.3.0-rc.1",
4
+ "version": "1.3.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -46,7 +46,7 @@
46
46
  "@carbon/feature-flags": "^0.7.0",
47
47
  "@carbon/icons-react": "^11.3.0-rc.0",
48
48
  "@carbon/layout": "^11.2.0-rc.0",
49
- "@carbon/styles": "^1.3.0-rc.0",
49
+ "@carbon/styles": "^1.3.0",
50
50
  "@carbon/telemetry": "0.1.0",
51
51
  "classnames": "2.3.1",
52
52
  "copy-to-clipboard": "^3.3.1",
@@ -129,5 +129,5 @@
129
129
  "**/*.scss",
130
130
  "**/*.css"
131
131
  ],
132
- "gitHead": "8dac57d7a6f5c832675edb4d0316f247ff4230fc"
132
+ "gitHead": "df7ebd7676092998702f525cdef6d8d80c6ed9ad"
133
133
  }