how to use x-collapse in mobile view only? #2282
-
Hey there! First of all, I´d like to thank for AlpineJS, I keep falling in love the longer I get into it! Great work! Right now I am trying to find a way to use "x-collapse" only on specific viewport sizes, eg. <1024px. My first idea was to use a function on init of the component that reads the viewportWidth and then adds/removes the "x-collapse" property to/from the $el, but this only works once, on page load.
So I bind another function "check" to "@resize.window" and the property gets added and removed from the element succesfully, but after it was added once, the removal doesn´t have any effects on the component, it still uses x-collapse.
Is there a way to "rerender" the component after removing the property from it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
It's a weird requirement, I must admit, however, you shouldn't need to do complicate stuff. cleanup(() => {
delete el._x_transition
el.style.removeProperty('overflow')
el.style.removeProperty('height')
if (! el._x_isShown) el.style.display = 'none'
}) As a temporary workaround, you can do something like Also, you should debounce |
Beta Was this translation helpful? Give feedback.
-
You probably don't want to remove it because it fixes an accessibility
issue. If its to keep borders and margins, you can use a wrapping div and
move the styles you need to show when collapsed to that element
…On Tue, 30 Nov 2021, 18:00 Phil Wolstenholme, ***@***.***> wrote:
Hi @StefanVesper <https://github.com/StefanVesper> - the hidden attribute
is related to a new feature I added to Alpine in #2353
<#2353>
One way to remove the attribute would be to do this alongside your other
cleanup bits:
this.$el.removeAttribute('hidden');
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2282 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACAJRWI2HZJSNRCOXR2JXXLUOUGLNANCNFSM5G7NDLFA>
.
|
Beta Was this translation helpful? Give feedback.
-
Got the exact same problem. And I don't think it's a weird requirement. I have a main navigation with dropdowns for each main nav item. On desktop I want to show the dropdown on So I figured out, that it's possible to conditionally bind the transition like this:
But I didn't find a way to conditionally bind |
Beta Was this translation helpful? Give feedback.
It's a weird requirement, I must admit, however, you shouldn't need to do complicate stuff.
The issue is that collapse doesn't implement a proper clean up face as it could do.
Basically, it just misses
As a temporary workaround, you can do something like
delete this.$el._x_transition; this.$el.style.removeProperty('overflow'); this.$el.style.removeProperty('height'); if (! this.$el._x_isShown) this.$el.style.display = 'none'
afterthis.$el.removeAttribute("x-collapse")
A…