Comments (2)
Hey! Sorry you're having trouble with the documentation, I know it's not in a good state right now. Writing independent, Svelte-specific documentation is my next priority for this project, but in the meantime I'm happy to try to help with questions like this.
The way to convert the docs is that the props are the same in both libraries & the "render props" in React become slot props in Svelte; the let:value
syntax in Svelte is for accessing a slot prop. For Listbox, value
is a normal prop, not a slot prop, so that's why your example doesn't work.
The way this component is designed (as well as most of the other components in the library) is that it doesn't manage its own state directly. You pass it a value
prop that says which value is selected, and the component fires a change event when the user selects a new value, which you use to update the value
prop. For example, something like:
<script>
let value;
</script>
<Listbox {value} on:change={(e) => value = e.detail}>
<ListboxButton>{value ?? ""}</ListboxButton>
<ListboxOptions>
<ListboxOption value="Option A">Option A</ListboxOption>
<ListboxOption value="Option B">Option B</ListboxOption>
<ListboxOption value="Option C">Option C</ListboxOption>
</ListboxOptions>
</Listbox>
It might seem a little unintuitive for it to work this way--why doesn't the Listbox just keep track of which item is selected instead of making you always tell it?--but it's more flexible, since it gives you total control over which item is selected in case you want to set it programmatically.
Hope that makes sense, let me know if you have more questions!
from svelte-headlessui.
@rgossiaux Thanks a lot for the detailed reply! I now have a better understanding of how to "read" the React docs and use your svelte components!
from svelte-headlessui.
Related Issues (20)
- component disappears after refresh when used in a svelte component HOT 1
- Support for @headlessui/tailwindcss HOT 1
- List box doesn't position absolute HOT 1
- Support Svelte 4 HOT 14
- Can't bind popover's "open" prop to a boolean HOT 1
- Switch not toggling
- RadioGroup and Listbox do not work properly when used together
- Can you readd on:change for listbox, etc
- Typo in Tabs Component Page
- Typescript Error 2322 when assigning object to ListboxOption value parameter
- Dialog breakes SvelteKit client-side routing HOT 2
- Conflicts in Svelte resolve
- Tree shaking HOT 1
- Time to update svelte? HOT 1
- Dialog nested in a Menu automatically opens when Menu opens
- warning when using sveltekit v2: The following packages have a svelte field in their package.json but no exports condition for svelte. HOT 1
- Missing close event on Menu
- Headless UI v2.0.0-alpha released
- Popover not detecting content click events (links / otherwise) in web component context (with fix) HOT 2
- Tabs: adding/removing tab work not properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-headlessui.