I have a TabGroup/TabItem component for both Vue 3 and Vue 2, but it's written in the Options API.
I'm creating a new carousel component, which shares a lot of the features, but I'm trying to write it in the Composition API as that's how we now write everything in our projects.
I am essentialy trying to access data on the child components, but I don't see an obvious way of doing it. I want to be able to determine which of the children is active within the group component, so it can manage things like keyboard navigation and so on.
- I could use Vuex, but this is a generic component that will be used more than one place. I could give each some kind of ID to differentiate them in the store, but this component is also eventually going into a library, which won't have access to the Vuex instance of whatever project is using it.
- Events don't seem like they'll work, because of the way the components are set up - the wrapper doesn't know what the children are, and they're just populated into the default slot. It seems like events will fire where the carousel is used, not inside the group.
- I can't use refs for the same reason, they will be available where the carousel is created, not in the
carousel-group. Plus I don't want anyone to have to add a ref to every panel just to use the component. - I can't provide the panels as an array to
carousel-group, because every panel can contain any content, and I want that to be as easy as possible to set up.
For some background, the basic setup is this:
<carousel-group>
<carousel-panel>
Panel content
</carousel-panel>
</carousel-group>
As part of the setup process I can access the children, similar to what I would do in the Options API, and get a list of the child panels.
panels.value = slots.default().filter(child => child.type.name === 'carousel-panel');
Each carousel-panel has instance data such as active, which is what I want to access. But getting the panels via the default slot doesn't come with any of those properties.
Any ideas would be great, as I'm a bit stumped at the moment. I don't really want to have to do this using the Options API.