Skip to content

Commit

Permalink
Addressed review comments (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Mar 27, 2024
1 parent fad37c9 commit 290d2ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 7 additions & 7 deletions packages/components/src/spectrum/picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
isElementOfType,
usePopoverOnScrollRef,
} from '@deephaven/react-hooks';
import { PICKER_ITEM_HEIGHT, PICKER_TOP_OFFSET } from '@deephaven/utils';
import {
EMPTY_FUNCTION,
PICKER_ITEM_HEIGHT,
PICKER_TOP_OFFSET,
} from '@deephaven/utils';
import cl from 'classnames';
import { Tooltip } from '../../popper';
import {
Expand Down Expand Up @@ -45,7 +49,7 @@ export type PickerProps = {
*/
onChange?: (key: PickerItemKey) => void;

/** Handler that is called when the popover is scrolled. */
/** Handler that is called when the picker is scrolled. */
onScroll?: (event: Event) => void;

/**
Expand Down Expand Up @@ -87,10 +91,6 @@ function createTooltipContent(content: ReactNode) {
return content;
}

function noOp(): void {
// No-op
}

/**
* Picker component for selecting items from a list of items. Items can be
* provided via the `items` prop or as children. Each item can be a string,
Expand All @@ -106,7 +106,7 @@ export function Picker({
getInitialScrollPosition,
onChange,
onOpenChange,
onScroll = noOp,
onScroll = EMPTY_FUNCTION,
onSelectionChange,
// eslint-disable-next-line camelcase
UNSAFE_className,
Expand Down
14 changes: 12 additions & 2 deletions packages/jsapi-components/src/spectrum/Picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface PickerProps extends Omit<PickerPropsBase, 'children'> {
keyColumn?: string;
/* The column of values to display as primary text. Defaults to the `keyColumn` value. */
labelColumn?: string;

// TODO #1890 : descriptionColumn, iconColumn
}

export function Picker({
Expand Down Expand Up @@ -77,11 +79,19 @@ export function Picker({
// Set viewport to include the selected item so that its data will load and
// the real `key` will be available to show the selection in the UI.
function setViewportFromSelectedKey() {
let isCanceled = false;

getItemIndexByValue().then(index => {
if (index != null) {
setViewport(index);
if (index == null || isCanceled) {
return;
}

setViewport(index);
});

return () => {
isCanceled = true;
};
},
[getItemIndexByValue, setViewport]
);
Expand Down

0 comments on commit 290d2ff

Please sign in to comment.