--- url: /reference/items/DataScope/examples.md --- # Examples ## Isolated reusable widgets Sibling scopes remain independent even when they use the same group name. In the following example, each profile owns its `person` group and its own `$data` snapshot. Updating one profile does not update the other. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { DataComputed, DataModel, DataScope } from '@studiometa/ui'; registerComponent(DataScope); registerComponent(DataModel); registerComponent(DataComputed); ``` ::: ## Tabs The following example implements two independent tab interfaces with `DataScope`, [`Action`](../Action/index.md), [`DataModel`](../DataModel/index.md), and [`DataBind`](../DataBind/index.md). The tab buttons are mirrored models for the same `active` key: the first button hydrates the initial value, every button can publish a new value, and virtual bindings synchronize the selected state and panels. The `Tabs` component is not registered. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataModel, DataScope } from '@studiometa/ui'; registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataModel); registerComponent(Action); ``` ::: ## Accordion This example uses the same mirrored-model pattern for two independent accordion interfaces. Each button toggles the shared `active` key with [`toggle()`](../DataBind/js-api.md); opening one panel closes the other panels in that scope, and clicking the open item closes it. The `Accordion` component is not registered. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataModel, DataScope } from '@studiometa/ui'; registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataModel); registerComponent(Action); ``` ::: ## Dropdown menu The same disclosure pattern powers a dropdown menu. Each `DataScope` isolates one menu, so the two below toggle independently despite sharing the `menu` group name. The button is a mirrored [`DataModel`](../DataModel/index.md) that toggles the `open` key with [`toggle()`](../DataBind/js-api.md) and mirrors it onto `aria-expanded`, while the list is a [`DataBind`](../DataBind/index.md) that shows or hides itself. Esc closes the menu while the button is focused. No `Menu` component is registered. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Action, DataBind, DataModel, DataScope } from '@studiometa/ui'; registerComponent(DataScope); registerComponent(DataBind); registerComponent(DataModel); registerComponent(Action); ``` ::: ## Nested and explicit groups A Data component without `data-option-group` inherits the group of its nearest `DataScope`. An explicit group creates another group inside the same scope instead of escaping the scope. ```html
```