Skip to content

Commit

Permalink
ItemSelection type (deephaven#1909)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 11, 2024
1 parent 9f4c1fb commit c964da7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/components/src/spectrum/listView/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import cl from 'classnames';
import {
ItemElementOrPrimitive,
ItemKey,
ItemSelection,
NormalizedItem,
normalizeItemList,
normalizeTooltipOptions,
Expand All @@ -36,7 +37,7 @@ export type ListViewProps = {
* `onSelectionChange`. We are renaming for better consistency with other
* components.
*/
onChange?: (keys: 'all' | Set<ItemKey>) => void;
onChange?: (keys: ItemSelection) => void;

/** Handler that is called when the picker is scrolled. */
onScroll?: (event: Event) => void;
Expand All @@ -45,7 +46,7 @@ export type ListViewProps = {
* Handler that is called when the selection changes.
* @deprecated Use `onChange` instead
*/
onSelectionChange?: (keys: 'all' | Set<ItemKey>) => void;
onSelectionChange?: (keys: ItemSelection) => void;
} & Omit<
SpectrumListViewProps<NormalizedItem>,
| 'children'
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/spectrum/utils/itemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type ItemOrSection = ItemElementOrPrimitive | SectionElement;
*/
export type ItemKey = Key | boolean;

export type ItemSelection = 'all' | Set<ItemKey>;

/**
* Augment the Spectrum selection change handler type to include boolean keys.
* Spectrum components already supports this, but the built in types don't
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Key, useCallback, useMemo } from 'react';
import { getItemKey, ItemKey, NormalizedItem } from './itemUtils';
import {
getItemKey,
ItemKey,
ItemSelection,
NormalizedItem,
} from './itemUtils';

function toStringKeySet(
keys?: 'all' | Iterable<ItemKey>
Expand All @@ -22,7 +27,7 @@ export interface UseStringifiedMultiSelectionOptions {
* `onSelectionChange`. We are renaming for better consistency with other
* components.
*/
onChange?: (keys: 'all' | Set<ItemKey>) => void;
onChange?: (keys: ItemSelection) => void;
}

export interface UseStringifiedMultiSelectionResult {
Expand Down

0 comments on commit c964da7

Please sign in to comment.