Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/@react-aria/selection/src/useSelectableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ref, key, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);

isDisabled = isDisabled || manager.isDisabled(key);
// Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
// item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
// on iOS 14 doesn't try to move real DOM focus to the item anyway.
let itemProps: SelectableItemAria['itemProps'] = {};
if (!shouldUseVirtualFocus) {
if (!shouldUseVirtualFocus && !isDisabled) {
itemProps = {
tabIndex: key === manager.focusedKey ? 0 : -1,
onFocus(e) {
Expand All @@ -160,14 +161,17 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
}
}
};
} else if (isDisabled) {
itemProps.onMouseDown = (e) => {
// Prevent focus going to the body when clicking on a disabled item.
e.preventDefault();
};
}


// With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.
// Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.
// With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.
// With touch, onAction occurs on single tap, and long press enters selection mode.
isDisabled = isDisabled || manager.isDisabled(key);
let allowsSelection = !isDisabled && manager.canSelectItem(key);
let allowsActions = onAction && !isDisabled;
let hasPrimaryAction = allowsActions && (
Expand Down
10 changes: 10 additions & 0 deletions packages/@react-spectrum/picker/stories/Picker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ storiesOf('Picker', module)
</Picker>
)
)
.add(
'disabled keys',
() => (
<Picker label="Test" onSelectionChange={action('selectionChange')} disabledKeys={['Short']}>
<Item key="Short">Short</Item>
<Item key="Normal">Normal</Item>
<Item key="This item is very long and word wraps poorly">This item is very long and word wraps poorly</Item>
</Picker>
)
)
.add(
'sections',
() => (
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-stately/table/src/useTableState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function useTableState<T extends object>(props: TableStateProps<T>): Tabl
(nodes, prev) => new TableCollection(nodes, prev, context),
context
);
let {disabledKeys, selectionManager} = useGridState({...props, collection});
let {disabledKeys, selectionManager} = useGridState({...props, collection, disabledBehavior: 'selection'});

return {
collection,
Expand Down