-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathindex.tsx
More file actions
64 lines (52 loc) · 1.34 KB
/
index.tsx
File metadata and controls
64 lines (52 loc) · 1.34 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { type Component, createSignal, Switch, Match } from "solid-js";
import { autofocus, createAutofocus } from "../src/index.js";
autofocus;
const AutofocusDirective: Component = () => {
return (
<button autofocus use:autofocus>
directive
</button>
);
};
const AutofocusRef: Component = () => {
let ref!: HTMLButtonElement;
createAutofocus(() => ref);
return (
<button class="btn" ref={ref}>
ref
</button>
);
};
const AutofocusRefSignal: Component = () => {
const [ref, setRef] = createSignal<HTMLButtonElement>();
createAutofocus(ref);
return (
<button class="btn" ref={setRef}>
ref signal
</button>
);
};
const App: Component = () => {
const [toggle, setToggle] = createSignal(0);
return (
<div class="center-child h-screen w-screen">
<div class="m-4 flex gap-4">
<button class="btn" onClick={() => setToggle((toggle() + 1) % 6)}>
toggle
</button>
<Switch fallback={<button>no autofocus</button>}>
<Match when={toggle() === 0}>
<AutofocusDirective />
</Match>
<Match when={toggle() === 2}>
<AutofocusRef />
</Match>
<Match when={toggle() === 4}>
<AutofocusRefSignal />
</Match>
</Switch>
</div>
</div>
);
};
export default App;