Compare commits
1 Commits
362f4943d4
...
6a57c13c56
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a57c13c56 |
+11
-1
@@ -1,6 +1,16 @@
|
|||||||
export const targetFromEvent = (evt: Event, selector: string): Element | undefined => {
|
export const targetFromEvent = (evt: Event, selector: string): Element | undefined => {
|
||||||
const targets = evt.composedPath() as Element[];
|
const targets = evt.composedPath() as Element[];
|
||||||
return targets.find((target) => target.matches?.(selector));
|
if (targets.length > 0) {
|
||||||
|
return targets.find((target) => target.matches?.(selector));
|
||||||
|
}
|
||||||
|
// composedPath() is empty when the event is no longer dispatching (e.g. inside a
|
||||||
|
// portal-within-portal in React 19). Walk up the DOM from evt.target instead.
|
||||||
|
let el = evt.target instanceof Element ? evt.target : null;
|
||||||
|
while (el) {
|
||||||
|
if (el.matches(selector)) return el;
|
||||||
|
el = el.parentElement;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editableActiveElement = (): boolean =>
|
export const editableActiveElement = (): boolean =>
|
||||||
|
|||||||
Reference in New Issue
Block a user