It seems like the issue is related to the x-anchor directive in your x-panel component. The x-anchor directive is used by Alpine.js to position floating elements like popovers or dropdowns relative to another element. The error message "Uncaught Alpine: no element provided to x-anchor..." indicates that Alpine.js is expecting an element to anchor the popover to, but it's not receiving one.
To fix this issue, you need to ensure that the element you want to anchor the popover to has an id that matches the one you're referencing in the x-anchor directive. In your x-popover.button component, you should add an id attribute that you can reference in the x-panel component.
Here's how you can modify your code:
- Add an
idto yourx-popover.buttoncomponent:
<!-- x-popover.button -->
<button type="button" id="popoverButton" x-popover:button {{ $attributes }}>
{{ $slot }}
</button>
- Update the
x-anchordirective in yourx-panelcomponent to reference theidof the button:
<!-- x-panel -->
@props(['position' => 'bottom-center'])
<div
x-popover:panel
x-cloak
x-transition.out.opacity
x-anchor.{{ $position }}.offset.1="document.getElementById('popoverButton')"
{{ $attributes->merge([
'class' => 'absolute left-0 mt-2 bg-white rounded-md',
]) }}
>
{{ $slot }}
</div>
Make sure that the id you use is unique on the page to avoid conflicts with other elements. If you have multiple popovers, you'll need to dynamically generate unique ids for each button and reference them accordingly in the x-anchor directive.
After making these changes, the popover should be correctly anchored to the button, and clicking the button should open the popover as expected. If you still encounter issues, double-check that you have included Alpine.js in your project and that it is initialized correctly.