Skip to content

Conversation

snowystinger
Copy link
Member

Closes #4350

Fixes issue where passing onKeyUp prevented onPress from being called.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

snowystinger and others added 3 commits December 6, 2023 17:29
@rspbot
Copy link

rspbot commented Dec 11, 2023

if (shouldStopPropagation) {
e.stopPropagation();
state.target?.dispatchEvent(new KeyboardEvent('keyup', {...e, bubbles: false}));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LFDanLu when do you anticipate this being hit? I'm not seeing it fail any of our current tests if I revert this line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, could've swore that without it I wasn't getting the onKeyDown attached to a button firing but it is working locally as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I remember now, I'm not sure why I removed the e.stopPropagation actually but IMO we should be stopping propagation of the keyup since usePress has handled it. The dispatch was there in order to try and get the keyUp on the button to still fire but it doesn't seem to work...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it should only stop it for the Enter and Space keys, everything else should go through
we don't allow through all the pointerDown/Up etc when we handle it, so I don't think there is a problem if we block the keyUp for those two keys?
The test I wrote shows that keyUp coming through, I actually thought that was a bit weird.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment the wrapping if statement that has isValidKeyboardEvent should already limit this block to only Enter/Space so readding the stopPropagation back above should be fine. However, adding it back in makes it so that keyUp doesn't fire on a Button when pressing Enter/Space even with the dispatchEvent, IMO if possible we should have keyUp on the same element handling the press still fire for Enter/Space but then stop at that level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, unfortunately we fail some others as a result.
I checked against pointerUp, and that does make it out, so I think your argument that keyUp should make it at least as far as pointerUp has merit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so we don't forget: after talking about this with the rest of the team, I think we can get rid of the dispatchEvent and stop propagation here. usePress has historically not stopped propagation of the keydown event technically since it happened at the window level on a non-capturing listener. useKeyboard should stop propagation where we need it to happen, all other cases should have onKeyUp continue bubbling

@rspbot
Copy link

rspbot commented Dec 11, 2023

@rspbot
Copy link

rspbot commented Dec 11, 2023

@rspbot
Copy link

rspbot commented Dec 12, 2023

see #5554 (comment),  essentialy it is ok that we dont stop propagation since we never have for keyup since it used to be a non capturing listener attached to the window
@rspbot
Copy link

rspbot commented Jan 11, 2024

@rspbot
Copy link

rspbot commented Jan 11, 2024

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse approval from @snowystinger :)

@rspbot
Copy link

rspbot commented Jan 17, 2024

@rspbot
Copy link

rspbot commented Jan 17, 2024

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@snowystinger snowystinger merged commit 55aca80 into main Jan 17, 2024
@snowystinger snowystinger deleted the adjust-usepress-event-order branch January 17, 2024 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Button onPress doesn't work using keyboard if onKeyUp is passed
4 participants