aboutsummaryrefslogtreecommitdiff
path: root/src/components/tab_switcher
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-09-08 13:44:29 +0300
committerHenry Jameson <me@hjkos.com>2019-09-08 13:44:29 +0300
commitdb086fe1fdeefdc904f51ee00b2710f089996599 (patch)
tree6e4734fc99544da9b34c78700b18c9b02a3f573f /src/components/tab_switcher
parent5851f97eb058b3e2df91f9122ba899bc7e4affaf (diff)
parente75ac9ddbc66a7e3cd40ef130b26b06b8cec9f1d (diff)
Merge remote-tracking branch 'upstream/develop' into emoji-selector-update
* upstream/develop: (116 commits) Password reset page add a comment force img updating immediately Fixed "sequimiento" to "seguimiento". Replace `/api/externalprofile/show.json` with a MastoAPI equialent Use mastodon api in follow requests "Optional" in lowercase. Update es.json fix pin/unpin status logic rename a mutation update fix user avatar fallback logic remove dead code Corrected "Media Proxy" translation. Update es.json make bio textarea resizable vertically only remove dead code Make image orientation consistent on FF, fix videos w/ modal remove dead code fix crazy watch logic in conversation ...
Diffstat (limited to 'src/components/tab_switcher')
-rw-r--r--src/components/tab_switcher/tab_switcher.js32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/components/tab_switcher/tab_switcher.js b/src/components/tab_switcher/tab_switcher.js
index 99428044..3ca316b9 100644
--- a/src/components/tab_switcher/tab_switcher.js
+++ b/src/components/tab_switcher/tab_switcher.js
@@ -14,7 +14,7 @@ export default Vue.component('tab-switcher', {
required: false,
type: Function
},
- customActive: {
+ activeTab: {
required: false,
type: String
},
@@ -29,6 +29,16 @@ export default Vue.component('tab-switcher', {
active: this.$slots.default.findIndex(_ => _.tag)
}
},
+ computed: {
+ activeIndex () {
+ // In case of controlled component
+ if (this.activeTab) {
+ return this.$slots.default.findIndex(slot => this.activeTab === slot.key)
+ } else {
+ return this.active
+ }
+ }
+ },
beforeUpdate () {
const currentSlot = this.$slots.default[this.active]
if (!currentSlot.tag) {
@@ -36,22 +46,14 @@ export default Vue.component('tab-switcher', {
}
},
methods: {
- activateTab (index, dataset) {
+ activateTab (index) {
return (e) => {
e.preventDefault()
if (typeof this.onSwitch === 'function') {
- this.onSwitch.call(null, index, this.$slots.default[index].elm.dataset)
+ this.onSwitch.call(null, this.$slots.default[index].key)
}
this.active = index
}
- },
- isActiveTab (index) {
- const customActiveIndex = this.$slots.default.findIndex(slot => {
- const dataFilter = slot.data && slot.data.attrs && slot.data.attrs['data-filter']
- return this.customActive && this.customActive === dataFilter
- })
-
- return customActiveIndex > -1 ? customActiveIndex === index : index === this.active
}
},
render (h) {
@@ -61,13 +63,13 @@ export default Vue.component('tab-switcher', {
const classesTab = ['tab']
const classesWrapper = ['tab-wrapper']
- if (this.isActiveTab(index)) {
+ if (this.activeIndex === index) {
classesTab.push('active')
classesWrapper.push('active')
}
if (slot.data.attrs.image) {
return (
- <div class={ classesWrapper.join(' ')}>
+ <div class={classesWrapper.join(' ')}>
<button
disabled={slot.data.attrs.disabled}
onClick={this.activateTab(index)}
@@ -79,7 +81,7 @@ export default Vue.component('tab-switcher', {
)
}
return (
- <div class={ classesWrapper.join(' ')}>
+ <div class={classesWrapper.join(' ')}>
<button
disabled={slot.data.attrs.disabled}
onClick={this.activateTab(index)}
@@ -91,7 +93,7 @@ export default Vue.component('tab-switcher', {
const contents = this.$slots.default.map((slot, index) => {
if (!slot.tag) return
- const active = index === this.active
+ const active = this.activeIndex === index
if (this.renderOnlyFocused) {
return active
? <div class="active">{slot}</div>