-
-
Notifications
You must be signed in to change notification settings - Fork 130
Adds update:show event to CTabs #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
What are real-life applications for tracking tab click? |
I have a tab with a Still new to vue...it is possible I'm doing something wrong?! |
Interesting case Accessing component by reference is considered bad practice because it generates tight coupling without a trace, is error-prone and hard to debug. Why do you need a reference? Can you share your code? |
The concrete example that I'm trying to achieve is to <template>
<CTabs>
<CTab active>
<CCard>
...
</CCard>
</CTab>
<CTab>
<GmapMap ref="mapRef" ...></GmapMap>
</CTab>
</CTabs>
</template>
<script>
export default {
mounted () {
// At this point, the child GmapMap has been mounted, but
// its map has not been initialized.
// Therefore we need to write mapRef.$mapPromise.then(() => ...)
this.$refs.mapRef.$mapPromise.then((map) => {
map.panTo({lat: 1.38, lng: 103.80})
})
}
} In this case accessing the reference is necessary in order to have access to Google Maps API. |
This example doesn't show an edge case, which couldn't be done by props. It just shows how to make access by ref (because it is not standard due to the promise). Behavior showed in the example can be achieved by the 'center' prop: <GmapMap
:center="{lat:10, lng:10}"
:zoom="7"
map-type-id="terrain"
style="width: 500px; height: 300px"
>
[...] If you ever encounter similar problem you can use watch for ref change (https://jsfiddle.net/kenberkeley/9pn1uqam/). But this is the last thing you want to do, as its as hacky as CTabs component :P Anyway, I see this functionality, as something which might have possible applications i.e. saving tabs state. But still, it doesn't really solve this component flexibility problem. What if users would like to listen for events on tabs for some reason? We could think of a solution that solves all these problems but it would demand a change of this component API. For now, it sacrifices full flexibility for convenient API (CTab are fake components allowing making one component for tab instead of two). I will merge your request and make some changes to it so it will emit an event on tab change, not on tab click. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use events named "update:{propName}" if you want the event to be able to automatically synchronize the prop passed to the component.
In this case, the component doesn't have 'show' prop so the event shouldn't suggest that component have such prop.
- In case of this functionality, we are interested in tab change, not tab click.
@woothu, thank you for the feedback! Indeed, I could use I picked |
Currently there is no event that indicate the click on a CTab.
This PR adds a
update:show
event forCTabs
indicatingindex
of new activeCTab
.What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
develop
branch (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information: