Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit a8d1f61

Browse files
committed
Use provide/inject to register tabs for layout flexibility
1 parent 9cf6ade commit a8d1f61

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

dev-example/WizardRoute.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
<form-wizard @on-complete="onComplete"
88
@on-change="handleChange"
99
:start-index.sync="activeIndex"
10-
layout="vertical"
11-
steps-classes="steps-size"
1210
color="#e74c3c">
1311
<tab-content v-for="tab in tabs" :title="tab" :key="tab">{{tab}}</tab-content>
1412
<transition name="fade" mode="out-in">

src/components/FormWizard.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@
157157
}
158158
}
159159
},
160+
provide () {
161+
return {
162+
addTab: this.addTab,
163+
removeTab: this.removeTab
164+
}
165+
},
160166
data () {
161167
return {
162168
activeTabIndex: 0,

src/components/TabContent.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
default: () => {}
3939
}
4040
},
41+
inject: ['addTab', 'removeTab'],
4142
data () {
4243
return {
4344
active: false,
@@ -57,13 +58,13 @@
5758
}
5859
},
5960
mounted () {
60-
this.$parent.addTab(this)
61+
this.addTab(this)
6162
},
6263
destroyed () {
6364
if (this.$el && this.$el.parentNode) {
6465
this.$el.parentNode.removeChild(this.$el)
6566
}
66-
this.$parent.removeTab(this)
67+
this.removeTab(this)
6768
}
6869
}
6970
</script>

test/unit/specs/FormWizard.spec.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import VueFormWizard from './../../../src/index'
2-
import {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index'
1+
import VueFormWizard, {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index'
32
import {mount, createLocalVue} from 'vue-test-utils'
43
import sinon from 'sinon'
5-
import Vue from "vue";
4+
import Vue from 'vue'
65

76
const localVue = createLocalVue()
87
localVue.use(VueFormWizard)
@@ -28,14 +27,30 @@ const twoStepWizard = {
2827
}
2928
}
3029
}
30+
31+
const divSlot = `<div>
32+
<tab-content title="Personal details"
33+
icon="ti-user">
34+
First
35+
</tab-content>
36+
<tab-content title="Additional Info"
37+
icon="ti-settings">
38+
Second
39+
</tab-content>
40+
<tab-content title="Last step"
41+
icon="ti-settings">
42+
Third
43+
</tab-content>
44+
</div>`
45+
3146
describe('FormWizard.vue', () => {
3247
it('contains wizard class', () => {
3348
const wizard = mount(twoStepWizard, {localVue})
3449
wizard.hasClass('vue-form-wizard')
3550
})
36-
it('renders steps', () => {
51+
it('renders steps', (done) => {
3752
const wizard = mount(twoStepWizard, {localVue})
38-
Vue.nextTick(()=>{
53+
Vue.nextTick(() => {
3954
const steps = wizard.findAll(WizardStep)
4055
const firsStep = steps.at(0)
4156
expect(steps.length).to.equal(3)
@@ -44,8 +59,8 @@ describe('FormWizard.vue', () => {
4459
expect(stepTitle.is('span')).to.equal(true)
4560
const stepText = stepTitle.text().trim()
4661
expect(stepText).to.equal('Personal details')
62+
done()
4763
})
48-
4964
})
5065
it('renders tabs', () => {
5166
const wizard = mount(twoStepWizard, {localVue})
@@ -81,4 +96,17 @@ describe('FormWizard.vue', () => {
8196
expect(nextTabHandler.called).to.equal(true)
8297
})
8398

99+
it('renders tab wrapped in another element', done => {
100+
const wizard = mount(FormWizard, {
101+
localVue,
102+
slots: {
103+
default: divSlot
104+
}
105+
})
106+
Vue.nextTick(() => {
107+
const tabs = wizard.findAll(WizardTab)
108+
expect(tabs.length).to.equal(3)
109+
done()
110+
})
111+
})
84112
})

0 commit comments

Comments
 (0)