-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Shadow dom event handling #8991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Shadow dom event handling #8991
Conversation
These tests specifically target issue adobe#8675 where menu items in popovers close immediately instead when using ShadowDOM with UNSAFE_PortalProvider. New test suites added: - FocusScope: Shadow DOM boundary containment issues - usePopover: Shadow DOM popover interactions and focus management - useFocusWithin: Focus within detection across shadow boundaries - useInteractOutside: Interact outside detection with portals I generated these tests with AI then reviewed / updated them.
After applying the patches I mentioned in my issue I've noticed that many of the AI generated tests were either broken or just not testing anything interesting. Luckily there are some that are. I'll have to update the rest of the tests as they aren't passing at the moment.
I have a conflicting default prettier config (I can't seem to find this projects.) I'm reverting a number of my autochanges.
There are a bunch of redundant tests. Getting rid of them for now.
Co-authored-by: Robert Snow <[email protected]>
Co-authored-by: Robert Snow <[email protected]>
# Conflicts: # package.json # packages/@react-aria/combobox/src/useComboBox.ts # packages/react-aria-components/src/Popover.tsx
I haven't touched tests yet, but wanted to open this PR as a draft given the scope of what I've touched. I feel like I should scale back, as the size of the delta is scary, but at the same time, react-spectrum won't have shadow DOM support unless all bubbling event.target or node.contains calls are shadow-dom safe. I didn't touch changeEvents because they don't bubble. |
return event.composedPath()[0] as Element; | ||
export function getEventTarget<E, SE extends SyntheticEvent<E>>(event: SE): SE extends EventTargetType<infer Target> ? Target : never; | ||
export function getEventTarget(event: Event): EventTarget | null; | ||
export function getEventTarget<E, SE extends SyntheticEvent<E>>(event: Event | SE): EventTarget | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made two major enhancements to this function's Typescript definition:
- Use function overloading to give a more accurate return type when a SyntheticEvent is used. For example, the target for a
FocusEvent
isEventTarget & Target
. The first overload preserves that type, resulting in no need for type assertions in those situations compared to usingevent.target
. - If the event is a
Event
, then the return type isEventTarget | null
, which is consistent with the type definitions in @types/react. The existing implementation assumes that event.target isElement
. While is this true in most circumstances, I worry that glossing over the edge cases in this central function could have unforeseen runtime consequences.
``` | ||
|
||
It's likely that you are using a different version of Node.js. Please use Node.js 18. When changing the node version, delete `node_modules` and re-run `yarn install` | ||
It's likely that you are using a different version of Node.js. Please use Node.js 22. When changing the node version, delete `node_modules` and re-run `yarn install` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package.json has:
"@types/node@npm:*": "^22",
"@types/node@npm:^18.0.0": "^22",
"@types/node@npm:>= 8": "^22",
This implies that the recommended Node.js version has changed. If true, documentation should update as well.
"en-US" | ||
] | ||
], | ||
"volta": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Volta has been extremely helpful in my projects to standardize versions of node and yarn used by my developers. Hopefully this isn't an untoward addition to package.json.
Closes #8675
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: