-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathfocus.tsx
More file actions
42 lines (36 loc) · 1.1 KB
/
focus.tsx
File metadata and controls
42 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React, { useRef } from 'react';
import {} from '../../src';
import { useLockFocus } from '../../src/Dom/focus';
import './focus.css';
export default function FocusDemo() {
const containerRef = useRef<HTMLDivElement>(null);
const [locking, setLocking] = React.useState(true);
useLockFocus(locking, () => containerRef.current);
return (
<div style={{ padding: 32 }} className="focus-demo">
<h2>Focus Utils Demo</h2>
{/* External buttons */}
<button onClick={() => setLocking(!locking)}>
Lock ({String(locking)})
</button>
{/* Middle container - Tab key cycling is limited within this area */}
<div
ref={containerRef}
tabIndex={0}
style={{
border: '2px solid green',
padding: 24,
margin: 16,
borderRadius: 8,
backgroundColor: '#f0f8ff',
}}
>
<button>Container Button 1</button>
<button>Container Button 2</button>
<button>Container Button 3</button>
</div>
{/* External buttons */}
<button>External Button 2</button>
</div>
);
}