Compare commits
9 Commits
97ef4b6436
...
ab971ab702
Author | SHA1 | Date |
---|---|---|
Audric Ackermann | ab971ab702 | 2 months ago |
Audric Ackermann | e58f88f1f0 | 2 months ago |
Audric Ackermann | 99562a5073 | 2 months ago |
Audric Ackermann | 1d71c00515 | 2 months ago |
Audric Ackermann | b887850388 | 2 months ago |
William Grant | 2265c59dcc | 2 months ago |
Audric Ackermann | 63fa2538fc | 2 months ago |
Audric Ackermann | 53aeb63894 | 2 months ago |
Audric Ackermann | 85c247eaf0 | 2 months ago |
@ -0,0 +1,21 @@
|
|||||||
|
import FocusTrap from 'focus-trap-react';
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import { useMount } from 'react-use';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Focus trap which activates on mount.
|
||||||
|
*/
|
||||||
|
export function SessionFocusTrap(props: { children: React.ReactNode }) {
|
||||||
|
const [active, setActive] = useState(false);
|
||||||
|
|
||||||
|
// Activate the trap on mount so we **should** have a button to tab through. focus-trap-react will throw if we don't have a button when the trap becomes active.
|
||||||
|
// We might still have an issue for dialogs which have buttons added with a useEffect, or asynchronously but have no buttons on mount.
|
||||||
|
// If that happens we will need to force those dialogs to have at least one button so focus-trap-react does not throw.
|
||||||
|
useMount(() => setActive(true));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FocusTrap active={active} focusTrapOptions={{ initialFocus: false, allowOutsideClick: true }}>
|
||||||
|
{props.children}
|
||||||
|
</FocusTrap>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue