(e: BaseEvent<KeyboardEvent<any>>)
| 178 | |
| 179 | // For textfield specific keydown operations |
| 180 | let onKeyDown = (e: BaseEvent<KeyboardEvent<any>>) => { |
| 181 | if (e.nativeEvent.isComposing) { |
| 182 | return; |
| 183 | } |
| 184 | switch (e.key) { |
| 185 | case 'Enter': |
| 186 | case 'Tab': |
| 187 | // Prevent form submission if menu is open since we may be selecting a option |
| 188 | if (state.isOpen && e.key === 'Enter') { |
| 189 | e.preventDefault(); |
| 190 | } |
| 191 | |
| 192 | // If the focused item is a link, trigger opening it. Items that are links are not selectable. |
| 193 | if (state.isOpen && listBoxRef.current && state.selectionManager.focusedKey != null) { |
| 194 | let collectionItem = state.collection.getItem(state.selectionManager.focusedKey); |
| 195 | if (collectionItem?.props.href) { |
| 196 | let item = listBoxRef.current.querySelector( |
| 197 | `[data-key="${CSS.escape(state.selectionManager.focusedKey.toString())}"]` |
| 198 | ); |
| 199 | if (e.key === 'Enter' && item instanceof HTMLAnchorElement) { |
| 200 | router.open( |
| 201 | item, |
| 202 | e, |
| 203 | collectionItem.props.href, |
| 204 | collectionItem.props.routerOptions as RouterOptions |
| 205 | ); |
| 206 | } |
| 207 | state.close(); |
| 208 | break; |
| 209 | } else if (collectionItem?.props.onAction) { |
| 210 | collectionItem.props.onAction(); |
| 211 | state.close(); |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | if (e.key === 'Enter' || state.isOpen) { |
| 216 | state.commit(); |
| 217 | } |
| 218 | if (e.key === 'Tab') { |
| 219 | e.continuePropagation(); |
| 220 | } |
| 221 | |
| 222 | break; |
| 223 | case 'Escape': |
| 224 | if (!state.selectionManager.isEmpty || state.inputValue === '' || props.allowsCustomValue) { |
| 225 | e.continuePropagation(); |
| 226 | } |
| 227 | state.revert(); |
| 228 | break; |
| 229 | case 'ArrowDown': |
| 230 | state.open('first', 'manual'); |
| 231 | break; |
| 232 | case 'ArrowUp': |
| 233 | state.open('last', 'manual'); |
| 234 | break; |
| 235 | case 'ArrowLeft': |
| 236 | case 'ArrowRight': |
| 237 | state.selectionManager.setFocusedKey(null); |
nothing calls this directly
no test coverage detected