Skip to content

Commit 27df81d

Browse files
committed
Update Headless UI docs page
1 parent d4d445c commit 27df81d

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/routes/docs/latest/tailwind-ui.svx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ Many Tailwind UI examples use the [heroicons](https://heroicons.com/) icon libra
1616

1717
The React library uses a `.` in the names of many components: `Tab.Group`, `Listbox.Button`, etc. The Svelte library does not use this pattern and instead exports every component under its own name with no dot: `TabGroup`, `ListboxButton`, etc.
1818

19+
### Managing component state
20+
21+
A few components in this library use the `bind:` directive to bind data from the component. For example, a `Switch` has a `checked` prop which the component will modify when the Switch is toggled. As React does not have two-way binding, React code instead uses a `onChange` callback function.
22+
23+
```jsx
24+
// React example
25+
<Switch checked={enabled} onChange={setEnabled}>
26+
// ...
27+
</Switch>
28+
```
29+
30+
becomes:
31+
32+
```svelte
33+
<!-- Svelte equivalent -->
34+
<Switch bind:checked={enabled}>
35+
// ...
36+
</Switch>
37+
```
38+
1939
### `useState`
2040

2141
State declared with `useState` in React becomes just a normal variable in Svelte:
@@ -48,6 +68,8 @@ becomes
4868
</Switch>
4969
```
5070

71+
This is new in version 2.0 of this library. The previous version also used an event callback to set this data.
72+
5173
### JSX camelCased attribute names
5274

5375
In React, some HTML attributes have different names from the standard ones that are used in Svelte. These are covered in the [React documentation](https://reactjs.org/docs/dom-elements.html#differences-in-attributes), but we repeat the most important differences here:
@@ -119,21 +141,6 @@ In Svelte, you instead use the `on:` directive:
119141
</Dialog>
120142
```
121143

122-
Furthermore, in the React library, event handlers will be called with the their data directly:
123-
124-
```jsx
125-
<Listbox value={selectedPerson} onChange={setSelectedPerson}>
126-
// ...
127-
</Listbox>
128-
```
129-
130-
In the Svelte version, your handler will be passed a `CustomEvent` object, and you need to look at its `.detail` property:
131-
```svelte
132-
<Listbox value={selectedPerson} on:change={(e) => selectedPerson = e.detail}>
133-
<!-- ... -->
134-
</Listbox>
135-
```
136-
137144
### Render props
138145

139146
The React components make use of render props:
@@ -232,7 +239,7 @@ Tailwind UI frequenty does iteration using `Array.prototype.map()`:
232239
In Svelte, you accomplish this by using the `{#each}` template syntax:
233240

234241
```svelte
235-
<Listbox value={selectedPerson} on:change={(e) => selectedPerson = e.detail}>
242+
<Listbox bind:value={selectedPerson}>
236243
<ListboxButton>{selectedPerson.name}</ListboxButton>
237244
<ListboxOptions>
238245
{#each people as person (person.id)}

0 commit comments

Comments
 (0)