Skip to content

Commit 6de184c

Browse files
committed
docs: use prop atom directly in tabs example
ctx.props.$active is already a WritableAtom; drop the redundant local copy and the unused atom import.
1 parent 4a8aeee commit 6de184c

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

apps/docs/src/content/examples/tabs.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ <h3>Setup</h3>
4848
<script type="module" data-type="javascript">
4949
import { define } from "nanotags";
5050
import { createContext } from "nanotags/context";
51-
import { atom } from "nanostores";
5251
import { attachRovingFocus } from "attachRovingFocus.js";
5352

5453
const tabsContext = createContext("tabs");
@@ -60,22 +59,21 @@ <h3>Setup</h3>
6059
tabs: r.many("[role=tab]")
6160
}))
6261
.setup((ctx) => {
63-
const $active = atom(ctx.props.$active.get());
64-
62+
// ctx.props.$active is already a WritableAtom, so use it directly as state.
6563
attachRovingFocus(ctx, ctx.refs.tablist, ctx.refs.tabs, {
66-
onFocus: (el) => $active.set(el.dataset.value),
64+
onFocus: (el) => ctx.props.$active.set(el.dataset.value),
6765
});
6866

69-
ctx.on(ctx.refs.tabs, "click", (e) => $active.set(e.target.dataset.value));
70-
ctx.effect($active, (active) => {
67+
ctx.on(ctx.refs.tabs, "click", (e) => ctx.props.$active.set(e.target.dataset.value));
68+
ctx.effect(ctx.props.$active, (active) => {
7169
ctx.refs.tabs.forEach((tab) => {
7270
const selected = tab.dataset.value === active;
7371
tab.setAttribute("aria-selected", String(selected));
7472
tab.setAttribute("tabindex", selected ? "0" : "-1");
7573
});
7674
});
7775

78-
tabsContext.provide(ctx, { $active });
76+
tabsContext.provide(ctx, { $active: ctx.props.$active });
7977
});
8078

8179
define("x-tab-panel")

0 commit comments

Comments
 (0)