Render incoming Reactions
This commit is contained in:
parent
b113eb19f0
commit
6cc0f2abce
25 changed files with 1411 additions and 134 deletions
26
ts/components/hooks.ts
Normal file
26
ts/components/hooks.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import * as React from 'react';
|
||||
|
||||
// Restore focus on teardown
|
||||
export const useRestoreFocus = (
|
||||
// The ref for the element to receive initial focus
|
||||
focusRef: React.RefObject<any>,
|
||||
// Allow for an optional root element that must exist
|
||||
root: boolean | HTMLElement | null = true
|
||||
) => {
|
||||
React.useEffect(() => {
|
||||
if (!root) {
|
||||
return;
|
||||
}
|
||||
|
||||
const lastFocused = document.activeElement as any;
|
||||
if (focusRef.current) {
|
||||
focusRef.current.focus();
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (lastFocused && lastFocused.focus) {
|
||||
lastFocused.focus();
|
||||
}
|
||||
};
|
||||
}, [focusRef, root]);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue