I am currently working with two nested native web components in the following setup:
<top-nav theme="aqua">
<nav-link selected>Dashboard</nav-link>
<nav-link>Settings</nav-link>
<nav-link>Profile</nav-link>
<nav-link>Logout</nav-link>
</fancy-tabs>
Each component renders fine on its own, but now I need to establish communication between them.
The simplest use-case is setting a link to be selected.
By default, the dashboard is the selected link.
Now, when I click on the settings link, it should become selected. However, I am unsure of how to notify the dashboard component to remove the selected attribute since only one link can be active at any given time.
My initial thought was to dispatch an event from the clicked element, handle the event in the top-nav element, and then iterate through all children to remove the selected attribute if the element is not the origin of the event.
This approach reminds me of the jQuery era and doesn't feel quite right. Are there any other ideas or suggestions for accomplishing this task?