({
visibleOptionCount = 5,
options,
defaultValue,
onChange,
onCancel,
onFocus,
focusValue,
}: UseSelectStateProps<T>)
| 125 | } |
| 126 | |
| 127 | export function useSelectState<T>({ |
| 128 | visibleOptionCount = 5, |
| 129 | options, |
| 130 | defaultValue, |
| 131 | onChange, |
| 132 | onCancel, |
| 133 | onFocus, |
| 134 | focusValue, |
| 135 | }: UseSelectStateProps<T>): SelectState<T> { |
| 136 | const [value, setValue] = useState<T | undefined>(defaultValue) |
| 137 | |
| 138 | const navigation = useSelectNavigation<T>({ |
| 139 | visibleOptionCount, |
| 140 | options, |
| 141 | initialFocusValue: undefined, |
| 142 | onFocus, |
| 143 | focusValue, |
| 144 | }) |
| 145 | |
| 146 | const selectFocusedOption = useCallback(() => { |
| 147 | setValue(navigation.focusedValue) |
| 148 | }, [navigation.focusedValue]) |
| 149 | |
| 150 | return { |
| 151 | ...navigation, |
| 152 | value, |
| 153 | selectFocusedOption, |
| 154 | onChange, |
| 155 | onCancel, |
| 156 | } |
| 157 | } |
| 158 |
no test coverage detected