@carbon/react 1.85.0-rc.0 → 1.85.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.
Files changed (40) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +869 -799
  2. package/es/components/DatePicker/DatePicker.d.ts +1 -1
  3. package/es/components/DatePicker/DatePicker.js +2 -2
  4. package/es/components/DatePicker/plugins/appendToPlugin.d.ts +12 -0
  5. package/es/components/DatePicker/plugins/appendToPlugin.js +9 -12
  6. package/es/components/Menu/Menu.js +7 -2
  7. package/es/components/Menu/MenuItem.js +13 -2
  8. package/es/components/MultiSelect/FilterableMultiSelect.js +1 -1
  9. package/es/components/MultiSelect/filter.d.ts +10 -0
  10. package/es/components/MultiSelect/filter.js +21 -0
  11. package/es/components/Slider/Slider.d.ts +59 -198
  12. package/es/components/Slider/Slider.js +68 -120
  13. package/es/components/Tabs/usePressable.d.ts +19 -0
  14. package/es/components/Tabs/usePressable.js +19 -33
  15. package/es/components/Tooltip/Tooltip.d.ts +2 -2
  16. package/es/components/Tooltip/Tooltip.js +2 -2
  17. package/es/components/TreeView/TreeNode.d.ts +22 -0
  18. package/es/components/TreeView/TreeNode.js +116 -9
  19. package/es/components/UIShell/HeaderPanel.js +5 -7
  20. package/lib/components/DatePicker/DatePicker.d.ts +1 -1
  21. package/lib/components/DatePicker/DatePicker.js +1 -1
  22. package/lib/components/DatePicker/plugins/appendToPlugin.d.ts +12 -0
  23. package/lib/components/DatePicker/plugins/appendToPlugin.js +9 -12
  24. package/lib/components/Menu/Menu.js +7 -2
  25. package/lib/components/Menu/MenuItem.js +13 -2
  26. package/lib/components/MultiSelect/FilterableMultiSelect.js +1 -1
  27. package/lib/components/MultiSelect/filter.d.ts +10 -0
  28. package/lib/components/MultiSelect/filter.js +25 -0
  29. package/lib/components/Slider/Slider.d.ts +59 -198
  30. package/lib/components/Slider/Slider.js +67 -119
  31. package/lib/components/Tabs/usePressable.d.ts +19 -0
  32. package/lib/components/Tabs/usePressable.js +19 -33
  33. package/lib/components/Tooltip/Tooltip.d.ts +2 -2
  34. package/lib/components/Tooltip/Tooltip.js +2 -2
  35. package/lib/components/TreeView/TreeNode.d.ts +22 -0
  36. package/lib/components/TreeView/TreeNode.js +115 -8
  37. package/lib/components/UIShell/HeaderPanel.js +5 -7
  38. package/package.json +6 -6
  39. package/es/components/ComboBox/tools/filter.js +0 -18
  40. package/lib/components/ComboBox/tools/filter.js +0 -22
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React, { PureComponent } from 'react';
9
+ import React, { PureComponent, createRef } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
12
  import { ArrowDown, ArrowLeft, ArrowUp, ArrowRight, Enter } from '../../internal/keyboard/keys.js';
@@ -24,7 +24,7 @@ import { throttle } from '../../node_modules/es-toolkit/dist/compat/function/thr
24
24
  import { Text } from '../Text/Text.js';
25
25
 
26
26
  const ThumbWrapper = ({
27
- hasTooltip = false,
27
+ hasTooltip,
28
28
  className,
29
29
  style,
30
30
  children,
@@ -50,24 +50,6 @@ const ThumbWrapper = ({
50
50
  );
51
51
  }
52
52
  };
53
- ThumbWrapper.propTypes = {
54
- /**
55
- * The thumb node itself.
56
- */
57
- children: PropTypes.node,
58
- /**
59
- * CSS wrapper class names.
60
- */
61
- className: PropTypes.string,
62
- /**
63
- * Should the thumb show a tooltip with the current value?
64
- */
65
- hasTooltip: PropTypes.bool.isRequired,
66
- /**
67
- * Percentage offset for the select thumb value.
68
- */
69
- style: PropTypes.object
70
- };
71
53
  const translationIds = {
72
54
  autoCorrectAnnouncement: 'carbon.slider.auto-correct-announcement'
73
55
  };
@@ -86,27 +68,18 @@ function translateWithId(translationId, translationState) {
86
68
  return '';
87
69
  }
88
70
  const defaultFormatLabel = (value, label) => {
89
- return typeof label === 'function' ? label(value) : `${value}${label}`;
71
+ return `${value}${label ?? ''}`;
90
72
  };
91
73
 
74
+ // TODO: Assuming a 16ms throttle corresponds to 60 FPS, should it be halved,
75
+ // since many systems can handle 120 FPS? If it doesn't correspond to 60 FPS,
76
+ // what does it correspond to?
92
77
  /**
93
- * Minimum time between processed "drag" events.
94
- */
95
- const EVENT_THROTTLE = 16; // ms
96
-
97
- /**
98
- * Event types that trigger "drags".
78
+ * Minimum time between processed "drag" events in milliseconds.
99
79
  */
80
+ const EVENT_THROTTLE = 16;
100
81
  const DRAG_EVENT_TYPES = new Set(['mousemove', 'touchmove']);
101
-
102
- /**
103
- * Event types that trigger a "drag" to stop.
104
- */
105
82
  const DRAG_STOP_EVENT_TYPES = new Set(['mouseup', 'touchend', 'touchcancel']);
106
-
107
- /**
108
- * Distinguish two handles by lower and upper positions.
109
- */
110
83
  var HandlePosition = /*#__PURE__*/function (HandlePosition) {
111
84
  HandlePosition["LOWER"] = "lower";
112
85
  HandlePosition["UPPER"] = "upper";
@@ -123,7 +96,7 @@ class Slider extends PureComponent {
123
96
  needsOnRelease: false,
124
97
  isValid: true,
125
98
  isValidUpper: true,
126
- activeHandle: null,
99
+ activeHandle: undefined,
127
100
  correctedValue: null,
128
101
  correctedPosition: null,
129
102
  isRtl: false
@@ -134,12 +107,15 @@ class Slider extends PureComponent {
134
107
  _defineProperty(this, "element", null);
135
108
  _defineProperty(this, "inputId", '');
136
109
  _defineProperty(this, "track", void 0);
110
+ _defineProperty(this, "handleDrag", event => {
111
+ if (event instanceof globalThis.MouseEvent || event instanceof globalThis.TouchEvent) {
112
+ this.onDrag(event);
113
+ }
114
+ });
137
115
  /**
138
116
  * Sets up "drag" event handlers and calls `this.onDrag` in case dragging
139
117
  * started on somewhere other than the thumb without a corresponding "move"
140
118
  * event.
141
- *
142
- * @param {Event} evt The event.
143
119
  */
144
120
  _defineProperty(this, "onDragStart", evt => {
145
121
  // Do nothing if component is disabled
@@ -153,23 +129,23 @@ class Slider extends PureComponent {
153
129
  // @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#notes
154
130
  evt.preventDefault();
155
131
 
156
- // Register drag stop handlers
132
+ // Add drag stop handlers
157
133
  DRAG_STOP_EVENT_TYPES.forEach(element => {
158
134
  this.element?.ownerDocument.addEventListener(element, this.onDragStop);
159
135
  });
160
136
 
161
- // Register drag handlers
137
+ // Add drag handlers
162
138
  DRAG_EVENT_TYPES.forEach(element => {
163
- this.element?.ownerDocument.addEventListener(element, this.onDrag);
139
+ this.element?.ownerDocument.addEventListener(element, this.handleDrag);
164
140
  });
165
- const clientX = this.getClientXFromEvent(evt);
141
+ const clientX = this.getClientXFromEvent(evt.nativeEvent);
166
142
  let activeHandle;
167
143
  if (this.hasTwoHandles()) {
168
144
  if (evt.target == this.thumbRef.current) {
169
145
  activeHandle = HandlePosition.LOWER;
170
146
  } else if (evt.target == this.thumbRefUpper.current) {
171
147
  activeHandle = HandlePosition.UPPER;
172
- } else {
148
+ } else if (clientX) {
173
149
  const distanceToLower = this.calcDistanceToHandle(HandlePosition.LOWER, clientX);
174
150
  const distanceToUpper = this.calcDistanceToHandle(HandlePosition.UPPER, clientX);
175
151
  if (distanceToLower <= distanceToUpper) {
@@ -199,10 +175,10 @@ class Slider extends PureComponent {
199
175
 
200
176
  // Perform first recalculation since we probably didn't click exactly in the
201
177
  // middle of the thumb.
202
- this.onDrag(evt, activeHandle);
178
+ this.onDrag(evt.nativeEvent, activeHandle);
203
179
  });
204
180
  /**
205
- * Unregisters "drag" and "drag stop" event handlers and calls sets the flag
181
+ * Removes "drag" and "drag stop" event handlers and calls sets the flag
206
182
  * indicating that the `onRelease` callback should be called.
207
183
  */
208
184
  _defineProperty(this, "onDragStop", () => {
@@ -218,7 +194,7 @@ class Slider extends PureComponent {
218
194
 
219
195
  // Remove drag handlers
220
196
  DRAG_EVENT_TYPES.forEach(element => {
221
- this.element?.ownerDocument.removeEventListener(element, this.onDrag);
197
+ this.element?.ownerDocument.removeEventListener(element, this.handleDrag);
222
198
  });
223
199
 
224
200
  // Set needsOnRelease flag so event fires on next update.
@@ -232,12 +208,11 @@ class Slider extends PureComponent {
232
208
  * Handles a "drag" event by recalculating the value/thumb and setting state
233
209
  * accordingly.
234
210
  *
235
- * @param {Event} evt The event.
236
- * @param activeHandle
237
- * The first drag event call, we may have an explicit activeHandle value,
238
- * which is to be used before state is used.
211
+ * @param evt The event.
212
+ * @param activeHandle The first drag event call, we may have an explicit
213
+ * activeHandle value, which is to be used before state is used.
239
214
  */
240
- _defineProperty(this, "_onDrag", (evt, activeHandle = null) => {
215
+ _defineProperty(this, "_onDrag", (evt, activeHandle) => {
241
216
  activeHandle = activeHandle ?? this.state.activeHandle;
242
217
  // Do nothing if component is disabled, or we have no event.
243
218
  if (this.props.disabled || this.props.readOnly || !evt) {
@@ -281,8 +256,6 @@ class Slider extends PureComponent {
281
256
  /**
282
257
  * Handles a `keydown` event by recalculating the value/thumb and setting
283
258
  * state accordingly.
284
- *
285
- * @param {Event} evt The event.
286
259
  */
287
260
  _defineProperty(this, "onKeyDown", evt => {
288
261
  // Do nothing if component is disabled, or we don't have a valid event
@@ -345,8 +318,6 @@ class Slider extends PureComponent {
345
318
  * Provides the two-way binding for the input field of the Slider. It also
346
319
  * Handles a change to the input field by recalculating the value/thumb and
347
320
  * setting state accordingly.
348
- *
349
- * @param {Event} evt The event.
350
321
  */
351
322
  _defineProperty(this, "onChange", evt => {
352
323
  // Do nothing if component is disabled
@@ -396,8 +367,6 @@ class Slider extends PureComponent {
396
367
  /**
397
368
  * Checks for validity of input value after clicking out of the input. It also
398
369
  * Handles state change to isValid state.
399
- *
400
- * @param {Event} evt The event.
401
370
  */
402
371
  _defineProperty(this, "onBlur", evt => {
403
372
  // Do nothing if we have no valid event, target, or value
@@ -410,12 +379,12 @@ class Slider extends PureComponent {
410
379
  this.processNewInputValue(evt.target);
411
380
  this.props.onBlur?.({
412
381
  value: targetValue,
413
- handlePosition: evt.target?.dataset?.handlePosition
382
+ handlePosition: evt.target.dataset.handlePosition
414
383
  });
415
384
  });
416
385
  _defineProperty(this, "onInputKeyDown", evt => {
417
386
  // Do nothing if component is disabled, or we don't have a valid event.
418
- if (this.props.disabled || this.props.readOnly) {
387
+ if (this.props.disabled || this.props.readOnly || !(evt.target instanceof HTMLInputElement)) {
419
388
  return;
420
389
  }
421
390
 
@@ -438,7 +407,7 @@ class Slider extends PureComponent {
438
407
  // When there are two handles, we'll also have the data-handle-position
439
408
  // attribute to consider the other value before settling on the validity to
440
409
  // set.
441
- const handlePosition = input?.dataset?.handlePosition;
410
+ const handlePosition = input.dataset.handlePosition;
442
411
  if (handlePosition === HandlePosition.LOWER) {
443
412
  this.setState({
444
413
  isValid: validity
@@ -482,7 +451,7 @@ class Slider extends PureComponent {
482
451
  });
483
452
  if (handlePosition) {
484
453
  this.setValueLeftForHandle(handlePosition, {
485
- value,
454
+ value: this.nearestStepValue(value),
486
455
  left
487
456
  });
488
457
  } else {
@@ -511,7 +480,7 @@ class Slider extends PureComponent {
511
480
  if (clientX) {
512
481
  const leftOffset = this.state.isRtl ? (boundingRect?.right ?? 0) - clientX : clientX - (boundingRect?.left ?? 0);
513
482
  return leftOffset / width;
514
- } else if (value !== null && value !== undefined && range) {
483
+ } else if (value !== null && typeof value !== 'undefined' && range) {
515
484
  // Prevent NaN calculation if the range is 0.
516
485
  return range === 0 ? 0 : (value - this.props.min) / range;
517
486
  }
@@ -719,15 +688,15 @@ class Slider extends PureComponent {
719
688
  _defineProperty(this, "getHandleBoundingRect", handle => {
720
689
  let boundingRect;
721
690
  if (handle === HandlePosition.LOWER) {
722
- boundingRect = this?.thumbRef?.current?.getBoundingClientRect();
691
+ boundingRect = this.thumbRef.current?.getBoundingClientRect();
723
692
  } else {
724
- boundingRect = this?.thumbRefUpper?.current?.getBoundingClientRect();
693
+ boundingRect = this.thumbRefUpper.current?.getBoundingClientRect();
725
694
  }
726
695
  return boundingRect ?? new DOMRect();
727
696
  });
728
- this.thumbRef = /*#__PURE__*/React.createRef();
729
- this.thumbRefUpper = /*#__PURE__*/React.createRef();
730
- this.filledTrackRef = /*#__PURE__*/React.createRef();
697
+ this.thumbRef = /*#__PURE__*/createRef();
698
+ this.thumbRefUpper = /*#__PURE__*/createRef();
699
+ this.filledTrackRef = /*#__PURE__*/createRef();
731
700
  }
732
701
 
733
702
  /**
@@ -829,7 +798,7 @@ class Slider extends PureComponent {
829
798
  value: this.props.value,
830
799
  useRawValue: true
831
800
  }));
832
- if (this.props.unstable_valueUpper !== undefined) {
801
+ if (typeof this.props.unstable_valueUpper !== 'undefined') {
833
802
  const {
834
803
  value: valueUpper,
835
804
  left: leftUpper
@@ -870,7 +839,7 @@ class Slider extends PureComponent {
870
839
  return clientX;
871
840
  }
872
841
  hasTwoHandles() {
873
- return this.state.valueUpper !== undefined;
842
+ return typeof this.state.valueUpper !== 'undefined';
874
843
  }
875
844
 
876
845
  // syncs invalid state and prop
@@ -879,49 +848,17 @@ class Slider extends PureComponent {
879
848
  isValid,
880
849
  isValidUpper
881
850
  } = state;
882
- let derivedState = {};
851
+ const derivedState = {};
883
852
 
884
853
  // Will override state in favor of invalid prop
885
854
  if (props.invalid === true) {
886
- if (isValid === true) {
887
- derivedState = {
888
- ...derivedState,
889
- isValid: false
890
- };
891
- }
892
- if (isValid === true) {
893
- derivedState = {
894
- ...derivedState,
895
- isValid: false
896
- };
897
- }
898
- if (isValidUpper === true) {
899
- derivedState = {
900
- ...derivedState,
901
- isValidUpper: false
902
- };
903
- }
855
+ if (isValid === true) derivedState.isValid = false;
856
+ if (isValidUpper === true) derivedState.isValidUpper = false;
904
857
  } else if (props.invalid === false) {
905
- if (isValid === false) {
906
- derivedState = {
907
- ...derivedState,
908
- isValid: true
909
- };
910
- }
911
- if (isValid === false) {
912
- derivedState = {
913
- ...derivedState,
914
- isValid: true
915
- };
916
- }
917
- if (isValidUpper === false) {
918
- derivedState = {
919
- ...derivedState,
920
- isValidUpper: true
921
- };
922
- }
858
+ if (isValid === false) derivedState.isValid = true;
859
+ if (isValidUpper === false) derivedState.isValidUpper = true;
923
860
  }
924
- return Object.entries(derivedState).length > 0 ? derivedState : null;
861
+ return Object.keys(derivedState).length ? derivedState : null;
925
862
  }
926
863
  render() {
927
864
  var _Fragment, _Fragment2, _Fragment3, _Fragment4;
@@ -930,15 +867,22 @@ class Slider extends PureComponent {
930
867
  unstable_ariaLabelInputUpper: ariaLabelInputUpper,
931
868
  className,
932
869
  hideTextInput = false,
933
- id = this.inputId = this.inputId || `__carbon-slider_${Math.random().toString(36).substr(2)}`,
870
+ id = this.inputId = this.inputId ||
871
+ // TODO:
872
+ // 1. Why isn't `inputId` just set to this value instead of an empty
873
+ // string?
874
+ // 2. Why this value instead of something else, like
875
+ // `crypto.randomUUID()` or `useId()`?
876
+ `__carbon-slider_${Math.random().toString(36).substr(2)}`,
934
877
  min,
935
- minLabel = '',
878
+ minLabel,
936
879
  max,
937
- maxLabel = '',
880
+ maxLabel,
938
881
  formatLabel = defaultFormatLabel,
939
882
  labelText,
940
883
  hideLabel,
941
884
  step = 1,
885
+ // TODO: Other properties are deleted below. Why isn't this one?
942
886
  stepMultiplier: _stepMultiplier,
943
887
  inputType = 'number',
944
888
  invalidText,
@@ -966,8 +910,12 @@ class Slider extends PureComponent {
966
910
  correctedPosition,
967
911
  isRtl
968
912
  } = this.state;
969
- const showWarning = !readOnly && warn || typeof correctedValue !== null && correctedPosition === HandlePosition.LOWER && isValid;
970
- const showWarningUpper = !readOnly && warn || typeof correctedValue !== null && correctedPosition === (twoHandles ? HandlePosition.UPPER : HandlePosition.LOWER) && (twoHandles ? isValidUpper : isValid);
913
+ const showWarning = !readOnly && warn ||
914
+ // TODO: https://github.com/carbon-design-system/carbon/issues/18991#issuecomment-2795709637
915
+ typeof correctedValue !== null && correctedPosition === HandlePosition.LOWER && isValid;
916
+ const showWarningUpper = !readOnly && warn ||
917
+ // TODO: https://github.com/carbon-design-system/carbon/issues/18991#issuecomment-2795709637
918
+ typeof correctedValue !== null && correctedPosition === (twoHandles ? HandlePosition.UPPER : HandlePosition.LOWER) && (twoHandles ? isValidUpper : isValid);
971
919
  return /*#__PURE__*/React.createElement(PrefixContext.Consumer, null, prefix => {
972
920
  const labelId = `${id}-label`;
973
921
  const labelClasses = cx(`${prefix}--label`, {
@@ -1077,14 +1025,14 @@ class Slider extends PureComponent {
1077
1025
  }, other), /*#__PURE__*/React.createElement(ThumbWrapper, _extends({
1078
1026
  hasTooltip: hideTextInput,
1079
1027
  className: lowerThumbWrapperClasses,
1080
- label: `${formatLabel(value, '')}`,
1028
+ label: formatLabel(value, undefined),
1081
1029
  align: "top"
1082
1030
  }, lowerThumbWrapperProps), /*#__PURE__*/React.createElement("div", {
1083
1031
  className: lowerThumbClasses,
1084
1032
  role: "slider",
1085
1033
  id: twoHandles ? undefined : id,
1086
1034
  tabIndex: readOnly || disabled ? undefined : 0,
1087
- "aria-valuetext": `${formatLabel(value, '')}`,
1035
+ "aria-valuetext": formatLabel(value, undefined),
1088
1036
  "aria-valuemax": twoHandles ? valueUpper : max,
1089
1037
  "aria-valuemin": min,
1090
1038
  "aria-valuenow": value,
@@ -1105,7 +1053,7 @@ class Slider extends PureComponent {
1105
1053
  }))) : undefined)), twoHandles ? /*#__PURE__*/React.createElement(ThumbWrapper, _extends({
1106
1054
  hasTooltip: hideTextInput,
1107
1055
  className: upperThumbWrapperClasses,
1108
- label: `${formatLabel(valueUpper || 0, '')}`,
1056
+ label: formatLabel(valueUpper ?? 0, undefined),
1109
1057
  align: "top"
1110
1058
  }, upperThumbWrapperProps), /*#__PURE__*/React.createElement("div", {
1111
1059
  className: upperThumbClasses,
@@ -1180,7 +1128,9 @@ class Slider extends PureComponent {
1180
1128
  });
1181
1129
  }
1182
1130
  }
1183
- _defineProperty(Slider, "propTypes", {
1131
+ _defineProperty(Slider, "contextType", FeatureFlagContext);
1132
+ _defineProperty(Slider, "translationIds", Object.values(translationIds));
1133
+ Slider.propTypes = {
1184
1134
  /**
1185
1135
  * The `ariaLabel` for the `<input>`.
1186
1136
  */
@@ -1263,7 +1213,7 @@ _defineProperty(Slider, "propTypes", {
1263
1213
  */
1264
1214
  onChange: PropTypes.func,
1265
1215
  /**
1266
- * Provide an optional function to be called when a key is pressed in the number input
1216
+ * Provide an optional function to be called when a key is pressed in the number input.
1267
1217
  */
1268
1218
  onInputKeyUp: PropTypes.func,
1269
1219
  /**
@@ -1318,8 +1268,6 @@ _defineProperty(Slider, "propTypes", {
1318
1268
  * Provide the text that is displayed when the Slider is in a warn state
1319
1269
  */
1320
1270
  warnText: PropTypes.node
1321
- });
1322
- _defineProperty(Slider, "contextType", FeatureFlagContext);
1323
- Slider.translationIds = Object.values(translationIds);
1271
+ };
1324
1272
 
1325
1273
  export { Slider as default };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2025
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type RefObject } from 'react';
8
+ type UsePressableState = {
9
+ longPress: boolean;
10
+ };
11
+ type UsePressableOptions = {
12
+ onPress?: (state: UsePressableState) => void;
13
+ onPressIn?: () => void;
14
+ onPressOut?: (state: UsePressableState) => void;
15
+ onLongPress?: () => void;
16
+ delayLongPressMs?: number;
17
+ };
18
+ export declare const usePressable: (ref: RefObject<HTMLElement | null>, { onPress, onPressIn, onPressOut, onLongPress, delayLongPressMs, }?: UsePressableOptions) => void;
19
+ export {};
@@ -7,26 +7,13 @@
7
7
 
8
8
  import { useRef, useState, useEffect } from 'react';
9
9
 
10
- /* istanbul ignore file */
11
-
12
- /**
13
- * @param {React.RefObject<HTMLElement | null>} ref
14
- *
15
- * @param {{
16
- * onPress?(state: { longPress: boolean }): void,
17
- * onPressIn?(): void,
18
- * onPressOut?(): void,
19
- * onLongPress?(): void,
20
- * delayLongPressMs?: number,
21
- * }} options
22
- */
23
- function usePressable(ref, {
10
+ const usePressable = (ref, {
24
11
  onPress,
25
12
  onPressIn,
26
13
  onPressOut,
27
14
  onLongPress,
28
15
  delayLongPressMs = 500
29
- } = {}) {
16
+ } = {}) => {
30
17
  const savedOnPress = useRef(onPress);
31
18
  const savedOnPressIn = useRef(onPressIn);
32
19
  const savedOnPressOut = useRef(onPressOut);
@@ -49,55 +36,54 @@ function usePressable(ref, {
49
36
  savedOnLongPress.current = onLongPress;
50
37
  }, [onLongPress]);
51
38
  useEffect(() => {
52
- const {
53
- current: element
54
- } = ref;
39
+ const element = ref.current;
40
+ if (!element) return;
55
41
 
56
42
  // Fired when a pointer becomes active buttons state.
57
- function onPointerDown(event) {
43
+ const onPointerDown = event => {
58
44
  setPendingLongPress(true);
59
45
  savedOnPressIn.current?.();
60
46
  event.preventDefault();
61
- }
47
+ };
62
48
 
63
49
  // Fired when a pointer is no longer active buttons state.
64
- function onPointerUp() {
50
+ const onPointerUp = () => {
65
51
  setPendingLongPress(false);
66
52
  setLongPress(false);
67
53
  savedOnPressOut.current?.(state.current);
68
- }
54
+ };
69
55
 
70
56
  // A browser fires this event if it concludes the pointer
71
57
  // will no longer be able to generate events (for example
72
58
  // the related device is deactivated).
73
- function onPointerCancel() {
59
+ const onPointerCancel = () => {
74
60
  setPendingLongPress(false);
75
61
  setLongPress(false);
76
- savedOnPressOut.current?.();
62
+ savedOnPressOut.current?.(state.current);
77
63
  state.current.longPress = false;
78
- }
64
+ };
79
65
 
80
66
  // Fired when a pointer is moved out of the hit test
81
67
  // boundaries of an element. For pen devices, this event
82
68
  // is fired when the stylus leaves the hover range
83
69
  // detectable by the digitizer.
84
- function onPointerLeave() {
70
+ const onPointerLeave = () => {
85
71
  setPendingLongPress(false);
86
72
  setLongPress(false);
87
- savedOnPressOut.current?.();
73
+ savedOnPressOut.current?.(state.current);
88
74
  state.current.longPress = false;
89
- }
90
- function onClick() {
75
+ };
76
+ const onClick = () => {
91
77
  setLongPress(false);
92
78
  setPendingLongPress(false);
93
79
  savedOnPress.current?.(state.current);
94
80
  state.current.longPress = false;
95
- }
81
+ };
96
82
 
97
83
  // Certain devices treat long press events as context menu triggers
98
- function onContextMenu(event) {
84
+ const onContextMenu = event => {
99
85
  event.preventDefault();
100
- }
86
+ };
101
87
  element.addEventListener('pointerdown', onPointerDown);
102
88
  element.addEventListener('pointerup', onPointerUp);
103
89
  element.addEventListener('pointercancel', onPointerCancel);
@@ -130,6 +116,6 @@ function usePressable(ref, {
130
116
  return savedOnLongPress.current?.();
131
117
  }
132
118
  }, [longPress]);
133
- }
119
+ };
134
120
 
135
121
  export { usePressable };
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React from 'react';
7
+ import React, { type JSX } from 'react';
8
8
  import { Popover, PopoverAlignment } from '../Popover';
9
9
  import { PolymorphicComponentPropWithRef } from '../../internal/PolymorphicProps';
10
10
  interface TooltipBaseProps {
@@ -15,7 +15,7 @@ interface TooltipBaseProps {
15
15
  /**
16
16
  * Pass in the child to which the tooltip will be applied
17
17
  */
18
- children?: React.ReactElement<any>;
18
+ children?: React.ReactElement<JSX.IntrinsicElements[keyof JSX.IntrinsicElements]>;
19
19
  /**
20
20
  * Specify an optional className to be applied to the container node
21
21
  */
@@ -55,7 +55,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
55
55
 
56
56
  // An `aria-label` takes precedence over `aria-describedby`, but when it's
57
57
  // needed and the user doesn't specify one, the fallback `id` is used.
58
- const labelledBy = hasAriaLabel ? null : hasLabel ? ariaLabelledBy ?? id : undefined;
58
+ const labelledBy = hasAriaLabel ? undefined : hasLabel ? ariaLabelledBy ?? id : undefined;
59
59
 
60
60
  // If `aria-label` is present, use any provided `aria-describedby`.
61
61
  // If not, fallback to child's `aria-describedby` or the tooltip `id` if needed.
@@ -175,7 +175,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
175
175
  open: open
176
176
  }), /*#__PURE__*/React.createElement("div", {
177
177
  className: `${prefix}--tooltip-trigger__wrapper`
178
- }, child !== undefined ? /*#__PURE__*/React.cloneElement(child, {
178
+ }, typeof child !== 'undefined' ? /*#__PURE__*/React.cloneElement(child, {
179
179
  ...triggerProps,
180
180
  ...getChildEventHandlers(child.props)
181
181
  }) : null), /*#__PURE__*/React.createElement(PopoverContent, {
@@ -78,6 +78,17 @@ export type TreeNodeProps = {
78
78
  * Optional: The URL the TreeNode is linking to
79
79
  */
80
80
  href?: string;
81
+ /**
82
+ *
83
+ * Specify how the trigger should align with the tooltip when text is truncated
84
+ */
85
+ align?: 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-end' | 'left-start' | 'right-end' | 'right-start';
86
+ /**
87
+ * **Experimental**: Will attempt to automatically align the floating
88
+ * element to avoid collisions with the viewport and being clipped by
89
+ * ancestor elements.
90
+ */
91
+ autoAlign?: boolean;
81
92
  } & Omit<React.LiHTMLAttributes<HTMLElement>, 'onSelect'>;
82
93
  declare const TreeNode: React.ForwardRefExoticComponent<{
83
94
  /**
@@ -152,5 +163,16 @@ declare const TreeNode: React.ForwardRefExoticComponent<{
152
163
  * Optional: The URL the TreeNode is linking to
153
164
  */
154
165
  href?: string;
166
+ /**
167
+ *
168
+ * Specify how the trigger should align with the tooltip when text is truncated
169
+ */
170
+ align?: "top" | "bottom" | "left" | "right" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "left-end" | "left-start" | "right-end" | "right-start";
171
+ /**
172
+ * **Experimental**: Will attempt to automatically align the floating
173
+ * element to avoid collisions with the viewport and being clipped by
174
+ * ancestor elements.
175
+ */
176
+ autoAlign?: boolean;
155
177
  } & Omit<React.LiHTMLAttributes<HTMLElement>, "onSelect"> & React.RefAttributes<HTMLElement>>;
156
178
  export default TreeNode;