Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 10 additions & 3 deletions packages/@react-aria/grid/src/useGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export interface GridProps extends DOMProps, AriaLabelingProps {
/** Handler that is called when a user performs an action on the row. */
onRowAction?: (key: Key) => void,
/** Handler that is called when a user performs an action on the cell. */
onCellAction?: (key: Key) => void
onCellAction?: (key: Key) => void,
/**
* Whether the grid allows the user to clear all selected items via Escape.
* @default false
*/
disallowClearAll?: boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok naming... 😂

  • Should have selection in the name? like disallowClearSelection? but that's also not right, you can deselect individual items and end up with nothing selected.
  • Should it have something specifically about Escape in the name? disallowEscape? shouldDisableEscape? * More explicit: shouldEscapeClearSelection but then the default is true?
  • Non-boolean: escapeKeyBehavior = 'clearSelection' | 'none'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i kinda like the non-boolean the most, it's most informative

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of the non-boolean one too.

}

export interface GridAria {
Expand All @@ -77,7 +82,8 @@ export function useGrid<T>(props: GridProps, state: GridState<T, GridCollection<
scrollRef,
getRowText,
onRowAction,
onCellAction
onCellAction,
disallowClearAll = false
} = props;
let {selectionManager: manager} = state;

Expand Down Expand Up @@ -106,7 +112,8 @@ export function useGrid<T>(props: GridProps, state: GridState<T, GridCollection<
keyboardDelegate: delegate,
isVirtualized,
scrollRef,
disallowTypeAhead
disallowTypeAhead,
disallowClearAll
});

let id = useId(props.id);
Expand Down
13 changes: 10 additions & 3 deletions packages/@react-aria/gridlist/src/useGridList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export interface AriaGridListProps<T> extends GridListProps<T>, DOMProps, AriaLa
* via the left/right arrow keys or the tab key.
* @default 'arrow'
*/
keyboardNavigationBehavior?: 'arrow' | 'tab'
keyboardNavigationBehavior?: 'arrow' | 'tab',
/**
* Whether the gridlist allows the user to clear all selected items via Escape.
* @default false
*/
disallowClearAll?: boolean
}

export interface AriaGridListOptions<T> extends Omit<AriaGridListProps<T>, 'children'> {
Expand Down Expand Up @@ -105,7 +110,8 @@ export function useGridList<T>(props: AriaGridListOptions<T>, state: ListState<T
onAction,
disallowTypeAhead,
linkBehavior = 'action',
keyboardNavigationBehavior = 'arrow'
keyboardNavigationBehavior = 'arrow',
disallowClearAll = false
} = props;

if (!props['aria-label'] && !props['aria-labelledby']) {
Expand All @@ -124,7 +130,8 @@ export function useGridList<T>(props: AriaGridListOptions<T>, state: ListState<T
shouldFocusWrap: props.shouldFocusWrap,
linkBehavior,
disallowTypeAhead,
autoFocus: props.autoFocus
autoFocus: props.autoFocus,
disallowClearAll
});

let id = useId(props.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface AriaSelectableCollectionOptions {
* @default false
*/
disallowSelectAll?: boolean,
/**
* Whether the collection allows the user to clear all selected items via Escape.
* @default false
*/
disallowClearAll?: boolean,
/**
* Whether selection should occur automatically on focus.
* @default false
Expand Down Expand Up @@ -108,6 +113,7 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
shouldFocusWrap = false,
disallowEmptySelection = false,
disallowSelectAll = false,
disallowClearAll = false,
selectOnFocus = manager.selectionBehavior === 'replace',
disallowTypeAhead = false,
shouldUseVirtualFocus,
Expand Down Expand Up @@ -279,7 +285,7 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
}
break;
case 'Escape':
if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
if (!disallowClearAll && !disallowEmptySelection && manager.selectedKeys.size !== 0) {
e.stopPropagation();
e.preventDefault();
manager.clearSelection();
Expand Down
7 changes: 6 additions & 1 deletion packages/@react-types/listbox/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export interface AriaListBoxProps<T> extends AriaListBoxPropsBase<T> {
* Handler that is called when a user performs an action on an item. The exact user event depends on
* the collection's `selectionBehavior` prop and the interaction modality.
*/
onAction?: (key: Key) => void
onAction?: (key: Key) => void,
/**
* Whether the listbox allows the user to clear all selected items via Escape.
* @default false
*/
disallowClearAll?: boolean
}

export interface SpectrumListBoxProps<T> extends AriaListBoxPropsBase<T>, AsyncLoadable, StyleProps {
Expand Down
8 changes: 7 additions & 1 deletion packages/@react-types/menu/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ export interface MenuProps<T> extends CollectionBase<T>, MultipleSelection {
onClose?: () => void
}

export interface AriaMenuProps<T> extends MenuProps<T>, DOMProps, AriaLabelingProps {}
export interface AriaMenuProps<T> extends MenuProps<T>, DOMProps, AriaLabelingProps {
/**
* Whether the menu allows the user to clear all selected items via Escape.
* @default false
*/
disallowClearAll?: boolean
}
export interface SpectrumMenuProps<T> extends AriaMenuProps<T>, StyleProps {}

export interface SpectrumActionMenuProps<T> extends CollectionBase<T>, Omit<SpectrumMenuTriggerProps, 'children'>, StyleProps, DOMProps, AriaLabelingProps {
Expand Down
7 changes: 6 additions & 1 deletion packages/@react-types/table/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export interface TableProps<T> extends MultipleSelection, Sortable {
/** The elements that make up the table. Includes the TableHeader, TableBody, Columns, and Rows. */
children: [ReactElement<TableHeaderProps<T>>, ReactElement<TableBodyProps<T>>],
/** A list of row keys to disable. */
disabledKeys?: Iterable<Key>
disabledKeys?: Iterable<Key>,
/**
* Whether the table allows the user to clear all selected items via Escape.
* @default false
*/
disallowClearAll?: boolean
}

/**
Expand Down
Loading