awcodes / alpine-floating-ui

Add Floating UI functionality to Alpine 3.x components.
MIT License
79 stars 3 forks source link

Add check if opened when calling close #6

Closed howdu closed 1 year ago

howdu commented 1 year ago

Prevent error if calling close of a floating UI which has not been opened.

can't access property "setAttribute", i.trigger is null

My use case for this is where I have embedded dropdown with a window event to close it, but if the embedded dropdown has not been opened the error is thrown.

x-on:close-dropdown.window="if ($event.detail.id === 123) close()"

I could prevent the error via additional parameters with an additional OR condition but I thought it made more sense to fix it here.