(e: PressEvent | LongPressEvent | PointerEvent)
| 143 | let router = useRouter(); |
| 144 | id = useId(id); |
| 145 | let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => { |
| 146 | if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) { |
| 147 | manager.toggleSelection(key); |
| 148 | } else { |
| 149 | if (manager.selectionMode === 'none') { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | if (manager.isLink(key)) { |
| 154 | if (linkBehavior === 'selection' && ref.current) { |
| 155 | let itemProps = manager.getItemProps(key); |
| 156 | router.open(ref.current, e, itemProps.href, itemProps.routerOptions); |
| 157 | // Always set selected keys back to what they were so that select and combobox close. |
| 158 | manager.setSelectedKeys(manager.selectedKeys); |
| 159 | return; |
| 160 | } else if (linkBehavior === 'override' || linkBehavior === 'none') { |
| 161 | return; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (manager.selectionMode === 'single') { |
| 166 | if (manager.isSelected(key) && !manager.disallowEmptySelection) { |
| 167 | manager.toggleSelection(key); |
| 168 | } else { |
| 169 | manager.replaceSelection(key); |
| 170 | } |
| 171 | } else if (e && e.shiftKey) { |
| 172 | manager.extendSelection(key); |
| 173 | } else if ( |
| 174 | manager.selectionBehavior === 'toggle' || |
| 175 | (e && (isCtrlKeyPressed(e) || e.pointerType === 'touch' || e.pointerType === 'virtual')) |
| 176 | ) { |
| 177 | // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys |
| 178 | manager.toggleSelection(key); |
| 179 | } else { |
| 180 | manager.replaceSelection(key); |
| 181 | } |
| 182 | } |
| 183 | }; |
| 184 | |
| 185 | // Focus the associated DOM node when this item becomes the focusedKey |
| 186 | // TODO: can't make this useLayoutEffect bacause it breaks menus inside dialogs |
no test coverage detected