@react-stately/grid
Advanced tools
Comparing version 3.0.0-nightly.2674 to 3.0.0-nightly.2677
@@ -19,7 +19,33 @@ var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends")); | ||
let { | ||
collection | ||
collection, | ||
focusMode | ||
} = props; | ||
let selectionState = useMultipleSelectionState(props); | ||
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]); // Reset focused key if that item is deleted from the collection. | ||
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]); | ||
let setFocusedKey = selectionState.setFocusedKey; | ||
selectionState.setFocusedKey = (key, child) => { | ||
// If focusMode is cell and an item is focused, focus a child cell instead. | ||
if (focusMode === 'cell' && key != null) { | ||
let item = collection.getItem(key); | ||
if ((item == null ? void 0 : item.type) === 'item') { | ||
let children = [...item.childNodes]; | ||
if (child === 'last') { | ||
var _children; | ||
key = (_children = children[children.length - 1]) == null ? void 0 : _children.key; | ||
} else { | ||
var _children$; | ||
key = (_children$ = children[0]) == null ? void 0 : _children$.key; | ||
} | ||
} | ||
} | ||
setFocusedKey(key, child); | ||
}; // Reset focused key if that item is deleted from the collection. | ||
useEffect(() => { | ||
@@ -26,0 +52,0 @@ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { |
@@ -6,7 +6,33 @@ import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends"; | ||
let { | ||
collection | ||
collection, | ||
focusMode | ||
} = props; | ||
let selectionState = useMultipleSelectionState(props); | ||
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]); // Reset focused key if that item is deleted from the collection. | ||
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]); | ||
let setFocusedKey = selectionState.setFocusedKey; | ||
selectionState.setFocusedKey = (key, child) => { | ||
// If focusMode is cell and an item is focused, focus a child cell instead. | ||
if (focusMode === 'cell' && key != null) { | ||
let item = collection.getItem(key); | ||
if ((item == null ? void 0 : item.type) === 'item') { | ||
let children = [...item.childNodes]; | ||
if (child === 'last') { | ||
var _children; | ||
key = (_children = children[children.length - 1]) == null ? void 0 : _children.key; | ||
} else { | ||
var _children$; | ||
key = (_children$ = children[0]) == null ? void 0 : _children$.key; | ||
} | ||
} | ||
} | ||
setFocusedKey(key, child); | ||
}; // Reset focused key if that item is deleted from the collection. | ||
useEffect(() => { | ||
@@ -13,0 +39,0 @@ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { |
@@ -13,2 +13,3 @@ import { GridCollection as _GridCollection1, GridNode, GridRow } from "@react-types/grid"; | ||
disabledKeys?: Iterable<Key>; | ||
focusMode?: 'row' | 'cell'; | ||
} | ||
@@ -15,0 +16,0 @@ export function useGridState<T extends object, C extends _GridCollection1<T>>(props: GridStateOptions<T, C>): GridState<T, C>; |
{ | ||
"name": "@react-stately/grid", | ||
"version": "3.0.0-nightly.2674+faa93480", | ||
"version": "3.0.0-nightly.2677+1e2b7f28", | ||
"description": "Spectrum UI components in React", | ||
@@ -21,5 +21,5 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-stately/selection": "3.0.0-nightly.994+faa93480", | ||
"@react-types/grid": "3.0.0-nightly.2674+faa93480", | ||
"@react-types/shared": "3.0.0-nightly.994+faa93480" | ||
"@react-stately/selection": "3.0.0-nightly.997+1e2b7f28", | ||
"@react-types/grid": "3.0.0-nightly.2677+1e2b7f28", | ||
"@react-types/shared": "3.0.0-nightly.997+1e2b7f28" | ||
}, | ||
@@ -32,3 +32,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "faa9348097bf62403e37e32daf897cdad5512e09" | ||
"gitHead": "1e2b7f280a04ead83e21b27fa580eb189e5f4186" | ||
} |
@@ -14,7 +14,8 @@ import {GridCollection} from '@react-types/grid'; | ||
collection: C, | ||
disabledKeys?: Iterable<Key> | ||
disabledKeys?: Iterable<Key>, | ||
focusMode?: 'row' | 'cell' | ||
} | ||
export function useGridState<T extends object, C extends GridCollection<T>>(props: GridStateOptions<T, C>): GridState<T, C> { | ||
let {collection} = props; | ||
let {collection, focusMode} = props; | ||
let selectionState = useMultipleSelectionState(props); | ||
@@ -25,2 +26,20 @@ let disabledKeys = useMemo(() => | ||
let setFocusedKey = selectionState.setFocusedKey; | ||
selectionState.setFocusedKey = (key, child) => { | ||
// If focusMode is cell and an item is focused, focus a child cell instead. | ||
if (focusMode === 'cell' && key != null) { | ||
let item = collection.getItem(key); | ||
if (item?.type === 'item') { | ||
let children = [...item.childNodes]; | ||
if (child === 'last') { | ||
key = children[children.length - 1]?.key; | ||
} else { | ||
key = children[0]?.key; | ||
} | ||
} | ||
} | ||
setFocusedKey(key, child); | ||
}; | ||
// Reset focused key if that item is deleted from the collection. | ||
@@ -27,0 +46,0 @@ useEffect(() => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
57005
563