-
-
Notifications
You must be signed in to change notification settings - Fork 883
Expand file tree
/
Copy pathuse-focus.tsx
More file actions
29 lines (26 loc) · 626 Bytes
/
use-focus.tsx
File metadata and controls
29 lines (26 loc) · 626 Bytes
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
import React from 'react';
import {Box, Text, render, useFocus} from '../../src/index.js';
function Focus() {
return (
<Box flexDirection="column" padding={1}>
<Box marginBottom={1}>
<Text>
Press Tab to focus next element, Shift+Tab to focus previous element,
Esc to reset focus.
</Text>
</Box>
<Item label="First" />
<Item label="Second" />
<Item label="Third" />
</Box>
);
}
function Item({label}: {readonly label: string}) {
const {isFocused} = useFocus();
return (
<Text>
{label} {isFocused ? <Text color="green">(focused)</Text> : null}
</Text>
);
}
render(<Focus />);