@react-aria/grid 3.6.2-nightly.3749 → 3.6.2-nightly.3757

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.
package/dist/import.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {getNthItem as $cVkRF$getNthItem, getChildNodes as $cVkRF$getChildNodes, getLastItem as $cVkRF$getLastItem, getFirstItem as $cVkRF$getFirstItem} from "@react-stately/collections";
2
2
  import {Rect as $cVkRF$Rect} from "@react-stately/virtualizer";
3
3
  import {useId as $cVkRF$useId, filterDOMProps as $cVkRF$filterDOMProps, mergeProps as $cVkRF$mergeProps, useUpdateEffect as $cVkRF$useUpdateEffect, useDescription as $cVkRF$useDescription, scrollIntoViewport as $cVkRF$scrollIntoViewport, getScrollParent as $cVkRF$getScrollParent} from "@react-aria/utils";
4
- import {useMemo as $cVkRF$useMemo, useRef as $cVkRF$useRef} from "react";
4
+ import {useMemo as $cVkRF$useMemo, useCallback as $cVkRF$useCallback, useRef as $cVkRF$useRef} from "react";
5
5
  import {useCollator as $cVkRF$useCollator, useLocale as $cVkRF$useLocale, useLocalizedStringFormatter as $cVkRF$useLocalizedStringFormatter} from "@react-aria/i18n";
6
6
  import {useSelectableCollection as $cVkRF$useSelectableCollection, useSelectableItem as $cVkRF$useSelectableItem} from "@react-aria/selection";
7
7
  import {announce as $cVkRF$announce} from "@react-aria/live-announcer";
@@ -950,6 +950,7 @@ function $5b9b5b5723db6ae1$export$be42ebdab07ae4c2(props) {
950
950
 
951
951
  function $83c6e2eafa584c67$export$f6b86a04e5d66d90(props, state, ref) {
952
952
  let { isVirtualized: isVirtualized , keyboardDelegate: keyboardDelegate , focusMode: focusMode , scrollRef: scrollRef , getRowText: getRowText , onRowAction: onRowAction , onCellAction: onCellAction } = props;
953
+ let { selectionManager: manager } = state;
953
954
  if (!props["aria-label"] && !props["aria-labelledby"]) console.warn("An aria-label or aria-labelledby prop is required for accessibility.");
954
955
  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
955
956
  // When virtualized, the layout object will be passed in as a prop and override this.
@@ -978,7 +979,7 @@ function $83c6e2eafa584c67$export$f6b86a04e5d66d90(props, state, ref) {
978
979
  ]);
979
980
  let { collectionProps: collectionProps } = (0, $cVkRF$useSelectableCollection)({
980
981
  ref: ref,
981
- selectionManager: state.selectionManager,
982
+ selectionManager: manager,
982
983
  keyboardDelegate: delegate,
983
984
  isVirtualized: isVirtualized,
984
985
  scrollRef: scrollRef
@@ -992,17 +993,37 @@ function $83c6e2eafa584c67$export$f6b86a04e5d66d90(props, state, ref) {
992
993
  }
993
994
  });
994
995
  let descriptionProps = (0, $5b9b5b5723db6ae1$export$be42ebdab07ae4c2)({
995
- selectionManager: state.selectionManager,
996
+ selectionManager: manager,
996
997
  hasItemActions: !!(onRowAction || onCellAction)
997
998
  });
998
999
  let domProps = (0, $cVkRF$filterDOMProps)(props, {
999
1000
  labelable: true
1000
1001
  });
1002
+ let onFocus = (0, $cVkRF$useCallback)((e)=>{
1003
+ if (manager.isFocused) {
1004
+ // If a focus event bubbled through a portal, reset focus state.
1005
+ if (!e.currentTarget.contains(e.target)) manager.setFocused(false);
1006
+ return;
1007
+ }
1008
+ // Focus events can bubble through portals. Ignore these events.
1009
+ if (!e.currentTarget.contains(e.target)) return;
1010
+ manager.setFocused(true);
1011
+ }, [
1012
+ manager
1013
+ ]);
1014
+ // Continue to track collection focused state even if keyboard navigation is disabled
1015
+ let navDisabledHandlers = (0, $cVkRF$useMemo)(()=>({
1016
+ onBlur: collectionProps.onBlur,
1017
+ onFocus: onFocus
1018
+ }), [
1019
+ onFocus,
1020
+ collectionProps.onBlur
1021
+ ]);
1001
1022
  let gridProps = (0, $cVkRF$mergeProps)(domProps, {
1002
1023
  role: "grid",
1003
1024
  id: id,
1004
- "aria-multiselectable": state.selectionManager.selectionMode === "multiple" ? "true" : undefined
1005
- }, state.isKeyboardNavigationDisabled ? {} : collectionProps, descriptionProps);
1025
+ "aria-multiselectable": manager.selectionMode === "multiple" ? "true" : undefined
1026
+ }, state.isKeyboardNavigationDisabled ? navDisabledHandlers : collectionProps, descriptionProps);
1006
1027
  if (isVirtualized) {
1007
1028
  gridProps["aria-rowcount"] = state.collection.size;
1008
1029
  gridProps["aria-colcount"] = state.collection.columnCount;
@@ -1238,6 +1259,18 @@ function $ab90dcbc1b5466d0$export$c7e10bfc0c59f67c(props, state, ref) {
1238
1259
  });
1239
1260
  var _node_colIndex;
1240
1261
  if (isVirtualized) gridCellProps["aria-colindex"] = ((_node_colIndex = node.colIndex) !== null && _node_colIndex !== void 0 ? _node_colIndex : node.index) + 1; // aria-colindex is 1-based
1262
+ // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the
1263
+ // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault
1264
+ // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.
1265
+ // To avoid this, remove the tabIndex from the cell briefly on pointer down.
1266
+ if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) gridCellProps.onPointerDown = (e)=>{
1267
+ let el = e.currentTarget;
1268
+ let tabindex = el.getAttribute("tabindex");
1269
+ el.removeAttribute("tabindex");
1270
+ requestAnimationFrame(()=>{
1271
+ el.setAttribute("tabindex", tabindex);
1272
+ });
1273
+ };
1241
1274
  return {
1242
1275
  gridCellProps: gridCellProps,
1243
1276
  isPressed: isPressed
package/dist/main.js CHANGED
@@ -962,6 +962,7 @@ function $340f2fcd0ef9ce8d$export$be42ebdab07ae4c2(props) {
962
962
 
963
963
  function $11d770dfabe45077$export$f6b86a04e5d66d90(props, state, ref) {
964
964
  let { isVirtualized: isVirtualized , keyboardDelegate: keyboardDelegate , focusMode: focusMode , scrollRef: scrollRef , getRowText: getRowText , onRowAction: onRowAction , onCellAction: onCellAction } = props;
965
+ let { selectionManager: manager } = state;
965
966
  if (!props["aria-label"] && !props["aria-labelledby"]) console.warn("An aria-label or aria-labelledby prop is required for accessibility.");
966
967
  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
967
968
  // When virtualized, the layout object will be passed in as a prop and override this.
@@ -990,7 +991,7 @@ function $11d770dfabe45077$export$f6b86a04e5d66d90(props, state, ref) {
990
991
  ]);
991
992
  let { collectionProps: collectionProps } = (0, $2oePb$reactariaselection.useSelectableCollection)({
992
993
  ref: ref,
993
- selectionManager: state.selectionManager,
994
+ selectionManager: manager,
994
995
  keyboardDelegate: delegate,
995
996
  isVirtualized: isVirtualized,
996
997
  scrollRef: scrollRef
@@ -1004,17 +1005,37 @@ function $11d770dfabe45077$export$f6b86a04e5d66d90(props, state, ref) {
1004
1005
  }
1005
1006
  });
1006
1007
  let descriptionProps = (0, $340f2fcd0ef9ce8d$export$be42ebdab07ae4c2)({
1007
- selectionManager: state.selectionManager,
1008
+ selectionManager: manager,
1008
1009
  hasItemActions: !!(onRowAction || onCellAction)
1009
1010
  });
1010
1011
  let domProps = (0, $2oePb$reactariautils.filterDOMProps)(props, {
1011
1012
  labelable: true
1012
1013
  });
1014
+ let onFocus = (0, $2oePb$react.useCallback)((e)=>{
1015
+ if (manager.isFocused) {
1016
+ // If a focus event bubbled through a portal, reset focus state.
1017
+ if (!e.currentTarget.contains(e.target)) manager.setFocused(false);
1018
+ return;
1019
+ }
1020
+ // Focus events can bubble through portals. Ignore these events.
1021
+ if (!e.currentTarget.contains(e.target)) return;
1022
+ manager.setFocused(true);
1023
+ }, [
1024
+ manager
1025
+ ]);
1026
+ // Continue to track collection focused state even if keyboard navigation is disabled
1027
+ let navDisabledHandlers = (0, $2oePb$react.useMemo)(()=>({
1028
+ onBlur: collectionProps.onBlur,
1029
+ onFocus: onFocus
1030
+ }), [
1031
+ onFocus,
1032
+ collectionProps.onBlur
1033
+ ]);
1013
1034
  let gridProps = (0, $2oePb$reactariautils.mergeProps)(domProps, {
1014
1035
  role: "grid",
1015
1036
  id: id,
1016
- "aria-multiselectable": state.selectionManager.selectionMode === "multiple" ? "true" : undefined
1017
- }, state.isKeyboardNavigationDisabled ? {} : collectionProps, descriptionProps);
1037
+ "aria-multiselectable": manager.selectionMode === "multiple" ? "true" : undefined
1038
+ }, state.isKeyboardNavigationDisabled ? navDisabledHandlers : collectionProps, descriptionProps);
1018
1039
  if (isVirtualized) {
1019
1040
  gridProps["aria-rowcount"] = state.collection.size;
1020
1041
  gridProps["aria-colcount"] = state.collection.columnCount;
@@ -1250,6 +1271,18 @@ function $cf2021be63b01ef4$export$c7e10bfc0c59f67c(props, state, ref) {
1250
1271
  });
1251
1272
  var _node_colIndex;
1252
1273
  if (isVirtualized) gridCellProps["aria-colindex"] = ((_node_colIndex = node.colIndex) !== null && _node_colIndex !== void 0 ? _node_colIndex : node.index) + 1; // aria-colindex is 1-based
1274
+ // When pressing with a pointer and cell selection is not enabled, usePress will be applied to the
1275
+ // row rather than the cell. However, when the row is draggable, usePress cannot preventDefault
1276
+ // on pointer down, so the browser will try to focus the cell which has a tabIndex applied.
1277
+ // To avoid this, remove the tabIndex from the cell briefly on pointer down.
1278
+ if (shouldSelectOnPressUp && gridCellProps.tabIndex != null && gridCellProps.onPointerDown == null) gridCellProps.onPointerDown = (e)=>{
1279
+ let el = e.currentTarget;
1280
+ let tabindex = el.getAttribute("tabindex");
1281
+ el.removeAttribute("tabindex");
1282
+ requestAnimationFrame(()=>{
1283
+ el.setAttribute("tabindex", tabindex);
1284
+ });
1285
+ };
1253
1286
  return {
1254
1287
  gridCellProps: gridCellProps,
1255
1288
  isPressed: isPressed