Skip to content

Commit

Permalink
Comments (deephaven#2065)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jun 12, 2024
1 parent 809662a commit 18108c2
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface UseOnChangeTrackUncontrolledResult<TChangeKey> {
onChangeMaybeUncontrolled: (key: TChangeKey) => void;
}

/**
* Returns a selectedKey and onChange handler that can manage selection for both
* controlled and uncontrolled components. Useful for cases where the component
* needs to know the last selectedKey regardless of controlled or uncontrolled.
*/
export function useOnChangeTrackUncontrolled<TChangeKey>({
defaultSelectedKey,
selectedKey,
Expand All @@ -27,7 +32,6 @@ export function useOnChangeTrackUncontrolled<TChangeKey>({
const onChangeMaybeUncontrolled = useCallback(
(key: TChangeKey): void => {
// If our component is uncontrolled, track the selected key internally
// so that we can scroll to the selected item if the user re-opens
if (isUncontrolled) {
setUncontrolledSelectedKey(key);
}
Expand All @@ -38,11 +42,9 @@ export function useOnChangeTrackUncontrolled<TChangeKey>({
);

return {
// isUncontrolled,
selectedKeyMaybeUncontrolled: isUncontrolled
? uncontrolledSelectedKey
: selectedKey,
// uncontrolledSelectedKey,
onChangeMaybeUncontrolled,
};
}
Expand Down

0 comments on commit 18108c2

Please sign in to comment.