@basic-ui/core 0.0.44 → 0.0.45

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.
@@ -1153,30 +1153,53 @@ function useFocusManagement(lastActionType, inputRef) {
1153
1153
  });
1154
1154
  }
1155
1155
 
1156
- function getNextItem(currentItem, incr, optionsItems, autocomplete) {
1156
+ function getNextItem(currentItem, key, optionsItems, autocomplete) {
1157
+ const jumpToStartOrEnd = key === 'Home' || key === 'End';
1158
+ let incr = 1;
1159
+
1160
+ switch (key) {
1161
+ case 'PageUp':
1162
+ incr = -10;
1163
+ break;
1164
+
1165
+ case 'PageDown':
1166
+ incr = 10;
1167
+ break;
1168
+
1169
+ case 'End':
1170
+ case 'ArrowUp':
1171
+ incr = -1;
1172
+ break;
1173
+
1174
+ case 'Home':
1175
+ case 'ArrowDown':
1176
+ incr = 1;
1177
+ break;
1178
+ }
1179
+
1157
1180
  const index = currentItem === '' ? -1 : optionsItems.findIndex(n => String(n.id) === currentItem);
1158
1181
  const optionsLen = optionsItems.length; // Nothing selected, either go to start, or end
1159
1182
 
1160
- if (index < 0) {
1183
+ if (index < 0 || jumpToStartOrEnd) {
1161
1184
  if (incr > 0) {
1162
1185
  // Go to start
1163
- return optionsItems[0].id;
1186
+ return optionsItems[0];
1164
1187
  } else {
1165
1188
  // Go to end
1166
- return optionsItems[optionsLen - 1].id;
1189
+ return optionsItems[optionsLen - 1];
1167
1190
  }
1168
1191
  } else if (autocomplete) {
1169
1192
  const nextIndex = index + incr;
1170
1193
 
1171
1194
  if (nextIndex < 0 || nextIndex >= optionsLen) {
1172
1195
  // Next is outside the bounds of list, return nothing selected
1173
- return '';
1196
+ return null;
1174
1197
  }
1175
1198
  } // I'm sure it won't be null, we already check optionsLen above
1176
1199
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1177
1200
 
1178
1201
 
1179
- return optionsItems[getCircularIndex(index + incr, optionsLen)].id;
1202
+ return optionsItems[getCircularIndex(index + incr, optionsLen)];
1180
1203
  } // We want the same events when the input or the popup have focus (HOW COOL ARE
1181
1204
  // HOOKS BTW?) This is probably the hairiest piece but it's not bad.
1182
1205
 
@@ -1201,6 +1224,10 @@ function useKeyDown() {
1201
1224
  const optionNodes = listScope.current.queryAllNodes(scopeQuery$1);
1202
1225
 
1203
1226
  switch (event.key) {
1227
+ case 'Home':
1228
+ case 'End':
1229
+ case 'PageUp':
1230
+ case 'PageDown':
1204
1231
  case 'ArrowUp':
1205
1232
  case 'ArrowDown':
1206
1233
  {
@@ -1220,17 +1247,26 @@ function useKeyDown() {
1220
1247
  persistSelection: persistSelectionRef.current
1221
1248
  });
1222
1249
  } else {
1223
- // ArrowUp decreases index, ArrowDown increases
1224
- const incr = event.key === 'ArrowUp' ? -1 : 1; // When autocompletting, we'll not cycle through the list directly
1225
-
1250
+ // When autocompletting, we'll not cycle through the list directly
1226
1251
  const autocomplete = autocompletePropRef.current; // Get next selected item
1227
1252
 
1228
- const nextItem = getNextItem(navigationItem, incr, optionNodes, autocomplete);
1229
- const value = nextItem !== '' ? optionsRef.current[nextItem].text : null;
1230
- transition(NAVIGATE, {
1231
- value,
1232
- item: nextItem
1233
- });
1253
+ const nextItem = getNextItem(navigationItem, event.key, optionNodes, autocomplete);
1254
+
1255
+ if (nextItem !== null) {
1256
+ nextItem.scrollIntoView({
1257
+ behavior: 'auto',
1258
+ block: 'nearest'
1259
+ });
1260
+ transition(NAVIGATE, {
1261
+ value: optionsRef.current[nextItem.id].text,
1262
+ item: nextItem.id
1263
+ });
1264
+ } else {
1265
+ transition(NAVIGATE, {
1266
+ value: null,
1267
+ item: ''
1268
+ });
1269
+ }
1234
1270
  }
1235
1271
 
1236
1272
  break;
@@ -2478,27 +2514,7 @@ const RadioGroup = /*#__PURE__*/react.forwardRef(function RadioGroup(props, forw
2478
2514
  });
2479
2515
  });
2480
2516
 
2481
- /**
2482
- * Welcome to @reach/slider!
2483
- *
2484
- * A UI input component where the user selects a value from within a given
2485
- * range. A Slider has a handle that can be moved along a track to change its
2486
- * value. When the user's mouse or focus is on the Slider's handle, the value
2487
- * can be incremented with keyboard controls.
2488
- *
2489
- * Random thoughts/notes:
2490
- * - Currently testing this against the behavior of the native input range
2491
- * element to get our slider on par. We'll explore animated and multi-handle
2492
- * sliders next.
2493
- * - We may want to research some use cases for reversed sliders in RTL
2494
- * languages if that's a thing
2495
- *
2496
- * @see Docs https://reach.tech/slider
2497
- * @see Source https://github.com/reach/reach-ui/tree/main/packages/slider
2498
- * @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2/#slider
2499
- * @see Example https://github.com/Stanko/aria-progress-range-slider
2500
- * @see Example http://www.oaa-accessibility.org/examplep/slider1/
2501
- */
2517
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2502
2518
 
2503
2519
  const noop = () => {
2504
2520
  /* noop */
@@ -2544,6 +2560,7 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
2544
2560
  'aria-labelledby': ariaLabelledBy,
2545
2561
  'aria-valuetext': ariaValueTextProp,
2546
2562
  as: Comp = 'div',
2563
+ innerAs,
2547
2564
  defaultValue,
2548
2565
  disabled = false,
2549
2566
  value: controlledValue,
@@ -2866,6 +2883,8 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
2866
2883
  rangeStyle: rangeStyle,
2867
2884
  updateValue: onChange,
2868
2885
  children: /*#__PURE__*/jsxRuntime.jsxs(Comp, { ...rest,
2886
+ // @ts-ignore
2887
+ as: innerAs,
2869
2888
  ref: assignMultipleRefs(sliderRef, forwardedRef),
2870
2889
  "data-reach-slider-input": "",
2871
2890
  "data-disabled": disabled ? '' : undefined,
@@ -2906,6 +2925,7 @@ const SliderInput = /*#__PURE__*/react.forwardRef(function SliderInput({
2906
2925
  */
2907
2926
  const SliderTrackImpl = /*#__PURE__*/react.forwardRef(function SliderTrack({
2908
2927
  as: Comp = 'div',
2928
+ innerAs,
2909
2929
  children,
2910
2930
  style = {},
2911
2931
  ...props
@@ -2916,7 +2936,9 @@ const SliderTrackImpl = /*#__PURE__*/react.forwardRef(function SliderTrack({
2916
2936
  trackRef
2917
2937
  } = useSliderContext('SliderTrack');
2918
2938
  return /*#__PURE__*/jsxRuntime.jsx(Comp, {
2919
- ref: assignMultipleRefs(trackRef, forwardedRef),
2939
+ ref: assignMultipleRefs(trackRef, forwardedRef) // @ts-ignore
2940
+ ,
2941
+ as: innerAs,
2920
2942
  style: { ...style,
2921
2943
  position: 'relative'
2922
2944
  },
@@ -2944,6 +2966,7 @@ const SliderTrack = /*#__PURE__*/react.memo(SliderTrackImpl);
2944
2966
  */
2945
2967
  const SliderRangeImpl = /*#__PURE__*/react.forwardRef(function SliderRange({
2946
2968
  as: Comp = 'div',
2969
+ innerAs,
2947
2970
  children,
2948
2971
  style = {},
2949
2972
  ...props
@@ -2954,7 +2977,9 @@ const SliderRangeImpl = /*#__PURE__*/react.forwardRef(function SliderRange({
2954
2977
  rangeStyle
2955
2978
  } = useSliderContext('SliderRange');
2956
2979
  return /*#__PURE__*/jsxRuntime.jsx(Comp, {
2957
- ref: forwardedRef,
2980
+ ref: forwardedRef // @ts-ignore
2981
+ ,
2982
+ as: innerAs,
2958
2983
  style: {
2959
2984
  position: 'absolute',
2960
2985
  ...rangeStyle,
@@ -2988,6 +3013,7 @@ const SliderHandleImpl = /*#__PURE__*/react.forwardRef(function SliderHandle({
2988
3013
  // min,
2989
3014
  // max,
2990
3015
  as: Comp = 'div',
3016
+ innerAs,
2991
3017
  onBlur,
2992
3018
  onFocus,
2993
3019
  style = {},
@@ -3009,7 +3035,9 @@ const SliderHandleImpl = /*#__PURE__*/react.forwardRef(function SliderHandle({
3009
3035
  sliderMax,
3010
3036
  value
3011
3037
  } = useSliderContext('SliderHandle');
3012
- return /*#__PURE__*/jsxRuntime.jsx(Comp, {
3038
+ return /*#__PURE__*/jsxRuntime.jsx(Comp // @ts-ignore
3039
+ , {
3040
+ as: innerAs,
3013
3041
  "aria-disabled": disabled || undefined // If the slider has a visible label, it is referenced by
3014
3042
  // `aria-labelledby` on the slider element. Otherwise, the slider
3015
3043
  // element has a label provided by `aria-label`.
@@ -3086,6 +3114,7 @@ const SliderHandle = /*#__PURE__*/react.memo(SliderHandleImpl);
3086
3114
  */
3087
3115
  const SliderMarkerImpl = /*#__PURE__*/react.forwardRef(function SliderMarker({
3088
3116
  as: Comp = 'div',
3117
+ innerAs,
3089
3118
  children,
3090
3119
  style = {},
3091
3120
  value,
@@ -3099,11 +3128,13 @@ const SliderMarkerImpl = /*#__PURE__*/react.forwardRef(function SliderMarker({
3099
3128
  sliderMax,
3100
3129
  value: sliderValue
3101
3130
  } = useSliderContext('SliderMarker');
3102
- const inRange = !(value < sliderMin || value > sliderMax);
3131
+ const inRange = value >= sliderMin && value <= sliderMax;
3103
3132
  const absoluteStartPosition = `${valueToPercent(value, sliderMin, sliderMax)}%`;
3104
3133
  const state = value < sliderValue ? 'under-value' : value === sliderValue ? 'at-value' : 'over-value';
3105
3134
  return inRange ? /*#__PURE__*/jsxRuntime.jsx(Comp, {
3106
- ref: forwardedRef,
3135
+ ref: forwardedRef // @ts-ignore
3136
+ ,
3137
+ as: innerAs,
3107
3138
  style: {
3108
3139
  position: 'absolute',
3109
3140
  ...(isVertical ? {