Skip to content
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

feat(tabs): inject parent #159

Merged
merged 2 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/tabs/tab-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import Vue from 'vue';
import Vue, { VueConstructor } from 'vue';
import props from './tab-panel-props';
import { renderContent } from '../utils/render-tnode';
import { prefix } from '../config';
import Tabs from './tabs';

export default Vue.extend({
interface TabPanel extends Vue {
parent?: InstanceType<typeof Tabs>;
}

export default (Vue as VueConstructor<TabPanel>).extend({
name: 'TTabPanel',

props: { ...props },

inject: {
parent: { default: null },
},

computed: {
active(): boolean {
const { value } = this.$parent as any;
const { value } = this.parent || {};
return this.value === value;
},
},

updated() {
(this.$parent as any)?.updatePanels?.({ force: true });
this.parent?.updatePanels?.({ force: true });
},

render() {
Expand Down
6 changes: 6 additions & 0 deletions src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export default (Vue as VueConstructor<TabVue>).extend({

props: { ...props },

provide(): { parent: TabVue } {
return {
parent: this,
};
},

data() {
return {
panels: [] as Array<InstanceType<typeof TTabPanel>>,
Expand Down