(e: KeyboardEvent)
| 501 | }; |
| 502 | |
| 503 | let onKeyUp = (e: KeyboardEvent) => { |
| 504 | if (state.isPressed && state.target && isValidKeyboardEvent(e, state.target)) { |
| 505 | if (shouldPreventDefaultKeyboard(getEventTarget(e) as Element, e.key)) { |
| 506 | e.preventDefault(); |
| 507 | } |
| 508 | |
| 509 | let target = getEventTarget(e); |
| 510 | let wasPressed = nodeContains(state.target, target as Element); |
| 511 | // eslint-disable-next-line react-hooks/rules-of-hooks |
| 512 | triggerPressEndEvent(createEvent(state.target, e), 'keyboard', wasPressed); |
| 513 | if (wasPressed) { |
| 514 | triggerSyntheticClick(e, state.target); |
| 515 | } |
| 516 | removeAllGlobalListeners(); |
| 517 | |
| 518 | // If a link was triggered with a key other than Enter, open the URL ourselves. |
| 519 | // This means the link has a role override, and the default browser behavior |
| 520 | // only applies when using the Enter key. |
| 521 | if ( |
| 522 | e.key !== 'Enter' && |
| 523 | isHTMLAnchorLink(state.target) && |
| 524 | nodeContains(state.target, target as Element) && |
| 525 | !e[LINK_CLICKED] |
| 526 | ) { |
| 527 | // Store a hidden property on the event so we only trigger link click once, |
| 528 | // even if there are multiple usePress instances attached to the element. |
| 529 | e[LINK_CLICKED] = true; |
| 530 | openLink(state.target, e, false); |
| 531 | } |
| 532 | |
| 533 | state.isPressed = false; |
| 534 | state.metaKeyEvents?.delete(e.key); |
| 535 | } else if (e.key === 'Meta' && state.metaKeyEvents?.size) { |
| 536 | // If we recorded keydown events that occurred while the Meta key was pressed, |
| 537 | // and those haven't received keyup events already, fire keyup events ourselves. |
| 538 | // See comment above for more info about the macOS bug causing this. |
| 539 | let events = state.metaKeyEvents; |
| 540 | state.metaKeyEvents = undefined; |
| 541 | for (let event of events.values()) { |
| 542 | state.target?.dispatchEvent(new KeyboardEvent('keyup', event)); |
| 543 | } |
| 544 | } |
| 545 | }; |
| 546 | |
| 547 | if (typeof PointerEvent !== 'undefined') { |
| 548 | pressProps.onPointerDown = e => { |
nothing calls this directly
no test coverage detected