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