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
Emit events from TPW? [OTHER] #19
Comments
Would this be okay? Should probably look at how others do this API... const emit = defineEmits<{
// when in tab mode
(e: 'select', idx: number): void
// when in accordion mode
(e: 'expand', idx: number): void
(e: 'collapse', idx: number): void
}>() |
@tjk thanks for the rapid reply. fyi I am using vue 2 (do you need to define emits for v2?) . Without seeing your response, I would probably would have done something like: spanClick(idx) {
if (this.isAccordion) {
this.$set(this.expandedTabsIdx, idx, !this.expandedTabsIdx[idx])
this.$emit('panelChange', this.expandedTabsId)
} else {
this.selectedTabIdx = idx
this.$emit('tabChange', this.selectedTabIdx)
}
}, |
Just spent a little time thinking about it and I think it probably makes more sense to parallelize event name and args as much as possible so a consumer who is using in ambiguous mode only needs to listen for one event (and can always expect the value to be an array)... If it's useful to know what mode the widget is in at event emit time, can also pass a third arg that is is either this.$emit("change", [1], 1) // if first tab is selected
this.$emit("change", [1], [1]) // this would mean just the first accordion panel is opened Makes sense hopefully? Maybe there is something more clever... const emit = defineEmits<{
(e: 'change', indices: number[], indexOrIndices: number | number[]): void
}>() |
This sounds workable, although I confess to having some difficulty with the number combo and discerning why the tab indicator is an array and the accordion panel indicator is an object. That's not an objection at all; I'm just new to this script and am still unfamiliar with how the indices work and get calculated. I guess more generally, I'd suggest imagining a user who is using the Vue version. They're probably using additional components, and so having an (or a more) accessible API for inter-component communication would be a big plus. There are a few props (although I still don't understand |
Is there any way to get the vue version to emit an event when the tab is changed? I'd do it myself, but I can't figure out how to take these scripts and make a standalone TPW vue component that I can add this to. I've got to have way to track the current tab.
The text was updated successfully, but these errors were encountered: