Comments (5)
You can have class
be a function which takes active
as an argument:
<MenuItem href="/" class={({active}) => active ? 'active-class' : ''}>Link</MenuItem>
This isn't well-documented in the React docs, but you can see a preview of some docs I'm writing here: https://github.com/rgossiaux/svelte-headlessui/blob/initial-docs/src/routes/docs/general/important-concepts.svx
from svelte-headlessui.
Thanks for the great report with a REPL!
The upstream library has this same behavior, actually: https://codesandbox.io/s/frosty-jepsen-c120o Given that, this is probably a wontfix, but I'm curious what your use case is, since the first example in your REPL seems to work fine. You can still render the MenuItems
as ul
and wrap the individual MenuItem
s in <li>
to get the same markup.
The reason this doesn't work is because the arrow keys focus the MenuItem
components themselves, so in your second example, the <a>
tags aren't focused (because they're children).
from svelte-headlessui.
Well, my particular case is to use HeadlessUI components with DaisyUi appearance. I have been able to use dropdown and menu components from DaisyUi and everything working well except keyboard navigation.
<li>
<MenuItem href="/">Link</MenuItem>
</li>
This will solve the problem with working links by keyboard navigation but I can't show the active state with this solution. Because let:active will be accessible only in child elements of <MenuItem>
.
In react HeadlessUi I would be able to make it like that:
<li>
<Menu.Item>
{({ active }) => (
<a href="/" class={active ? 'active-class' : ''}>Link</a>
)
</Menu.Item>
</li>
And it will work perfectly because react HeadlessUi uses child <a>
as the main element of MenuItem. But in svelte HeadlessUi the same approach will lead to a not working link when you press Enter.
Any ideas on how I can have fully working keyboard navigation with the ability to set active classes in svelte HeadlessUi?
from svelte-headlessui.
Fully working Codesandbox with an example which I want to reach in svelte HeadlessUi. Actually, it seems impossible with the current implementation.
from svelte-headlessui.
Thank you very much. Glad that there option to set active classes right in MenuItem. Definitely would be helpful to have this feature documented. =D
from svelte-headlessui.
Related Issues (20)
- 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
- Add new maintainers HOT 8
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.